Exemple #1
0
        private void CreateInitialSimplex()
        {
            List <int> list = FindInitialPoints();

            int[] array = new int[NumOfDimensions + 1];
            for (int i = 0; i < NumOfDimensions + 1; i++)
            {
                int[] array2 = new int[NumOfDimensions];
                int   j      = 0;
                int   num    = 0;
                for (; j <= NumOfDimensions; j++)
                {
                    if (i != j)
                    {
                        if (j == list.Count)
                        {
                            int num2 = 0;
                            num2++;
                        }
                        int num3 = list[j];
                        array2[num++] = num3;
                    }
                }
                ConvexFaceInternal convexFaceInternal = FacePool[ObjectManager.GetFace()];
                convexFaceInternal.Vertices = array2;
                Array.Sort(array2);
                mathHelper.CalculateFacePlane(convexFaceInternal, Center);
                array[i] = convexFaceInternal.Index;
            }
            for (int k = 0; k < NumOfDimensions; k++)
            {
                for (int l = k + 1; l < NumOfDimensions + 1; l++)
                {
                    UpdateAdjacency(FacePool[array[k]], FacePool[array[l]]);
                }
            }
            int[] array3 = array;
            foreach (int num5 in array3)
            {
                ConvexFaceInternal convexFaceInternal2 = FacePool[num5];
                FindBeyondVertices(convexFaceInternal2);
                if (convexFaceInternal2.VerticesBeyond.Count == 0)
                {
                    ConvexFaces.Add(convexFaceInternal2.Index);
                }
                else
                {
                    UnprocessedFaces.Add(convexFaceInternal2);
                }
            }
            foreach (int item in list)
            {
                VertexVisited[item] = false;
            }
        }
Exemple #2
0
        /// <summary>
        /// Check whether the vertex v is beyond the given face. If so, add it to beyondVertices.
        /// </summary>
        /// <param name="face">The face.</param>
        /// <param name="beyondVertices">The beyond vertices.</param>
        /// <param name="v">The v.</param>
        private void IsBeyond(ConvexFaceInternal face, IndexBuffer beyondVertices, int v)
        {
            var distance = mathHelper.GetVertexDistance(v, face);

            if (distance >= PlaneDistanceTolerance)
            {
                if (distance > MaxDistance)
                {
                    // If it's within the tolerance distance, use the lex. larger point
                    if (distance - MaxDistance < PlaneDistanceTolerance)
                    { // todo: why is this LexCompare necessary. Would seem to favor x over y over z (etc.)?
                        if (LexCompare(v, FurthestVertex) > 0)
                        {
                            MaxDistance    = distance;
                            FurthestVertex = v;
                        }
                    }
                    else
                    {
                        MaxDistance    = distance;
                        FurthestVertex = v;
                    }
                }
                beyondVertices.Add(v);
            }
        }
Exemple #3
0
        /// <summary>
        /// Check whether the vertex v is beyond the given face. If so, add it to beyondVertices.
        /// </summary>
        /// <param name="face"></param>
        /// <param name="beyondVertices"></param>
        /// <param name="v"></param>
        void IsBeyond(ConvexFaceInternal face, IndexBuffer beyondVertices, int v)
        {
            double distance = MathHelper.GetVertexDistance(v, face);

            if (distance >= PlaneDistanceTolerance)
            {
                if (distance > MaxDistance)
                {
                    // If it's within the tolerance distance, use the lex. larger point
                    if (distance - MaxDistance < PlaneDistanceTolerance)
                    {
                        if (LexCompare(v, FurthestVertex) > 0)
                        {
                            MaxDistance    = distance;
                            FurthestVertex = v;
                        }
                    }
                    else
                    {
                        MaxDistance    = distance;
                        FurthestVertex = v;
                    }
                }
                beyondVertices.Add(v);
            }
        }
Exemple #4
0
        private void IsBeyond(ConvexFaceInternal face, IndexBuffer beyondVertices, int v)
        {
            double vertexDistance = mathHelper.GetVertexDistance(v, face);

            if (vertexDistance >= PlaneDistanceTolerance)
            {
                if (vertexDistance > MaxDistance)
                {
                    if (vertexDistance - MaxDistance < PlaneDistanceTolerance)
                    {
                        if (LexCompare(v, FurthestVertex) > 0)
                        {
                            MaxDistance    = vertexDistance;
                            FurthestVertex = v;
                        }
                    }
                    else
                    {
                        MaxDistance    = vertexDistance;
                        FurthestVertex = v;
                    }
                }
                beyondVertices.Add(v);
            }
        }
