| 103 | } |
| 104 | |
| 105 | SubMesh* Mesh::BuildSubMesh(const Primitive& primitive, const MeshParams& params) |
| 106 | { |
| 107 | NazaraAssert(m_impl, "Mesh should be created first"); |
| 108 | NazaraAssert(m_impl->animationType == AnimationType_Static, "Submesh building only works for static meshes"); |
| 109 | NazaraAssert(params.IsValid(), "Invalid parameters"); |
| 110 | NazaraAssert(params.vertexDeclaration->HasComponentOfType<Vector3f>(VertexComponent_Position), "The vertex declaration doesn't have a Vector3 position component"); |
| 111 | |
| 112 | Boxf aabb; |
| 113 | IndexBufferRef indexBuffer; |
| 114 | VertexBufferRef vertexBuffer; |
| 115 | |
| 116 | Matrix4f matrix(primitive.matrix); |
| 117 | matrix *= params.matrix; |
| 118 | |
| 119 | VertexDeclaration* declaration = params.vertexDeclaration; |
| 120 | |
| 121 | switch (primitive.type) |
| 122 | { |
| 123 | case PrimitiveType_Box: |
| 124 | { |
| 125 | unsigned int indexCount; |
| 126 | unsigned int vertexCount; |
| 127 | ComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount); |
| 128 | |
| 129 | indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags); |
| 130 | vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags); |
| 131 | |
| 132 | VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly); |
| 133 | |
| 134 | VertexPointers pointers; |
| 135 | pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal); |
| 136 | pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position); |
| 137 | pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent); |
| 138 | pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord); |
| 139 | |
| 140 | IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly); |
| 141 | GenerateBox(primitive.box.lengths, primitive.box.subdivision, matrix, primitive.textureCoords, pointers, indexMapper.begin(), &aabb); |
| 142 | break; |
| 143 | } |
| 144 | |
| 145 | case PrimitiveType_Cone: |
| 146 | { |
| 147 | unsigned int indexCount; |
| 148 | unsigned int vertexCount; |
| 149 | ComputeConeIndexVertexCount(primitive.cone.subdivision, &indexCount, &vertexCount); |
| 150 | |
| 151 | indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, params.indexBufferFlags); |
| 152 | vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, params.vertexBufferFlags); |
| 153 | |
| 154 | VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly); |
| 155 | |
| 156 | VertexPointers pointers; |
| 157 | pointers.normalPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Normal); |
| 158 | pointers.positionPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Position); |
| 159 | pointers.tangentPtr = vertexMapper.GetComponentPtr<Vector3f>(VertexComponent_Tangent); |
| 160 | pointers.uvPtr = vertexMapper.GetComponentPtr<Vector2f>(VertexComponent_TexCoord); |
| 161 | |
| 162 | IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly); |
no test coverage detected