First I set color of material to the node:
CC3MeshNode *node = [self.modelNode getMeshNodeNamed:nodeName];
CC3Material *material = [CC3Material material];
material.color = [CCColor colorWithUIColor:[UIColor colorWithHexString:color]];
node.material = material;
node.visible = YES;
Later I need to fill this node with texture. And I can't
CC3Texture *texture = [CC3Texture textureFromFile:@"texture.png"];
material.texture = texture;
node.material = material;
or
CC3Texture *texture = [CC3Texture textureFromFile:@"texture.png"];
[node.material addTexture:texture]
or
CC3Texture *texture = [CC3Texture textureFromFile:@"texture.png"];
node.material.color = [CCColor colorWithRed:1 green:1 blue:1 alpha:0];
[node.material addTexture:texture];
or
node.material = nil;
CC3Material *material = [CC3Material material];
node.material = material;
[node.material addTexture:texture];
returns white node with no texture.
But setting texture to the node at the begining works:
CC3MeshNode *node = [self.modelNode getMeshNodeNamed:nodeName];
CC3Texture *texture = [CC3Texture textureFromFile:@"texture.png"];
[node.material addTexture:texture];
node.visible = YES;
Any idea how to apply texture to the node after setting its color?
You are probably using a shader that does not support textures.
If you are allowing Cocos3D to automatically select shaders for you, it will take certain aspects of your node into consideration when choosing the shaders. One of the primary aspects that determines which shaders to use is whether the node has a texture.
Cocos3D selects shaders either when you explicitly invoke the selectShaders
method, or the first time the node is rendered. Once shaders have been initially selected, they are not automatically reselected if something on the node changes.
You can cause Cocos3D to select new shaders for your node by invoking removeShaders
on your node, and then either invoking selectShaders
again, or waiting until the node is rendered again.
An alternate would be to specifically assign your own shaders, that can accommodate all of the changes you will be making to your node.