Exemple #5
0
 /// <summary>
 /// Check if the vertex was already added and if not, add it.
 /// </summary>
 /// <param name="i"></param>
 void AddConvexVertex(int i)
 {
     if (!VertexAdded[i])
     {
         ConvexHull.Add(i);
         VertexAdded[i] = true;
     }
 }
Exemple #6
0
 public SoftSubMesh(Mesh mesh, int[] indexes)
 {
     if (indexes != null && indexes.Length > 0)
     {
         m_IndexBuffer          = new IndexBuffer();
         m_IndexBuffer.Capacity = indexes.Length;
         for (int i = 0; i < indexes.Length; ++i)
         {
             m_IndexBuffer.Add(indexes[i]);
         }
     }
 }
Exemple #7
0
        public SpherePath(float height)
        {
            this.height = height;

            Center     = new Vector3Df(0);
            FrontColor = Color.SolidCyan;
            BackColor  = Color.SolidBlue;

            // we allocated once 64000 indices, initialize the sequence and never touch them in future... we will only use SetCount() method to set actual number of used indices
            indBoth.Reallocate(64000);
            for (int i = 0; i < indBoth.AllocatedCount - 1; i++)
            {
                indBoth.Add(i);
            }
        }
		public int TotalLightnings { get { return indexBuffer.Count / (2 * 10); } } // number of points for each line is 2, number of lines for each lightning is 10

		public LightningShot(SceneManager sceneManager, TriangleSelector worldTriangles, float worldInfinity = 5000, float shotSpeed = 0.1f, float shotRadius = 100)
		{
			this.sceneManager = sceneManager;
			this.worldTriangles = worldTriangles;
			this.worldInfinity = worldInfinity;
			this.shotSpeed = shotSpeed;
			this.shotRadius = shotRadius;

			indexBuffer = IndexBuffer.Create(IndexType._16Bit);
			indexBuffer.Reallocate(64000);
			for (int i = 0; i < indexBuffer.AllocatedCount - 1; i++)
				indexBuffer.Add(i);

			vertexBuffer = VertexBuffer.Create();
		}
        }                                                                                   // number of points for each line is 2, number of lines for each lightning is 10

        public LightningShot(SceneManager sceneManager, TriangleSelector worldTriangles, float worldInfinity = 5000, float shotSpeed = 0.1f, float shotRadius = 100)
        {
            this.sceneManager   = sceneManager;
            this.worldTriangles = worldTriangles;
            this.worldInfinity  = worldInfinity;
            this.shotSpeed      = shotSpeed;
            this.shotRadius     = shotRadius;

            indexBuffer = IndexBuffer.Create(IndexType._16Bit);
            indexBuffer.Reallocate(64000);
            for (int i = 0; i < indexBuffer.AllocatedCount - 1; i++)
            {
                indexBuffer.Add(i);
            }

            vertexBuffer = VertexBuffer.Create();
        }
Exemple #10
0
        private void IsBeyond(ConvexFaceInternal face, IndexBuffer beyondVertices, int v)
        {
            double vertexDistance = this.MathHelper.GetVertexDistance(v, face);

            if (vertexDistance >= this.PlaneDistanceTolerance)
            {
                if (vertexDistance > this.MaxDistance)
                {
                    if ((vertexDistance - this.MaxDistance) >= this.PlaneDistanceTolerance)
                    {
                        this.MaxDistance    = vertexDistance;
                        this.FurthestVertex = v;
                    }
                    else if (this.LexCompare(v, this.FurthestVertex) > 0)
                    {
                        this.MaxDistance    = vertexDistance;
                        this.FurthestVertex = v;
                    }
                }
                beyondVertices.Add(v);
            }
        }
