Convert C++ code to javascript code


#1

Hi every one
I have a code:

m_pMeshCommand = new MeshCommand();
m_pMeshCommand->genMaterialID(0, m_ProgramState, m_RenderMesh->getVertexBuffer(), m_RenderMesh->getVertexBuffer(), m_BlendFunc);
m_pMeshCommand->init(_globalZOrder, textureID, programstate, m_BlendFunc, m_RenderMesh->getVertexBuffer(),m_RenderMesh->getIndexBuffer(),(GLenum)m_RenderMesh->getPrimitiveType(), (GLenum)m_RenderMesh->getIndexFormat(), m_RenderMesh->getIndexCount(), transform);

m_pMeshCommand->setCullFaceEnabled(false);
m_pMeshCommand->setDepthTestEnabled(false);
m_pMeshCommand->setDisplayColor(Vec4(color.r, color.g, color.b, color.a));

I need convert it to javascript language, but I don’t know how to use MeshCommand on jsb cocos2d.
Does anyone help me? Please.
Thanks


#2

hello
I have tried to add c++ functions to cocos2d js . I have tried to use jsb.reflection.callStaticMethod to call static function in c++ class and i have tried to Bind a custom class to js runtime But it does not work
Can u help me please
please advice


#3

Follow this guide. It works.

http://www.cocos2d-x.org/wiki/How_to_bind_C++_to_Javascript


#4

Generating bindings for cocos2dx…
Using userconfig
[]
Traceback (most recent call last):
File “C:\Users\User\Desktop\bidings-example-v3\frameworks\cocos2d-x\tools\bind
ings-generator/generator.py”, line 1550, in
main()
File “C:\Users\User\Desktop\bidings-example-v3\frameworks\cocos2d-x\tools\bind
ings-generator/generator.py”, line 1468, in main
clang_lib_path = os.path.join(userconfig.get(‘DEFAULT’, ‘cxxgeneratordir’),
‘libclang’)
File “C:\Python27\lib\ConfigParser.py”, line 618, in get
raise NoOptionError(option, section)
NoOptionError: No option ‘cxxgeneratordir’ in section: ‘DEFAULT’

Generating javascript bindings fails.

how to fixed it? any hepl please


#5

Be sure you have these in test.py file:

project_root = os.path.abspath(os.path.join(os.path.dirname(file), ‘…’, ‘…’))
cxx_generator_root = os.path.abspath(os.path.join(project_root, ‘bindings-generator’))

config.set(‘DEFAULT’, ‘cxxgeneratordir’, cxx_generator_root)

It’s just the path to bindings folder. You can name them as you want.


#6

Maybe it’s not important anymore, but if you have a JSB generator don’t work, because this reason. The problem is that generator.py don’t see userconf.ini. There are is wrong search of this file in row 1465 userconfig.read('userconf.ini'). Write there path to your userconfig file, and all work fine.