Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VolumeMapView::_manualFromMesh(PolyVox::SurfaceMesh* mesh, Ogre::ManualObject* manual)
- {
- const float ATLAS_WIDTH = 512.0f;
- const float TEX_WIDTH = 32.0f;
- const float BlockOffset = TEX_WIDTH / ATLAS_WIDTH;
- const float pixelOffset = 1.0 / ATLAS_WIDTH;
- const float blockEOffset = 1.0 / TEX_WIDTH;
- using std::vector;
- const vector<uint32_t>& indices = mesh->getIndices();
- const vector<SurfaceVertex>& vertices = mesh->getVertices();
- if(vertices.size() < 1)
- return;
- //Build the Ogre Manual Object. We first iterate through the vertices add position to that.
- //
- const Ogre::Vector2 texCoords[4] =
- { Ogre::Vector2(0.0f, 1.0f), Ogre::Vector2(1.0f, 1.0f), Ogre::Vector2(0.0f, 0.0f), Ogre::Vector2(1.0f, 0.0f) };
- size_t texIdx = 0;
- _manual->estimateVertexCount(indices.size());
- _manual->estimateVertexCount(vertices.size());
- _manual->begin("PRJZ/Minecraft", Ogre::RenderOperation::OT_TRIANGLE_LIST, "PROJECT_ZOMBIE");
- for (vector<SurfaceVertex>::const_iterator itVertex = vertices.begin(); itVertex != vertices.end(); ++itVertex)
- {
- const SurfaceVertex& vertex = *itVertex;
- const Vector3DFloat& vertPos = vertex.getPosition();
- //const Vector3DFloat& finalPos = vertPos + static_cast<Vector3DFloat> (mesh.m_Region.getLowerCorner());
- Vector3DFloat origin(_origin.x, _origin.y, _origin.z);
- const Vector3DFloat& finalPos = vertPos + origin;
- manual->position(finalPos.getX(), finalPos.getY(), finalPos.getZ());
- manual->normal(vertex.getNormal().getX(), vertex.getNormal().getY(), vertex.getNormal().getZ());
- //Assume that the passed in position are counter clockwise starting from top left corner.
- manual->textureCoord(texCoords[texIdx % 4]);
- texIdx++;
- Ogre::ColourValue val;
- uint8_t material = vertex.getMaterial() + 0.5;
- val.r = (float) (material - 1) * BlockOffset;// - pixelOffset;
- val.g = 0.0f;
- val.b = 0.0f;
- val.a = 1.0f;
- manual->colour(val);
- }
- //Then iterate through the indices add create the indices list.
- for (vector<uint32_t>::const_iterator itIdx = indices.begin(); itIdx != indices.end(); ++itIdx)
- {
- manual->index(*itIdx);
- uint32_t ix = *itIdx;
- //cout << "INDEX!: " << ix << endl;
- }
- manual->end();
- //add it to root scene.
- _root->attachObject(manual);
- _root->setVisible(true);
- //scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
- }
Advertisement
Add Comment
Please, Sign In to add comment