Exemple #11
0
 /// <summary>
 /// Check whether the vertex v is beyond the given face. If so, add it to beyondVertices.
 /// </summary>
 /// <param name="face"></param>
 /// <param name="beyondVertices"></param>
 /// <param name="v"></param>
 void IsBeyond(ConvexFaceInternal face, IndexBuffer beyondVertices, int v)
 {
     double distance = MathHelper.GetVertexDistance(v, face);
     if (distance >= PlaneDistanceTolerance)
     {
         if (distance > MaxDistance)
         {
             // If it's within the tolerance distance, use the lex. larger point
             if (distance - MaxDistance < PlaneDistanceTolerance)
             {
                 if (LexCompare(v, FurthestVertex) > 0)
                 {
                     MaxDistance = distance;
                     FurthestVertex = v;
                 }
             }
             else
             {
                 MaxDistance = distance;
                 FurthestVertex = v;
             }
         }
         beyondVertices.Add(v);
     }
 }
Exemple #12
0
        public unsafe bool BuildClusterFromMeshSource(CRenderContext rc, RName meshSourceName)
        {
            Graphics.Mesh.CGfxMeshDataProvider meshSource = new Graphics.Mesh.CGfxMeshDataProvider();
            var meshPrimitive = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(rc, meshSourceName, true);

            meshSource.InitFromMesh(rc, meshPrimitive);

            uint a, b, c;

            a = 0;
            b = 0;
            c = 0;
            List <Cluster> clusterArray = new List <Cluster>();
            int            vertNum      = meshSource.VertexNumber;

            Vector3 *pPos    = (Vector3 *)meshSource.GetVertexPtr(EVertexSteamType.VST_Position, 0).ToPointer();
            Vector3 *pNor    = (Vector3 *)meshSource.GetVertexPtr(EVertexSteamType.VST_Normal, 0).ToPointer();
            Vector4 *pTan    = (Vector4 *)meshSource.GetVertexPtr(EVertexSteamType.VST_Tangent, 0).ToPointer();
            Vector2 *pDiffUV = (Vector2 *)meshSource.GetVertexPtr(EVertexSteamType.VST_UV, 0).ToPointer();

            GpuSceneVertex vert = new GpuSceneVertex();

            for (int i = 0; i < vertNum; i++)
            {
                vert.Reset();
                if (pPos != null)
                {
                    vert.Position = pPos[i];
                }
                if (pNor != null)
                {
                    vert.Normal = pNor[i];
                }
                if (pTan != null)
                {
                    vert.Tangent = pTan[i];
                }
                if (pDiffUV != null)
                {
                    vert.DiffuseU = pDiffUV[i].X;
                    vert.DiffuseV = pDiffUV[i].Y;
                }

                MeshVertices.Add(vert);
            }

            for (int i = 0; i < meshSource.TriangleNumber; i++)
            {
                meshSource.GetTriangle(i, ref a, ref b, ref c);
                IndexBuffer.Add(a);
                IndexBuffer.Add(b);
                IndexBuffer.Add(c);
            }

            Cluster  curCluster = null;
            Vector3 *pPosPtr    = (Vector3 *)meshSource.GetVertexPtr(EVertexSteamType.VST_Position, 0).ToPointer();

            for (uint i = 0; i < meshSource.AtomNumber; i++)
            {
                CDrawPrimitiveDesc desc = meshSource[i, 0];

                if (desc.PrimitiveType != EPrimitiveType.EPT_TriangleList)
                {
                    return(false);
                }

                uint startFace = desc.StartIndex / 3;

                for (uint j = 0; j < desc.NumPrimitives; j++)
                {
                    if (curCluster == null || curCluster.Data.FaceCount >= 64)
                    {
                        curCluster = new Cluster();
                        curCluster.Data.InstanceId     = i;
                        curCluster.Data.StartFaceIndex = startFace;
                        curCluster.Data.FaceCount      = 0;

                        clusterArray.Add(curCluster);
                    }
                    startFace++;
                    curCluster.Data.FaceCount++;
                }
            }

            ClusterDatas.Clear();
            for (int i = 0; i < clusterArray.Count; i++)
            {
                clusterArray[i].Proccess(pPosPtr, IndexBuffer);

                ClusterDatas.Add(clusterArray[i].Data);
            }
            return(true);
        }
