Material problem after cloning Spatial

I have created a wall section and my intention is to copy it and place along a line to create a wall. This is how I have done this:

[java]float x = 2.0f;
float y = -2.5f;
float z = 0.0f;
float width = 3.0f;
Node node = new Node();

    for(int i = 0; i < 10; i++)
    {
        z = i * width;
        Spatial tmp = wall.clone(true);
        tmp.setLocalTranslation(x, y, z);
        node.attachChild(tmp);
    }
    rootNode.attachChild(node);[/java]

but I can only see, what appears to be, one instance of the material at a time as if only one of the wall sections can have this material applied. In addition to the above I also tried deepClone and setting the material but I got the same results. How do I do this?

Ok so if I change the material from

[java]new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);[/java]

to

[java]new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); [/java]

and, of course remove the settings associated with the lighting material it renders each section correctly. So is this a lighting issue?

I’m also getting a similar effect… I have a huge box as ground with a Lighting.j3md based material, and many enemies also with Lighting.j3md based material. All the enemies share the same material variable (I’m thinking low memory usage here). I also have a DirectionalSunLight and an AmbientLight. When the enemies are spawned and walks into the camera view, the whole scene gets darker, but the first created enemy is brighter than the others. Can this be the same problem?

Well I have found that if I alter the coords for my DirectionalLight I get slightly different results.

[java]
DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(1, -1, 0).normalizeLocal());
rootNode.addLight(sun);[/java]

Thats the best for me i.e. the one section that I can see is lit better. This is making me think that I haven’t set up the lighting to adequately light a large scene. Also having this light added seems to counteract my AmbientLight which is still added to the rootNode.

[java]
AmbientLight amb = new AmbientLight();
amb.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(amb);[/java]

What is a good basic strategy for lighting, what will be, a fairly large area that I want consistent lighting over?

p.s. Also if I move around to the other side of my wall I don’t see any so I think I am pointing it in the wrong direction.

@onesixtyfourth said: Well I have found that if I alter the coords for my DirectionalLight I get slightly different results.

[java]
DirectionalLight sun = new DirectionalLight();
sun.setColor(ColorRGBA.White);
sun.setDirection(new Vector3f(1, -1, 0).normalizeLocal());
rootNode.addLight(sun);[/java]

Thats the best for me i.e. the one section that I can see is lit better. This is making me think that I haven’t set up the lighting to adequately light a large scene. Also having this light added seems to counteract my AmbientLight which is still added to the rootNode.

[java]
AmbientLight amb = new AmbientLight();
amb.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(amb);[/java]

What is a good basic strategy for lighting, what will be, a fairly large area that I want consistent lighting over?

p.s. Also if I move around to the other side of my wall I don’t see any so I think I am pointing it in the wrong direction.

I think this all comes down to the model. Is it something you’ve loaded that was create in another tool or is it a JME Box?

…try a JME Box and I bet everything starts to work.

Yes I made the model in Blender so that I could UV a texture for it. I will give it a go but if that is the problem how do I fix the model. Is it recalculate normals or something like that before I export?

@onesixtyfourth said: Yes I made the model in Blender so that I could UV a texture for it. I will give it a go but if that is the problem how do I fix the model. Is it recalculate normals or something like that before I export?

Depends on what is wrong with it. Use the JME box first to confirm that it’s even the problem.

Also, do you have normal maps or bump maps or something?

Ok I will try jme box first and see what happens.

yep you are right it works ok with a jme box. Obviously the material isn’t great as sizes are different but the important fact that it is visible on all of the sections shows what you were saying is correct. My texture only has a diffuse map at the moment but I would like to create a normal map also in the future.

What should I be investigating regards the state of my model? It may just be easier to use the box but I then wouldn’t be able to use my uv coords from Blender would I?

Right I definitely have something wrong here. I have got home and tried with the model I created there as I followed the exporting tutorial for it. I still have problems with it but not quite the same. I can see the brick material on both sides of the wall and for each section created with the code above. The model does not have its material applied at either end of the wall or on the top where I have mapped a concrete coping stone type thing. In all cases the sides are visible but the top and ends are not. As I roam around the wall it appears that the width is not correct and it looks like each side is mapped to either side of the same plane.

I replaced my model with a box sized to my models dimensions (0.325, 3, 3) Which I have worked out gives me a realistic brick size and width of wall. Applying the blue mat from tut 1 it looks exactly as it should and proves, I think, that I have a problem with the model.

I went back to Blender and attempted a fix. I looked again at the exporting tutorial and checked the material properties and checked mine against it. They seem ok but I do have 2.69 of Blender and there were some items in image sampling I wasn’t sure about but left at default. I am only attempting the diffuse map at the moment. I did the apply location/rotation/scale bit and also re calculated the normals but I still get the problem. I also tried applying my texture to the jme box and it didn’t show at all.

What else can I do to fix this? Any pointers to tutorials/information about creating/exporting my model would be appreciated.

I have an answer of sorts. I was having problems seeing parts of the material on my model and I can now see all sides. I had to add lights for each direction is what I think I have done.

[java]
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-1,0,0).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);

DirectionalLight sun1 = new DirectionalLight();
sun1.setDirection(new Vector3f(1,0,0).normalizeLocal());
sun1.setColor(ColorRGBA.White);
rootNode.addLight(sun1);[/java]

I have a pair like that above for each axis so that I have a light pointing towards each side of the wall. Is that the correct analysis of the code and is this the correct usage of the light?

You know have two suns opposite each other, basically. If that’s the only thing wrong then having an ambient light (and making sure the material has ambient or has turned off UseMaterialColors [a JME setting not a blender one]) should also be an option.

I don’t know what might be wrong with your model other than that.

I have decided to stick with an ambient light for now. The wall sections don’t look that bad and I don’t currently have the time to investigate in more depth. In the last post I didn’t just have those two lights I had two for each axis so a total of six. I also had an ambient light and I don’t think that is the right approach for lighting. The application I am building would actually have a problem with shadow from the walls so its a viable option to just use an ambient light.

Thanks for your help again pspeed .

@onesixtyfourth said: I have decided to stick with an ambient light for now. The wall sections don't look that bad and I don't currently have the time to investigate in more depth. In the last post I didn't just have those two lights I had two for each axis so a total of six. I also had an ambient light and I don't think that is the right approach for lighting. The application I am building would actually have a problem with shadow from the walls so its a viable option to just use an ambient light.

Thanks for your help again pspeed .

Might as well just use Unshaded.j3md then.

Pspeed was right on this as it turned out to be an error when exporting from blender to obj. I altered the planes before exporting to z up and y forward ( from memory). All works well with lighting based materials now.