| 53 | } |
| 54 | |
| 55 | Ref<SceneGraph::Node> geometry() |
| 56 | { |
| 57 | Ref<SceneGraph::MaterialNode> mnode = new OBJMaterial(1.0f,Vec3fa(1.0f),Vec3fa(0.0f),1.0f); |
| 58 | Ref<SceneGraph::TriangleMeshNode> mesh = new SceneGraph::TriangleMeshNode(mnode,1); |
| 59 | |
| 60 | const size_t width = texture->width; |
| 61 | const size_t height = texture->height; |
| 62 | |
| 63 | mesh->positions[0].resize(height*width); |
| 64 | for (size_t y=0; y<height; y++) |
| 65 | for (size_t x=0; x<width; x++) |
| 66 | mesh->positions[0][y*width+x] = at(x,y); |
| 67 | |
| 68 | mesh->triangles.resize(2*(height-1)*(width-1)); |
| 69 | for (size_t y=0; y<height-1; y++) { |
| 70 | for (size_t x=0; x<width-1; x++) { |
| 71 | const size_t p00 = (y+0)*width+(x+0); |
| 72 | const size_t p01 = (y+0)*width+(x+1); |
| 73 | const size_t p10 = (y+1)*width+(x+0); |
| 74 | const size_t p11 = (y+1)*width+(x+1); |
| 75 | const size_t tri = y*(width-1)+x; |
| 76 | mesh->triangles[2*tri+0] = SceneGraph::TriangleMeshNode::Triangle(unsigned(p00),unsigned(p01),unsigned(p10)); |
| 77 | mesh->triangles[2*tri+1] = SceneGraph::TriangleMeshNode::Triangle(unsigned(p01),unsigned(p11),unsigned(p10)); |
| 78 | } |
| 79 | } |
| 80 | return mesh.dynamicCast<SceneGraph::Node>(); |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | Ref<Image> texture; |
no test coverage detected