Exemple #13
0
        public bool LoadClusteredMesh(RName name)
        {
            Name = name;

            Cleanup();

            var xnd = IO.XndHolder.SyncLoadXND(name.Address);

            IO.XndNode node = xnd.Node;

            var attr = node.FindAttrib("Vertices");

            if (attr == null)
            {
                return(false);
            }
            attr.BeginRead();
            int count = 0;

            attr.Read(out count);
            for (int i = 0; i < count; i++)
            {
                GpuSceneVertex vert;
                attr.Read(out vert);
                MeshVertices.Add(vert);
            }
            attr.EndRead();

            attr = node.FindAttrib("ClusterDatas");
            if (attr == null)
            {
                return(false);
            }
            attr.BeginRead();
            attr.Read(out count);
            for (int i = 0; i < count; i++)
            {
                GpuCluster cluster;
                attr.Read(out cluster);
                ClusterDatas.Add(cluster);
            }
            attr.EndRead();

            attr = node.FindAttrib("IndexBuffer");
            attr.BeginRead();
            attr.Read(out count);
            for (int i = 0; i < count; i++)
            {
                uint index;
                attr.Read(out index);
                IndexBuffer.Add(index);
            }
            attr.EndRead();

            unsafe
            {
                ResourceState.ResourceSize = (uint)(MeshVertices.Count * sizeof(GpuSceneVertex) + ClusterDatas.Count * sizeof(GpuCluster) + IndexBuffer.Count * sizeof(uint));
            }

            return(true);
        }
Exemple #14
0
        public void Parse(DataReader reader)
        {
            Name = reader.ReadString(reader.ReadInt32());
            if (reader.BaseStream.Position % 4 != 0)
            {
                reader.BaseStream.Position += 4 - (reader.BaseStream.Position % 4);
            }

            int subMeshCount = reader.ReadInt32();

            for (int i = 0; i < subMeshCount; i++)
            {
                UnitySubMesh sm = new UnitySubMesh();
                sm.Parse(reader);
                SubMesh.Add(sm);
            }

            int blendCount = reader.ReadInt32();

            for (int i = 0; i < blendCount; i++)
            {
                var sm = new UnityBlendShapeVertex();
                sm.Parse(reader);
                BlendShapeVertices.Add(sm);
            }

            int blendShapeCount = reader.ReadInt32();

            for (int i = 0; i < blendShapeCount; i++)
            {
                var sm = new UnityBlendShape();
                sm.Parse(reader);
                BlendShapes.Add(sm);
            }
            int blendShapeChannelCount = reader.ReadInt32();

            for (int i = 0; i < blendShapeChannelCount; i++)
            {
                var sm = new UnityBlendShapeChannel();
                sm.Parse(reader);
                BlendShapeChannels.Add(sm);
            }
            int fullWeightCount = reader.ReadInt32();

            for (int i = 0; i < fullWeightCount; i++)
            {
                var sm = reader.ReadSingle();
                FullWeights.Add(sm);
            }

            int bindPoseCount = reader.ReadInt32();

            for (int i = 0; i < bindPoseCount; i++)
            {
                var sm = new Matrix4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(),
                                     reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(),
                                     reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(),
                                     reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                BindPoses.Add(sm);
            }

            int boneNameHashCount = reader.ReadInt32();

            for (int i = 0; i < boneNameHashCount; i++)
            {
                BoneNameHashes.Add(reader.ReadInt32());
            }

            RootBoneNameHash = reader.ReadInt32();
            MeshCompression  = reader.ReadByte();
            IsReadable       = reader.ReadByte() == 1;
            KeepVertices     = reader.ReadByte() == 1;
            KeepIndices      = reader.ReadByte() == 1;

            int IndexBufferCount = reader.ReadInt32();

            for (int i = 0; i < IndexBufferCount / 2; i++)
            {
                IndexBuffer.Add(reader.ReadUInt16());
            }

            int BoneICount = reader.ReadInt32();

            for (int i = 0; i < BoneICount; i++)
            {
                var bi = new UnityBoneInfluence();
                bi.Parse(reader);
                BoneInfluences.Add(bi);
            }

            VertexData.Parse(reader);

            reader.PrintPosition();

            CompVertices.Parse(reader);

            reader.PrintPosition();
        }
Exemple #15
0
 private void TagAffectedFaces(ConvexFaceInternal currentFace)
 {
     AffectedFaceBuffer.Clear();
     AffectedFaceBuffer.Add(currentFace.Index);
     TraverseAffectedFaces(currentFace.Index);
 }