Esempio n. 1
0
	TriMesh<FloatType> Shapes<FloatType>::wireframeBox(FloatType dim, const vec4<FloatType>& color, FloatType thickness) {
		MLIB_WARNING("untested function");
		FloatType cubeVData[8][3] = {
			{ 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f },
			{ 1.0f, -1.0f, 1.0f }, { 1.0f, 1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f },
			{ -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }
		};

		int cubeEData[12][2] = {
			{ 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 },
			{ 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 },
			{ 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 }
		};

		std::vector<ml::TriMesh<FloatType>> meshes;
		ml::vec3<FloatType> v[8];  std::memmove(v, cubeVData, sizeof(v[0]) * 8);
		for (uint i = 0; i < 12; i++) {
			meshes.push_back(line(dim * v[cubeEData[i][0]], dim * v[cubeEData[i][1]], color, thickness));
		}
		return meshutil::createUnifiedMesh(meshes);
	}
Esempio n. 2
0
	TriMesh<FloatType>::TriMesh( const MeshData<FloatType>& meshData )
	{

		m_Vertices.resize(meshData.m_Vertices.size());

		m_bHasNormals = meshData.m_Normals.size() > 0;
		m_bHasColors = meshData.m_Colors.size() > 0;
		m_bHasTexCoords = meshData.m_TextureCoords.size() > 0;

		for (size_t i = 0; i < m_Vertices.size(); i++) {
			m_Vertices[i].position = meshData.m_Vertices[i];
		}

		for (unsigned int i = 0; i < meshData.m_FaceIndicesVertices.size(); i++) {
			if (meshData.m_FaceIndicesVertices[i].size() == 3) {
				//we need to split vertices if the same vertex has different texcoords and/or normals
				bool bFaceHasNormals	= m_bHasNormals && meshData.getFaceIndicesNormals()[i].size() > 0;
				bool bFaceHasTexCoords	= m_bHasTexCoords && meshData.getFaceIndicesTexCoords()[i].size() > 0;
				bool bFaceHasColors		= m_bHasColors && meshData.getFaceIndicesColors()[i].size() > 0;

				if (bFaceHasNormals || bFaceHasTexCoords || bFaceHasColors) {
					vec3ui coords = vec3ui(0,0,0);
					for (unsigned int j = 0; j < 3; j++) {
						bool vertexSplit = false;
						if (bFaceHasNormals) { //split if normal is different than the one found before
							const point3d<FloatType>& n = meshData.m_Normals[meshData.getFaceIndicesNormals()[i][j]];
							if (m_Vertices[meshData.getFaceIndicesVertices()[i][j]].normal != point3d<FloatType>::origin && 
								m_Vertices[meshData.getFaceIndicesVertices()[i][j]].normal != n)	vertexSplit = true;
						}
						if (bFaceHasTexCoords) { //split if texcoord is different than the one found before
							const point2d<FloatType>& t = meshData.m_TextureCoords[meshData.getFaceIndicesTexCoords()[i][j]];
							if (m_Vertices[meshData.getFaceIndicesVertices()[i][j]].texCoord != point2d<FloatType>::origin && 
								m_Vertices[meshData.getFaceIndicesVertices()[i][j]].texCoord != t) vertexSplit = true;
						}
						if (bFaceHasColors) { //split if texcoord is different than the one found before
							const point4d<FloatType>& c = meshData.m_Colors[meshData.getFaceIndicesColors()[i][j]];
							if (m_Vertices[meshData.getFaceIndicesVertices()[i][j]].color != point4d<FloatType>::origin && 
								m_Vertices[meshData.getFaceIndicesVertices()[i][j]].color != c) vertexSplit = true;
						}

						if (vertexSplit) {
							MLIB_WARNING("vertex split untested");
							Vertex<FloatType> v = m_Vertices[meshData.getFaceIndicesVertices()[i][j]];
							if (bFaceHasNormals)		v.normal = meshData.m_Normals[meshData.getFaceIndicesNormals()[i][j]];
							if (bFaceHasTexCoords)	v.texCoord = meshData.m_TextureCoords[meshData.getFaceIndicesTexCoords()[i][j]];
							if (bFaceHasColors)		v.color = meshData.m_Colors[meshData.getFaceIndicesColors()[i][j]];
							m_Vertices.push_back(v);
							coords[j] = (unsigned int)m_Vertices.size() - 1;
						} else {
							if (bFaceHasNormals)		m_Vertices[meshData.getFaceIndicesVertices()[i][j]].normal = meshData.m_Normals[meshData.getFaceIndicesNormals()[i][j]];
							if (bFaceHasTexCoords)	m_Vertices[meshData.getFaceIndicesVertices()[i][j]].texCoord = meshData.m_TextureCoords[meshData.getFaceIndicesTexCoords()[i][j]];
							if (bFaceHasColors)		m_Vertices[meshData.getFaceIndicesVertices()[i][j]].color = meshData.m_Colors[meshData.getFaceIndicesColors()[i][j]];
							coords[j] = meshData.getFaceIndicesVertices()[i][j];
						}
					}
					m_Indices.push_back(coords);

					//m_Indices.push_back(vec3ui(meshData.m_FaceIndicesVertices[i][0], meshData.m_FaceIndicesVertices[i][1], meshData.m_FaceIndicesVertices[i][2]));
					//if (hasNormals) {
					//	//we are ignoring the fact that sometimes there might be vertex split required (if a vertex has two different normals)
					//	m_Vertices[m_Indices[i][0]].normal = meshData.m_Normals[meshData.m_FaceIndicesNormals[i][0]];
					//	m_Vertices[m_Indices[i][1]].normal = meshData.m_Normals[meshData.m_FaceIndicesNormals[i][1]];
					//	m_Vertices[m_Indices[i][2]].normal = meshData.m_Normals[meshData.m_FaceIndicesNormals[i][2]];
					//}
					//if (hasTexCoords) {
					//	//we are ignoring the fact that sometimes there might be vertex split required (if a vertex has two different normals)
					//	m_Vertices[m_Indices[i][0]].texCoord = meshData.m_TextureCoords[meshData.m_FaceIndicesTextureCoords[i][0]];
					//	m_Vertices[m_Indices[i][1]].texCoord = meshData.m_TextureCoords[meshData.m_FaceIndicesTextureCoords[i][1]];
					//	m_Vertices[m_Indices[i][2]].texCoord = meshData.m_TextureCoords[meshData.m_FaceIndicesTextureCoords[i][2]];
					//}
				} else {
					m_Indices.push_back(vec3ui(meshData.m_FaceIndicesVertices[i][0], meshData.m_FaceIndicesVertices[i][1], meshData.m_FaceIndicesVertices[i][2]));
				}
			} else {
				MLIB_WARNING("non triangle face found - ignoring it");
			}
		}
	}