Exemplo n.º 1
0
 public override void DoWork()
 {
     try
     {
         foreach (Vector3I vectori in this.CellBatch)
         {
             if (!this.m_isCancelled)
             {
                 VrVoxelMesh self = this.m_targetPhysics.CreateMesh(new MyCellCoord(this.Lod, vectori));
                 if (!this.m_isCancelled)
                 {
                     if (self.IsEmpty())
                     {
                         this.m_newShapes.Add(vectori, (HkBvCompressedMeshShape)HkShape.Empty);
                     }
                     else
                     {
                         this.m_newShapes.Add(vectori, this.m_targetPhysics.CreateShape(self, this.Lod));
                     }
                     if (self != null)
                     {
                         self.Dispose();
                     }
                     continue;
                 }
             }
             break;
         }
     }
     finally
     {
     }
 }
Exemplo n.º 2
0
 public override void DoWork()
 {
     try
     {
         if (!this.m_isCancelled)
         {
             using (VrVoxelMesh mesh = this.m_args.TargetPhysics.CreateMesh(this.m_args.GeometryCell))
             {
                 if (!mesh.IsEmpty())
                 {
                     if (!this.m_isCancelled)
                     {
                         this.Result = this.m_args.TargetPhysics.CreateShape(mesh, this.m_args.GeometryCell.Lod);
                     }
                     else
                     {
                         return;
                     }
                 }
             }
             this.ResultComplete = true;
         }
     }
     finally
     {
     }
 }
Exemplo n.º 3
0
 private void RequestShapeBatchBlockingInternal(HkShapeBatch info, bool lod1physics)
 {
     if (!MyPhysics.InsideSimulation && !ReferenceEquals(Thread.CurrentThread, MyUtils.MainThread))
     {
         MyLog.Default.Error("Invalid request shape Thread id: " + Thread.CurrentThread.ManagedThreadId.ToString() + " Stack trace: " + Environment.StackTrace, Array.Empty <object>());
     }
     if (!this.m_voxelMap.MarkedForClose)
     {
         if (!this.m_bodiesInitialized)
         {
             this.CreateRigidBodies();
         }
         this.m_needsShapeUpdate = true;
         int count = info.Count;
         if (((count > 0x4e20) || (Interlocked.Add(ref this.m_voxelQueriesInLastFrames, count) >= 0x2710)) && (Interlocked.Exchange(ref this.m_hasExtendedCache, 1) == 0))
         {
             HkUniformGridShape shape;
             Interlocked.Increment(ref ActiveVoxelPhysicsBodiesWithExtendedCache);
             if (this.GetShape(lod1physics ? 1 : 0, out shape))
             {
                 shape.EnableExtendedCache();
             }
         }
         Parallel.For(0, count, delegate(int i) {
             Vector3I vectori;
             info.GetInfo(i, out vectori);
             int lod = lod1physics ? 1 : 0;
             MyCellCoord geometryCellCoord = new MyCellCoord(lod, vectori);
             if (MyDebugDrawSettings.DEBUG_DRAW_REQUEST_SHAPE_BLOCKING)
             {
                 BoundingBoxD xd;
                 MyVoxelCoordSystems.GeometryCellCoordToWorldAABB(this.m_voxelMap.PositionLeftBottomCorner, ref geometryCellCoord, out xd);
                 MyRenderProxy.DebugDrawAABB(xd, lod1physics ? Color.Yellow : Color.Red, 1f, 1f, false, false, false);
             }
             bool flag = false;
             HkBvCompressedMeshShape empty        = (HkBvCompressedMeshShape)HkShape.Empty;
             MyPrecalcJobPhysicsPrefetch prefetch = this.m_workTracker.Cancel(geometryCellCoord);
             if (((prefetch != null) && prefetch.ResultComplete) && (Interlocked.Exchange(ref prefetch.Taken, 1) == 0))
             {
                 flag  = true;
                 empty = prefetch.Result;
             }
             if (!flag)
             {
                 VrVoxelMesh mesh = this.CreateMesh(geometryCellCoord);
                 empty            = this.CreateShape(mesh, lod);
                 if (mesh != null)
                 {
                     mesh.Dispose();
                 }
             }
             info.SetResult(i, ref empty);
         }, 1, WorkPriority.VeryHigh, new WorkOptions?(Parallel.DefaultOptions.WithDebugInfo(MyProfiler.TaskType.Voxels, "RequestBatch")), true);
     }
 }
Exemplo n.º 4
0
 public unsafe void PostProcess(VrVoxelMesh mesh, MyStorageDataTypeFlags dataTypes)
 {
     if (dataTypes.Requests(MyStorageDataTypeEnum.Material))
     {
         VrVoxelVertex *vertices    = mesh.Vertices;
         int            vertexCount = mesh.VertexCount;
         Vector3        start       = (Vector3)mesh.Start;
         float          scale       = mesh.Scale;
         for (int i = 0; i < vertexCount; i++)
         {
             Vector3 position = (start + vertices[i].Position) * scale;
             Vector3 vector3  = this.Material.GetColorShift(position, vertices[i].Material, 1024f);
             if (vector3 != Vector3.Zero)
             {
                 vertices[i].Color.PackedValue = PackColorShift(vector3 * new Vector3(360f, 100f, 100f));
             }
         }
     }
 }
