Hi there,
I'm trying to test whether 3d mesh with Hemesh can be used for rendering 3d femur.. I want to create 3d mesh out of coordinate list in the form of xyz file.
once rendered, it seems slow and a bit distorted.. anyone has any idea how to optimize and improve the rendering?
- import wblut.math.*;
- import wblut.processing.*;
- import wblut.core.*;
- import wblut.hemesh.*;
- import wblut.geom.*;
- import processing.opengl.*;
- HE_Mesh mesh;
- WB_Render render;
- void setup() {
- size(600, 600, OPENGL);
- smooth();
- //Custom mesh creation is easiest by creating an array of vertices and the corresponding faces
- //and calling the faceList creator. Writing a full-blown implementation of a HEC_Creator
- //is best done in Eclipse with full access to the code repository.
- // //Array of all vertices
- float [][] vertices = new float [7502][3];
- int index = 0;
- String[] strLines = loadStrings("Femur.xyz");
- for (int i = 0; i < strLines.length; ++i) {
- String[] arrTokens = split(strLines[i], ' ');
- float xx = float(arrTokens[0]);
- float yy = float(arrTokens[1]);
- float zz = float(arrTokens[2]);
- vertices[index][0] = xx;
- vertices[index][1] = yy;
- vertices[index][2] = zz;
- index++;
- }
- //Array of faces. Each face is an arry of vertex indices;
- index=0;
- int[][] faces = new int[7327][3];
- for (int j = 0; j < 85; j++) {
- for (int i = 0; i < 85; i++) {
- faces[index]=new int[4];
- faces[index][0] = i + 86 * j;
- faces[index][1] = i + 1 + 86 * j;
- faces[index][2] = i + 1 + 86 * (j + 1);
- faces[index][3] = i + 86 * (j + 1);
- index++;
- }
- }
- //HEC_Facelist uses the vertices and the indexed faces to create a mesh with all connectivity.
- HEC_FromFacelist facelistCreator=new HEC_FromFacelist().setVertices(vertices).setFaces(faces).setDuplicate(false);
- mesh=new HE_Mesh(facelistCreator);
- //check mesh validity, surfaces meshes will have "Null reference (face)" for the outer halfedges.
- //other messages could refer to inconsistent face orientation, missing faces or meshes not representable by
- //the hemesh datastructure
- mesh.validate(true, true);
- //This should work
- // mesh.modify(new HEM_Lattice().setDepth(5).setWidth(5));
- mesh.subdivide(new HES_Smooth());
- render=new WB_Render(this);
- }
- void draw() {
- background(120);
- lights();
- translate(300, 300, 0);
- rotateY(mouseX*1.0f/width*TWO_PI);
- rotateX(mouseY*1.0f/height*TWO_PI);
- noStroke();
- render.drawFaces(mesh);
- stroke(0);
- render.drawEdges(mesh);
- }
1