コード例 #1
0
        private void AddMeshTriangles(MyIsoMesh mesh, Vector3 offset, Matrix rotation, Matrix ownRotation)
        {
            for (int i = 0; i < mesh.TrianglesCount; i++)
            {
                ushort a = mesh.Triangles[i].VertexIndex0;
                ushort b = mesh.Triangles[i].VertexIndex1;
                ushort c = mesh.Triangles[i].VertexIndex2;
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + c);
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + b);
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + a);
            }

            for (int i = 0; i < mesh.VerticesCount; i++)
            {
                Vector3 vert;
                mesh.GetUnpackedPosition(i, out vert);
                Vector3.Transform(ref vert, ref ownRotation, out vert);
                vert -= offset;
                Vector3.Transform(ref vert, ref rotation, out vert);

                m_worldVertices.Vertices.Add(vert);
            }

            m_worldVertices.VerticesMaxValue += mesh.VerticesCount;
        }
コード例 #2
0
        private unsafe void AddMeshTriangles(MyIsoMesh mesh, Vector3 offset, Matrix rotation, Matrix ownRotation)
        {
            for (int i = 0; i < mesh.TrianglesCount; i++)
            {
                ushort num2 = mesh.Triangles[i].V0;
                ushort num3 = mesh.Triangles[i].V1;
                ushort num4 = mesh.Triangles[i].V2;
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num4);
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num3);
                m_worldVertices.Triangles.Add(m_worldVertices.VerticesMaxValue + num2);
            }
            for (int j = 0; j < mesh.VerticesCount; j++)
            {
                Vector3 vector;
                mesh.GetUnpackedPosition(j, out vector);
                Vector3 *vectorPtr1 = (Vector3 *)ref vector;
                Vector3.Transform(ref (Vector3) ref vectorPtr1, ref ownRotation, out vector);
                vector -= offset;
                Vector3 *vectorPtr2 = (Vector3 *)ref vector;
                Vector3.Transform(ref (Vector3) ref vectorPtr2, ref rotation, out vector);
                m_worldVertices.Vertices.Add(vector);
            }
            WorldVerticesInfo worldVertices = m_worldVertices;

            worldVertices.VerticesMaxValue += mesh.VerticesCount;
        }
コード例 #3
0
 private void PreprocessTriangles(MyIsoMesh generatedMesh, Vector3 centerDisplacement)
 {
     for (int i = 0; i < generatedMesh.TrianglesCount; i++)
     {
         Vector3 vector3;
         ushort  idx  = generatedMesh.Triangles[i].V0;
         ushort  num3 = generatedMesh.Triangles[i].V1;
         ushort  num4 = generatedMesh.Triangles[i].V2;
         generatedMesh.GetUnpackedPosition(idx, out vector3);
         Vector3 vector = vector3 - centerDisplacement;
         generatedMesh.GetUnpackedPosition(num3, out vector3);
         Vector3 vector2 = vector3 - centerDisplacement;
         generatedMesh.GetUnpackedPosition(num4, out vector3);
         bool flag = false;
         if ((vector2 - vector).LengthSquared() <= MyVoxelConnectionHelper.OUTER_EDGE_EPSILON_SQ)
         {
             m_vertexMapping.Union(idx, num3);
             flag = true;
         }
         Vector3 vector1 = vector3 - centerDisplacement;
         if (((vector3 - centerDisplacement) - vector).LengthSquared() <= MyVoxelConnectionHelper.OUTER_EDGE_EPSILON_SQ)
         {
             m_vertexMapping.Union(idx, num4);
             flag = true;
         }
         Vector3 vector4 = (vector3 - centerDisplacement) - vector2;
         if (vector4.LengthSquared() <= MyVoxelConnectionHelper.OUTER_EDGE_EPSILON_SQ)
         {
             m_vertexMapping.Union(num3, num4);
             flag = true;
         }
         if (!flag)
         {
             this.m_connectionHelper.PreprocessInnerEdge(idx, num3);
             this.m_connectionHelper.PreprocessInnerEdge(num3, num4);
             this.m_connectionHelper.PreprocessInnerEdge(num4, idx);
         }
     }
 }
