Lets say you want a simple rectangle [(x0, y0, z0); (x1, y1, z1); (x2, y2, z2); (x0+x2-x1, y0+y2-y1, z0+z2-z1)],
with texture coordinates (0.0, 0.0, 0.5, 0.5), how would one create that in JM3?
In Java3D, i’d simply do a
[java] public static Shape3D texturedPlane(Point3f[] pfa, TexCoord2f[] qfa,
Texture2D tex, boolean fMaterial)
{
GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY);
NormalGenerator ng = new NormalGenerator();
return texturedPlane(pfa, qfa, tex, fMaterial, gi, ng);
};
public static Shape3D texturedPlane(Point3f[] pfa, TexCoord2f[] qfa,
Texture2D tex, boolean fMaterial, GeometryInfo gi, NormalGenerator ng)
{
if (tex == null)
return null;
Appearance appear = new Appearance();
QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES
| GeometryArray.TEXTURE_COORDINATE_2 | QuadArray.NORMALS
);
if (fMaterial)
{
Material mat = new Material();
mat.setAmbientColor(new Color3f(0.1f,0.1f,0.1f));
mat.setDiffuseColor(new Color3f(0.3f,0.3f,0.3f));
mat.setSpecularColor(new Color3f(0.01f,0.01f,0.009f));
mat.setLightingEnable(true);
mat.setShininess(0.0f);
appear.setMaterial(mat);
}
if (tex.getFormat() == Texture2D.RGBA)
{
TransparencyAttributes transAttr = new TransparencyAttributes();
transAttr.setTransparency(0.0f);
transAttr.setTransparencyMode( TransparencyAttributes.BLENDED );
appear.setTransparencyAttributes(transAttr);
}
TextureAttributes textAttr = new TextureAttributes();
textAttr.setTextureBlendColor(0.01f, 0.01f, 0.01f, 0.5f);
textAttr.setTextureMode(TextureAttributes.MODULATE);
appear.setTextureAttributes(textAttr);
gi.setCoordinates(pfa);
ng.generateNormals(gi);
plane.setNormals(0, gi.getNormals());
appear.setTexture(tex);
plane.setCoordinates(0,pfa);
plane.setTextureCoordinates(0, 0, qfa);
Shape3D shape = new Shape3D(plane);
shape.setAppearance(appear);
return shape;
};
[/java]
Lol, “simply do a” xD
Have you seen this: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes ?
Ah, must have skipped that… BTW, if you substract the material and color blending, it is /almost/ simple ;-}
I posted a RFC/contribution here.
There is btw an error in the wiki’s article – the texture coordinates are messed up.
[java]Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0,0);
texCoord[1] = new Vector2f(1,0);
texCoord[2] = new Vector2f(0,1);
texCoord[3] = new Vector2f(1,1);[/java]
see, what i mean?
rhavin said:
There is btw an error in the wiki's article – the texture coordinates are messed up.
You can edit the wiki with the wiki entry in the black bar menu on top.
lol Ok, i just noticed that bar for the first time;-)