Hi,
i made a trianlge geometry by using a custom mesh, here is the code :
public class Triangle extends Mesh
{
public static final float SIZE = 12f;
private Mesh mesh = new Mesh();
public Triangle(float a, float b, float c)
{
Vector3f [] vertices = new Vector3f[3];
vertices[0] = new Vector3f(0.0f, a ,0.0f);
vertices[1] = new Vector3f(SIZE, c ,0.0f);
vertices[2] = new Vector3f(SIZE/2, b ,SIZE); //pointe
Vector2f [] texCoord = new Vector2f[3];
texCoord[0] = new Vector2f(0,0);
texCoord[1] = new Vector2f(1,0);
texCoord[2] = new Vector2f(0,1);
short[] indexes = {1, 0, 2};
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
mesh.updateBound();
}
public Mesh mesh()
{
return mesh;
}
}
And i use it in this scene :
public class test2 extends SimpleApplication
{
@Override
public void simpleInitApp()
{
assetManager.registerLocator("res/", FileLocator.class);
Triangle triangle = new Triangle(0,0,0);
Mesh mesh = triangle.mesh();
Geometry geo;
Vector3f vec;
for(int x=0 ; x<=1 ; x++)
{
for(int z=0 ; z<=0 ; z++)
{
boolean reverse = false;
vec = new Vector3f(x*Triangle.SIZE/2, 0, z*Triangle.SIZE);
geo = new Geometry("Triangle", mesh);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/grass.jpg"));
mat.setBoolean("UseMaterialColors",true);
mat.setColor("Diffuse",ColorRGBA.White);
mat.setColor("Specular",ColorRGBA.White);
mat.setFloat("Shininess", 64f);
if (x%2 != 0)
{
reverse = true;
}
if (z%2 == 0)
{
reverse = !reverse;
}
if (reverse)
{
geo.rotate(0, FastMath.PI, 0);
vec.x += Triangle.SIZE;
vec.z += Triangle.SIZE;
}
geo.setLocalTranslation(vec);
geo.setMaterial(mat);
rootNode.attachChild(geo);
}
}
flyCam.setMoveSpeed(50f);
lamp_light = new PointLight();
lamp_light.setColor(ColorRGBA.White);
lamp_light.setRadius(100f);
rootNode.addLight(lamp_light);
}
PointLight lamp_light;
public void simpleUpdate(float tps)
{
lamp_light.setPosition(cam.getLocation());
}
public static void main(String[] args)
{
test2 app = new test2();
app.start();
}
}
In this sceen thereās 2 triangles but i canāt see both at the same time, depend of the camera direction i can only see one of them.
But if i change the material to :
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
They both appear. What i did wrong ?
(you need to turn the camera to the right to see them)
with light:
http://image.noelshack.com/fichiers/2016/15/1460815014-a.png
http://image.noelshack.com/fichiers/2016/15/1460815011-b.png
without light:
http://image.noelshack.com/fichiers/2016/15/1460815015-c.png
thx guys !