Hello everyone!
I am developing an app for my 3D printer and I need to display and manipulate stl objects. I am trying jMonkey now. So here are some questions :
Is there a different, better way to import STL files than to directly manipulate mesh vertex buffers (i got the triangle data : vertex and normals)?
And if there isn’t - why this does not work (my triangle does not render)?
[java]
// Don’t concern yourself with this - this works well
STLInterface s = new STLInterface();
s.loadSTLfile(“resources/cube.stl”);
FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
fpp.addFilter(bloom);
viewPort.addProcessor(fpp);
ArrayList<Triangle> tr = new ArrayList<Triangle>();
Vector3f[] normals = new Vector3f[3];
Vector3f[] verti = new Vector3f[3];
Vector2f[] texCoord = new Vector2f[3];
int[] index = new int[3];
ArrayList<Geometry> geoms = new ArrayList<Geometry>();
int i = 0;
int k = 0;
int z = 0;
for(Facet x : s.facets)
{
// Here i load the triangle data to vertex buffers
Triangle t = new Triangle(x.v[0],x.v[1],x.v[2]);
normals[0] = x.n;
normals[1] = x.n;
normals[2] = x.n;
tr.add(t);
index[0] = 2;
index[1] = 1;
index[2] = 0;
verti[0] = x.v[0];
verti[1] = x.v[1];
verti[2] = x.v[2];
// I have no idea what i am doing here - helpful advice/link explaining uv coordinates and texture coord buffer is greatly needed
texCoord[0] = new Vector2f(1,0);
texCoord[1] = new Vector2f(0,1);
texCoord[2] = new Vector2f(1,1);
Mesh mymesh = new Mesh();
//mymesh.setMode(Mesh.Mode.Triangles);
mymesh.setBuffer(Type.Position, 3,BufferUtils.createFloatBuffer(verti));
mymesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mymesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
mymesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(index));
Geometry geom = new Geometry("Triangle", mymesh);
geoms.add(geom);
break;
// I just add one triangle for testing
}
Mesh outMesh = new Mesh();
GeometryBatchFactory.mergeGeometries(geoms, outMesh);
Geometry geom = new Geometry("", outMesh);// create cube geometry from the shape
TangentBinormalGenerator.generate(outMesh);
// This is a sphere from examples to test if the material renders - and it does
Sphere rock = new Sphere(32,32, 2f);
Geometry shiny_rock = new Geometry(“Shiny rock”, rock);
//rock.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
TangentBinormalGenerator.generate(rock); // for lighting effect
Material mat_lit = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat_lit.setTexture(“DiffuseMap”, assetManager.loadTexture(“Textures/Terrain/Pond/Pond.jpg”));
mat_lit.setTexture(“NormalMap”, assetManager.loadTexture(“Textures/Terrain/Pond/Pond_normal.png”));
mat_lit.setBoolean(“UseMaterialColors”,true);
mat_lit.setColor(“Specular”,ColorRGBA.White);
mat_lit.setColor(“Diffuse”,ColorRGBA.White);
mat_lit.setFloat(“Shininess”, 5f); // [1,128]
shiny_rock.setMaterial(mat_lit);
shiny_rock.setLocalTranslation(10,10,10); // Move it a bit
shiny_rock.rotate(1.6f, 0, 0); // Rotate it a bit
rootNode.attachChild(shiny_rock);
geom.setMaterial(mat_lit);
geom.move(-20f, -20f, -20f);
rootNode.attachChild(geom);
PointLight lamp_light = new PointLight();
lamp_light.setColor(ColorRGBA.Yellow);
lamp_light.setRadius(40000f);
lamp_light.setPosition(new Vector3f(-1f,-1f,1f));
rootNode.addLight(lamp_light);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(0,-20,-20).normalizeLocal());
sun.setColor(ColorRGBA.Blue);
rootNode.addLight(sun);
[/java]
If you help me and ever visit middle Europe i am buying you a keg of beer.
Piotr Lipert