Exemplo n.º 5
0
        internal unsafe HkBvCompressedMeshShape CreateShape(VrVoxelMesh mesh, int lod)
        {
            HkBvCompressedMeshShape shape;

            if (((mesh == null) || (mesh.TriangleCount == 0)) || (mesh.VertexCount == 0))
            {
                return((HkBvCompressedMeshShape)HkShape.Empty);
            }
            using (MyUtils.ReuseCollection <int>(ref m_indexListCached))
            {
                using (MyUtils.ReuseCollection <Vector3>(ref m_vertexListCached))
                {
                    using (MyUtils.ReuseCollection <byte>(ref m_materialListCached))
                    {
                        List <int>     indexListCached    = m_indexListCached;
                        List <Vector3> vertexListCached   = m_vertexListCached;
                        List <byte>    materialListCached = m_materialListCached;
                        vertexListCached.EnsureCapacity <Vector3>(mesh.VertexCount);
                        indexListCached.EnsureCapacity <int>(mesh.TriangleCount * 3);
                        materialListCached.EnsureCapacity <byte>(mesh.TriangleCount);
                        int index = 0;
                        while (true)
                        {
                            if (index >= mesh.TriangleCount)
                            {
                                float          scale    = mesh.Scale;
                                VrVoxelVertex *vertices = mesh.Vertices;
                                Vector3        vector   = (Vector3)((mesh.Start * scale) - (this.m_voxelMap.StorageMin * 1f));
                                int            num4     = 0;
                                while (true)
                                {
                                    if (num4 >= mesh.VertexCount)
                                    {
                                        uint userData = 0xfffffffe;
                                        int  num5     = 0;
                                        while (true)
                                        {
                                            if (num5 >= mesh.TriangleCount)
                                            {
                                                int[] pinned numArray;
                                                try
                                                {
                                                    int *numPtr;
                                                    byte[] pinned buffer;
                                                    if (((numArray = indexListCached.GetInternalArray <int>()) == null) || (numArray.Length == 0))
                                                    {
                                                        numPtr = null;
                                                    }
                                                    else
                                                    {
                                                        numPtr = numArray;
                                                    }
                                                    try
                                                    {
                                                        byte *numPtr2;
                                                        Vector3[] pinned vectorArray;
                                                        if (((buffer = materialListCached.GetInternalArray <byte>()) == null) || (buffer.Length == 0))
                                                        {
                                                            numPtr2 = null;
                                                        }
                                                        else
                                                        {
                                                            numPtr2 = buffer;
                                                        }
                                                        try
                                                        {
                                                            Vector3 *vectorPtr;
                                                            if (((vectorArray = vertexListCached.GetInternalArray <Vector3>()) == null) || (vectorArray.Length == 0))
                                                            {
                                                                vectorPtr = null;
                                                            }
                                                            else
                                                            {
                                                                vectorPtr = vectorArray;
                                                            }
                                                            float physicsConvexRadius = MyPerGameSettings.PhysicsConvexRadius;
                                                            if (userData == -2)
                                                            {
                                                                userData = uint.MaxValue;
                                                            }
                                                            HkBvCompressedMeshShape local1 = new HkBvCompressedMeshShape(vectorPtr, vertexListCached.Count, numPtr, indexListCached.Count, numPtr2, materialListCached.Count, HkWeldingType.None, physicsConvexRadius);
                                                            HkShape.SetUserData((HkShape)local1, userData);
                                                            shape = local1;
                                                        }
                                                        finally
                                                        {
                                                            vectorArray = null;
                                                        }
                                                    }
                                                    finally
                                                    {
                                                        buffer = null;
                                                    }
                                                }
                                                finally
                                                {
                                                    numArray = null;
                                                }
                                                break;
                                            }
                                            VrVoxelTriangle triangle = mesh.Triangles[num5];
                                            byte            material = vertices[triangle.V0].Material;
                                            if (userData == -2)
                                            {
                                                userData = material;
                                            }
                                            else if (userData != material)
                                            {
                                                userData = uint.MaxValue;
                                            }
                                            materialListCached.Add(material);
                                            num5++;
                                        }
                                        break;
                                    }
                                    vertexListCached.Add((vertices[num4].Position * scale) + vector);
                                    num4++;
                                }
                                break;
                            }
                            indexListCached.Add(mesh.Triangles[index].V0);
                            indexListCached.Add(mesh.Triangles[index].V2);
                            indexListCached.Add(mesh.Triangles[index].V1);
                            index++;
                        }
                    }
                }
            }
            return(shape);
        }