コード例 #4
0
        private unsafe void AddVoxelMesh(MyVoxelBase voxelBase, IMyStorage storage, Dictionary <Vector3I, MyIsoMesh> cache, float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List <BoundingBoxD> bbList)
        {
            Vector3I vectori3;
            Vector3I vectori4;
            bool     flag = cache != null;

            if (flag)
            {
                this.CheckCacheValidity();
            }
            Vector3D *vectordPtr1 = (Vector3D *)ref obb.HalfExtent;

            vectordPtr1[0] += new Vector3D((double)border, 0.0, (double)border);
            BoundingBoxD  aABB   = obb.GetAABB();
            int           num    = (int)Math.Round((double)(aABB.HalfExtents.Max() * 2.0));
            BoundingBoxD *xdPtr1 = (BoundingBoxD *)ref aABB;

            xdPtr1 = (BoundingBoxD *)new BoundingBoxD(aABB.Min, aABB.Min + num);
            ((BoundingBoxD *)ref aABB).Translate(obb.Center - aABB.Center);
            bbList.Add(new BoundingBoxD(aABB.Min, aABB.Max));
            aABB = aABB.TransformFast(voxelBase.PositionComp.WorldMatrixInvScaled);
            aABB.Translate(voxelBase.SizeInMetresHalf);
            Vector3I voxelCoord = Vector3I.Round(aABB.Min);
            Vector3I vectori2   = (Vector3I)(voxelCoord + num);

            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref voxelCoord, out vectori3);
            MyVoxelCoordSystems.VoxelCoordToGeometryCellCoord(ref vectori2, out vectori4);
            MyOrientedBoundingBoxD xd2 = obb;

            xd2.Transform(voxelBase.PositionComp.WorldMatrixInvScaled);
            Vector3D *vectordPtr2 = (Vector3D *)ref xd2.Center;

            vectordPtr2[0] += voxelBase.SizeInMetresHalf;
            Vector3I_RangeIterator iterator = new Vector3I_RangeIterator(ref vectori3, ref vectori4);
            MyCellCoord            coord    = new MyCellCoord {
                Lod = 0
            };
            int     num2        = 0;
            Vector3 offset      = (Vector3)(originPosition - voxelBase.PositionLeftBottomCorner);
            Vector3 up          = -Vector3.Normalize(MyGravityProviderSystem.CalculateTotalGravityInPoint(originPosition));
            Matrix  rotation    = Matrix.CreateFromQuaternion(Quaternion.Inverse(Quaternion.CreateFromForwardUp(Vector3.CalculatePerpendicularVector(up), up)));
            Matrix  orientation = (Matrix)voxelBase.PositionComp.WorldMatrix.GetOrientation();

            while (iterator.IsValid())
            {
                BoundingBox box;
                MyIsoMesh   mesh;
                if (flag && cache.TryGetValue(iterator.Current, out mesh))
                {
                    if (mesh != null)
                    {
                        this.AddMeshTriangles(mesh, offset, rotation, orientation);
                    }
                    iterator.MoveNext();
                    continue;
                }
                coord.CoordInLod = iterator.Current;
                MyVoxelCoordSystems.GeometryCellCoordToLocalAABB(ref coord.CoordInLod, out box);
                if (!xd2.Intersects(ref box))
                {
                    num2++;
                    iterator.MoveNext();
                }
                else
                {
                    BoundingBoxD item = new BoundingBoxD(box.Min, box.Max).Translate(-voxelBase.SizeInMetresHalf);
                    bbList.Add(item);
                    Vector3I  lodVoxelMin = (coord.CoordInLod * 8) - 1;
                    MyIsoMesh mesh2       = MyPrecalcComponent.IsoMesher.Precalc(storage, 0, lodVoxelMin, (Vector3I)(((lodVoxelMin + 8) + 1) + 1), MyStorageDataTypeFlags.Content, 0);
                    if (flag)
                    {
                        cache[iterator.Current] = mesh2;
                    }
                    if (mesh2 != null)
                    {
                        this.AddMeshTriangles(mesh2, offset, rotation, orientation);
                    }
                    iterator.MoveNext();
                }
            }
        }