public CenterPointedMesh(BigMesh bigMesh) { this.bigMesh = bigMesh; centerPoint = GetCenter( bigMesh.triangleStripList .SelectMany(triangleStrip => triangleStrip.vertexIndices) .Select(index => bigMesh.vertexList[index]) ); }
public static IEnumerable <BigMesh> Split(BigMesh bigMesh) { var stripIndex = 0; var maxStrip = bigMesh.triangleStripList.Count; while (stripIndex < maxStrip) { var smallMesh = new BigMesh { textureIndex = bigMesh.textureIndex, matDef = bigMesh.matDef, }; var localIndexMap = new Dictionary <int, int>(); var countStocked = 0; for (; stripIndex < maxStrip; stripIndex++) { var triStrip = bigMesh.triangleStripList[stripIndex]; if (countStocked + triStrip.vertexIndices.Count > MaxVertCount) { break; } var newTriStrip = new BigMesh.TriangleStrip { uvList = triStrip.uvList.ToList(), vertexColorList = triStrip.vertexColorList.ToList(), vertexIndices = triStrip.vertexIndices .Select(gi => MapToLocal(localIndexMap, gi)) .ToList(), }; smallMesh.triangleStripList.Add(newTriStrip); countStocked += newTriStrip.vertexIndices.Count; } var globalIndexMap = localIndexMap .ToDictionary(pair => pair.Value, pair => pair.Key); smallMesh.textureIndex = bigMesh.textureIndex; for (int loop = 0; loop < localIndexMap.Count; loop++) { var globalIndex = globalIndexMap[loop]; smallMesh.vertexList.Add(bigMesh.vertexList[globalIndex]); } yield return(smallMesh); } }
public MapVifPacketBuilder( BigMesh mesh ) { var nLarge = mesh.triangleStripList.Sum(it => it.vertexIndices.Count); var nSmall = mesh.vertexList.Count; var top = new TopHeader { numVertIdx = nLarge, offVertIdx = 4, numClrVert = nLarge, offClrVert = 4 + nLarge, numPosVert = nSmall, offPosVert = 4 + nLarge + nLarge, }; { var writer = new BinaryWriter(vifPacket); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write(0x6C048000); // unpack V4-32 c 4 a 000 usn 0 flg 1 m 0 BinaryMapping.WriteObject(vifPacket, top); vifPacket.AlignPosition(4); { // write uv var off = 4; var num = Convert.ToByte(nLarge); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write((int)(0x65008000 | off | (num << 16))); // unpack V2-16 c 14 a 004 usn 0 flg 1 m 0 foreach (var one in mesh.triangleStripList.SelectMany(it => it.uvList)) { writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.X * 4096))))); writer.Write(Convert.ToInt16(Math.Max(-32768, Math.Min(32767, (one.Y * 4096))))); } } vifPacket.AlignPosition(4); { // write idx var off = 4; var num = Convert.ToByte(nLarge); writer.Write(0x20000000); // stmask 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 3 writer.Write(0xcfcfcfcf); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 foreach (var one in mesh.triangleStripList.SelectMany(it => it.vertexIndices)) { writer.Write(Convert.ToByte(one)); } } vifPacket.AlignPosition(4); { // write flags var off = 4; var num = Convert.ToByte(nLarge); writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 writer.Write(0x3f3f3f3f); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write((int)(0x7200C000 | off | (num << 16))); // unpack S-8 c 14 a 004 usn 1 flg 1 m 1 foreach (var triStrip in mesh.triangleStripList) { var count = triStrip.vertexIndices.Count; if (count >= 1) { writer.Write((byte)0x10); if (count >= 2) { writer.Write((byte)0x10); for (var x = 2; x < count; x++) { if (0 == (x & 1)) { writer.Write((byte)0x20); } else { writer.Write((byte)0x30); } } } } } } vifPacket.AlignPosition(4); { // write vertex color list var off = 4 + nLarge; var num = Convert.ToByte(nLarge); writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 writer.Write(0x3f3f3f3f); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write((int)(0x6E00C000 | off | (num << 16))); // unpack V4-8 c 14 a 012 usn 1 flg 1 m 0 foreach (var color in mesh.triangleStripList.SelectMany(it => it.vertexColorList)) { writer.Write(color.r); writer.Write(color.g); writer.Write(color.b); writer.Write(color.a); } } vifPacket.AlignPosition(4); { // write vertices var off = 4 + nLarge + nLarge; var num = Convert.ToByte(nSmall); writer.Write(0x31000000); // stcol 3f800000 3f800000 3f800000 3f800000 writer.Write(0x3f800000); writer.Write(0x3f800000); writer.Write(0x3f800000); writer.Write(0x3f800000); writer.Write(0x20000000); // stmask 3 3 3 0 3 3 3 0 3 3 3 0 3 3 3 0 writer.Write(0x80808080); writer.Write(0x01000101); // stcycl cl 01 wl 01 writer.Write((int)(0x78008000 | off | (num << 16))); // unpack V3-32 c 9 a 020 usn 0 flg 1 m 1 foreach (var one in mesh.vertexList) { writer.Write(one.X); writer.Write(one.Y); writer.Write(one.Z); } } vifPacket.AlignPosition(4); writer.Write(0x17000000); // mscnt } Align16Plus8(vifPacket); firstVifPacketQwc = Convert.ToUInt16(vifPacket.Length / 16); vifPacket.Write(new byte[8], 0, 8); // write later 8 bytes of the follwing dma (id=RET) packet. }
private byte[] BuildNavmesh() { IEnumerable <Collider> colliders = GatherColliders(this.walkableLayers); Bounds bounds = new Bounds(this.center, this.size); BigCombineInstance[] combineInstances = MakeCombineInstanceArray(colliders, bounds); if (combineInstances.Length == 0) { Debug.LogError("No colliders found"); return(null); } BigMesh m = new BigMesh(combineInstances); Debug.Log(string.Format( "Combined {0} meshes, {1} vertices, {2} triangles", combineInstances.Length, m.vertices.Length, m.triangles.Length / 3)); int dataSize = NativeBuildNavmesh( m.vertices.Length, m.vertices, m.triangles.Length, m.triangles, bounds.min.x, bounds.min.y, bounds.min.z, bounds.max.x, bounds.max.y, bounds.max.z, this.cellSize, this.cellHeight, this.walkableHeight, this.walkableSlopeAngle, this.walkableClimb, this.walkableRadius, this.maxEdgeLen, this.maxSimplificationError, this.monotonePartitioning, this.minRegionArea, this.mergeRegionArea, this.detailSampleDist, this.detailSampleMaxError, this.keepIntermediateData, 1000000); if (dataSize <= 0) { Debug.LogError("Error during navmesh generation: " + dataSize); return(null); } else { Debug.Log("Built navmesh of size " + dataSize); } byte[] buffer = new byte[dataSize]; NativeRetrieveNavmeshData(buffer); return(buffer); }
private byte[] BuildNavmesh() { IEnumerable<Collider> colliders = GatherColliders(this.walkableLayers); Bounds bounds = new Bounds(this.center, this.size); BigCombineInstance[] combineInstances = MakeCombineInstanceArray(colliders, bounds); if (combineInstances.Length == 0) { Debug.LogError("No colliders found"); return null; } BigMesh m = new BigMesh(combineInstances); Debug.Log(string.Format( "Combined {0} meshes, {1} vertices, {2} triangles", combineInstances.Length, m.vertices.Length, m.triangles.Length / 3)); int dataSize = NativeBuildNavmesh( m.vertices.Length, m.vertices, m.triangles.Length, m.triangles, bounds.min.x, bounds.min.y, bounds.min.z, bounds.max.x, bounds.max.y, bounds.max.z, this.cellSize, this.cellHeight, this.walkableHeight, this.walkableSlopeAngle, this.walkableClimb, this.walkableRadius, this.maxEdgeLen, this.maxSimplificationError, this.monotonePartitioning, this.minRegionArea, this.mergeRegionArea, this.detailSampleDist, this.detailSampleMaxError, this.keepIntermediateData, 1000000); if (dataSize <= 0) { Debug.LogError("Error during navmesh generation: " + dataSize); return null; } else { Debug.Log("Built navmesh of size " + dataSize); } byte[] buffer = new byte[dataSize]; NativeRetrieveNavmeshData(buffer); return buffer; }