Hello cocos community.
Does c3b format support lights ? If yes, then how to apply these which defined in the c3b model description to a Sprite3D which created from the same c3b model description?
I have a project in blender where I have a skinned mesh and 6 direction lights. I use FBX format for cocos2d-x (because my model is animated) and glTF for cocos2d-html5. When I export it to fbx, then convert fbx to c3b and import to a scene, the result is like in the follow picture:
The model have no shadows and lights on it’s surface. Looks like simple drawn texture without any lights applied on it. Lights are present in the fbx file, but what happens when I convert it to c3b - I don’t know. Moreover, there is no mention of the word “light” in CCSprite3D.cpp and only one macro BUNDLE_TYPE_LIGHT in CCBundle3D.cpp. Does it mean that light nodes are ignored by c3b parser ? Does it mean that there is no lights support in c3b ? I don’t want to create lights manually in the code. I wish to use only model files for all 3d objects added to the scene.
When I draw glTF on cocos2d-html5 using three.js I achieve the expected result:
Here is a model which is lit by 6 direction lights defined in the blender project and exported to glTF. How to achieve the same result using c3b ?
I believe you need to update or add a configuration. This enables lighting with 3D scenes. You can check by writing out GLProgramCache::getInstance()->getShaderMacrosForLight() to the console or check in debugger.
You can set this configuration if you look at cpp-tests project you’ll find a plist for configuring lights (among other things).
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
Have you added any lights into the scene manually? I don’t believe cocos2d-x engine imports lights from the c3b format (or any format yet).
DirectionLight* dlight;
dlight->setColor(color);
dlight->setDirection(Vec3(-1,-1,-1));
dlight->setPosition3D(Vec3(50,50,50));
addChild(dlight);
Thanks a lot for the answer.
Yes I have already tried to add lights to the scene manually and use config-example.plist. It’s all fine, but I wish to import lights from the model project because these lights are configured by an artist. I can’t reproduce the effect of that lights in the code. It is sad if the engine have no ability to import lights.
getShaderMacrosForLight returns the follow:
#define MAX_DIRECTIONAL_LIGHT_NUM 4
#define MAX_POINT_LIGHT_NUM 4
#define MAX_SPOT_LIGHT_NUM 4
One interesting thing that if I define lights count more than 4 (5 or 10 for example) then 3D objects are not displayed and I got an error in the console:
cocos2d: warning: Uniform not found: u_color
cocos2d: warning: Uniform not found: u_matrixPalette
OpenGL error 0x0502 in ~/project.js/frameworks/js-bindings/cocos2d-x/cocos/renderer/CCTextureAtlas.cpp drawNumberOfQuads 691
But it is not a problem. I understand that so many lights on one screen is bad and I will use 1 or 2 light sources instead.
Yeah, I don’t believe lights are currently imported. Essentially the current cocos2d-x 3D import support is only for meshes as far as I can tell. If you’re interested in working on the importing of lights or an entire scene I’m sure others would love the contribution.