ManualObject* OgreNewtonMesh::CreateEntity (const String& name) const { ManualObject* const object = new ManualObject(name); int pointCount = GetPointCount(); int indexCount = GetTotalIndexCount(); dNewtonScopeBuffer<int> indexList (indexCount); dNewtonScopeBuffer<int> remapIndex (indexCount); dNewtonScopeBuffer<dNewtonMesh::dPoint> posits (pointCount); dNewtonScopeBuffer<dNewtonMesh::dPoint> normals (pointCount); dNewtonScopeBuffer<dNewtonMesh::dUV> uv0 (pointCount); dNewtonScopeBuffer<dNewtonMesh::dUV> uv1 (pointCount); GetVertexStreams(&posits[0], &normals[0], &uv0[0], &uv1[0]); void* const materialsHandle = BeginMaterialHandle (); for (int handle = GetMaterialIndex (materialsHandle); handle != -1; handle = GetNextMaterialIndex (materialsHandle, handle)) { int materialIndex = MaterialGetMaterial (materialsHandle, handle); int indexCount = MaterialGetIndexCount (materialsHandle, handle); MaterialGetIndexStream (materialsHandle, handle, &indexList[0]); MaterialMap::const_iterator materialItr = m_materialMap.find(materialIndex); //object->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST); object->begin(materialItr->second->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST); // ogre does not support shared vertex for sub mesh, we will have remap the vertex data int vertexCount = 0; memset (&remapIndex[0], 0xff, indexCount * sizeof (remapIndex[0])); for( int i = 0; i < indexCount; i ++) { int index = indexList[i]; if (remapIndex[index] == -1) { remapIndex[index] = vertexCount; object->position (posits[index].m_x, posits[index].m_y, posits[index].m_z); object->normal (normals[index].m_x, normals[index].m_y, normals[index].m_z); object->textureCoord (uv0[index].m_u, uv0[index].m_v); vertexCount ++; } indexList[i] = remapIndex[index]; } for (int i = 0; i < indexCount; i += 3) { object->triangle (indexList[i + 0], indexList[i + 1], indexList[i + 2]); } object->end(); } EndMaterialHandle (materialsHandle); return object; }
AST_expr* remapExpr(AST_expr* node, bool wrap_with_assign=true) { if (node == NULL) return NULL; AST_expr* rtn; switch (node->type) { case AST_TYPE::Attribute: rtn = remapAttribute(static_cast<AST_Attribute*>(node)); break; case AST_TYPE::BinOp: rtn = remapBinOp(static_cast<AST_BinOp*>(node)); break; case AST_TYPE::BoolOp: rtn = remapBoolOp(static_cast<AST_BoolOp*>(node)); break; case AST_TYPE::Call: rtn = remapCall(static_cast<AST_Call*>(node)); break; case AST_TYPE::Compare: rtn = remapCompare(static_cast<AST_Compare*>(node)); break; case AST_TYPE::Dict: rtn = remapDict(static_cast<AST_Dict*>(node)); break; case AST_TYPE::IfExp: rtn = remapIfExp(static_cast<AST_IfExp*>(node)); break; case AST_TYPE::Index: rtn = remapIndex(static_cast<AST_Index*>(node)); break; case AST_TYPE::List: rtn = remapList(static_cast<AST_List*>(node)); break; case AST_TYPE::ListComp: rtn = remapListComp(static_cast<AST_ListComp*>(node)); break; case AST_TYPE::Name: return node; case AST_TYPE::Num: return node; case AST_TYPE::Slice: rtn = remapSlice(static_cast<AST_Slice*>(node)); break; case AST_TYPE::Str: return node; case AST_TYPE::Subscript: rtn = remapSubscript(static_cast<AST_Subscript*>(node)); break; case AST_TYPE::Tuple: rtn = remapTuple(static_cast<AST_Tuple*>(node)); break; case AST_TYPE::UnaryOp: rtn = remapUnaryOp(static_cast<AST_UnaryOp*>(node)); break; default: RELEASE_ASSERT(0, "%d", node->type); } if (wrap_with_assign && rtn->type != AST_TYPE::Name) { std::string name = nodeName(node); push_back(makeAssign(name, rtn)); return makeName(name, AST_TYPE::Load); } else { return rtn; } }