Hi,
how do I render a mesh/face two sided? I set the two sided option in blender and exported it in an .obj file, but the mesh/face is not rendered two sided. It has a texture on it, which is visible from one side, but not from the other.
You need to change the FaceCullMode of the object material :
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
default is Back
Really cool, but how do I get the material of a loaded .obj?
[java]
// Import the spatial.
Spatial ship = manuskriptManager.loadModel(“data/models/Ship.obj”);
???
material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
rootNode.attachChild(ship);
[/java]
ship is either a geometry or a node containig geometry
if(ship instanceof Geoemtry){
Geometry sgeom = (Geometry)ship;
sgeom.getMaterial();
}
pretty much the same for a node, except you then need to check the children of the node for the geometry.
[snippet id=“13”]
[java]
// Import the spatial.
Node ship = (Node) manuskriptManager.loadModel(“data/models/Ship.obj”);
for (Spatial child : ship.getChildren()) {
if (child instanceof Geometry) {
((Geometry) child).getMaterial().getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
((Geometry) child).getMaterial().setBoolean(“m_UseAlpha”, true); // Use alpha from diffuse color.
((Geometry) child).getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
child.setQueueBucket(Bucket.Transparent); // enables back-to-front sorting
}
}
rootNode.attachChild(ship);
rootNode.updateGeometricState();
[/java]
Fantastic!
Now for the last one:
I want to have transparent textures on the geometries. What did I forget in my code?
That code should enable transparency. Do you have an alpha channel in your textures?