/// <summary> /// Finds an existing common vertex, or inserts a new one. /// </summary> /// <returns></returns> protected int FindOrCreateCommonVertex(Vector3 vec, int vertexSet, int indexSet, int originalIndex) { for (var index = 0; index < this.vertices.Count; index++) { var commonVec = (CommonVertex)this.vertices[index]; if (RealEqual(vec.x, commonVec.position.x, 1e-04f) && RealEqual(vec.y, commonVec.position.y, 1e-04f) && RealEqual(vec.z, commonVec.position.z, 1e-04f) && (commonVec.vertexSet == vertexSet || this.weldVerticesAcrossVertexSets) && (commonVec.indexSet == indexSet || this.weldVerticesAcrossIndexSets) && (commonVec.originalIndex == originalIndex || this.weldVertices)) { return(index); } } // Not found, insert var newCommon = new CommonVertex(); newCommon.index = this.vertices.Count; newCommon.position = vec; newCommon.vertexSet = vertexSet; newCommon.indexSet = indexSet; newCommon.originalIndex = originalIndex; this.vertices.Add(newCommon); return(newCommon.index); }
/// <summary> /// Finds an existing common vertex, or inserts a new one. /// </summary> /// <returns></returns> protected int FindOrCreateCommonVertex(Vector3 vec, int vertexSet, int indexSet, int originalIndex) { for (int index = 0; index < vertices.Count; index++) { CommonVertex commonVec = (CommonVertex)vertices[index]; if (MathUtil.FloatEqual(vec.x, commonVec.position.x, 1e-04f) && MathUtil.FloatEqual(vec.y, commonVec.position.y, 1e-04f) && MathUtil.FloatEqual(vec.z, commonVec.position.z, 1e-04f) && (commonVec.vertexSet == vertexSet || weldVerticesAcrossVertexSets) && (commonVec.indexSet == indexSet || weldVerticesAcrossIndexSets) && (commonVec.originalIndex == originalIndex || weldVertices)) { return(index); } } // Not found, insert CommonVertex newCommon = new CommonVertex(); newCommon.index = vertices.Count; newCommon.position = vec; newCommon.vertexSet = vertexSet; newCommon.indexSet = indexSet; newCommon.originalIndex = originalIndex; vertices.Add(newCommon); return(newCommon.index); }
public unsafe void DebugLog(Log log) { log.Write("EdgeListBuilder Log"); log.Write("-------------------"); log.Write("Number of vertex sets: {0}", vertexDataList.Count); log.Write("Number of index sets: {0}", indexDataList.Count); int i, j; // Log original vertex data for (i = 0; i < vertexDataList.Count; i++) { VertexData vData = (VertexData)vertexDataList[i]; log.Write("."); log.Write("Original vertex set {0} - vertex count {1}", i, vData.vertexCount); VertexElement posElem = vData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.Position); HardwareVertexBuffer vbuf = vData.vertexBufferBinding.GetBuffer(posElem.Source); // lock the buffer for reading IntPtr basePtr = vbuf.Lock(BufferLocking.ReadOnly); byte *pBaseVertex = (byte *)basePtr.ToPointer(); float *pReal; for (j = 0; j < vData.vertexCount; j++) { pReal = (float *)(pBaseVertex + posElem.Offset); log.Write("Vertex {0}: ({1}, {2}, {3})", j, pReal[0], pReal[1], pReal[2]); pBaseVertex += vbuf.VertexSize; } vbuf.Unlock(); } // Log original index data for (i = 0; i < indexDataList.Count; i += 3) { IndexData iData = (IndexData)indexDataList[i]; log.Write("."); log.Write("Original triangle set {0} - index count {1} - vertex set {2})", i, iData.indexCount, indexDataVertexDataSetList[i]); // Get the indexes ready for reading short *p16Idx = null; int * p32Idx = null; IntPtr idxPtr = iData.indexBuffer.Lock(BufferLocking.ReadOnly); if (iData.indexBuffer.Type == IndexType.Size32) { p32Idx = (int *)idxPtr.ToPointer(); } else { p16Idx = (short *)idxPtr.ToPointer(); } for (j = 0; j < iData.indexCount / 3; j++) { if (iData.indexBuffer.Type == IndexType.Size32) { log.Write("Triangle {0}: ({1}, {2}, {3})", j, *p32Idx++, *p32Idx++, *p32Idx++); } else { log.Write("Triangle {0}: ({1}, {2}, {3})", j, *p16Idx++, *p16Idx++, *p16Idx++); } } iData.indexBuffer.Unlock(); // Log common vertex list log.Write("."); log.Write("Common vertex list - vertex count {0}", vertices.Count); for (i = 0; i < vertices.Count; i++) { CommonVertex c = (CommonVertex)vertices[i]; log.Write("Common vertex {0}: (vertexSet={1}, originalIndex={2}, position={3}", i, c.vertexSet, c.index, c.position); } } }
/// <summary> /// Finds an existing common vertex, or inserts a new one. /// </summary> /// <returns></returns> protected int FindOrCreateCommonVertex(Vector3 vec, int vertexSet, int indexSet, int originalIndex) { for (int index = 0; index < vertices.Count; index++) { CommonVertex commonVec = (CommonVertex)vertices[index]; if (MathUtil.FloatEqual(vec.x, commonVec.position.x, 1e-04f) && MathUtil.FloatEqual(vec.y, commonVec.position.y, 1e-04f) && MathUtil.FloatEqual(vec.z, commonVec.position.z, 1e-04f) && (commonVec.vertexSet == vertexSet || weldVerticesAcrossVertexSets) && (commonVec.indexSet == indexSet || weldVerticesAcrossIndexSets) && (commonVec.originalIndex == originalIndex || weldVertices)) { return index; } } // Not found, insert CommonVertex newCommon = new CommonVertex(); newCommon.index = vertices.Count; newCommon.position = vec; newCommon.vertexSet = vertexSet; newCommon.indexSet = indexSet; newCommon.originalIndex = originalIndex; vertices.Add(newCommon); return newCommon.index; }