CenterOfMassGeometry GetCenterOfMassGeometry(float radius)
        {
            for (int n = 0; n < centerOfMassGeometryCache.Count; n++)
            {
                var item2 = centerOfMassGeometryCache[n];
                if (Math.Abs(item2.radius - radius) < .01)
                {
                    return(item2);
                }
            }

            while (centerOfMassGeometryCache.Count > 15)
            {
                centerOfMassGeometryCache.RemoveAt(0);
            }

            var item = new CenterOfMassGeometry();

            item.radius = radius;
            var segments = 10;

            SimpleMeshGenerator.GenerateSphere(radius, segments, ((segments + 1) / 2) * 2, false, out item.positions, out item.indices);
            centerOfMassGeometryCache.Add(item);

            return(item);
        }
Exemplo n.º 2
0
        /////////////////////////////////////////

        public override void GetProceduralGeneratedData(ref VertexElement[] vertexStructure, ref byte[] vertices, ref int[] indices, ref Component_Material material, ref Component_Mesh.StructureClass structure)
        {
            //!!!!!можно было бы не обновлять если такие же параметры

            vertexStructure = StandardVertex.MakeStructure(StandardVertex.Components.StaticOneTexCoord, true, out int vertexSize);
            unsafe
            {
                if (vertexSize != sizeof(StandardVertex.StaticOneTexCoord))
                {
                    Log.Fatal("vertexSize != sizeof( StandardVertexF )");
                }
            }

            Vector3F[] positions;
            Vector3F[] normals;
            Vector4F[] tangents;
            Vector2F[] texCoords;
            SimpleMeshGenerator.Face[] faces;

            if (SphereType.Value == SphereTypeEnum.GeoSphere)
            {
                SimpleMeshGenerator.GenerateSphere(Radius, SegmentsHorizontal, SegmentsVertical, InsideOut, out positions, out normals, out tangents, out texCoords, out indices, out faces);
            }
            else
            {
                SimpleMeshGenerator.GenerateIcoSphere(Radius, Subdivisions.Value, InsideOut, out positions, out normals, out tangents, out texCoords, out indices, out faces);
            }

            if (faces != null)
            {
                structure = SimpleMeshGenerator.CreateMeshStructure(faces);
            }

            vertices = new byte[vertexSize * positions.Length];
            unsafe
            {
                fixed(byte *pVertices = vertices)
                {
                    StandardVertex.StaticOneTexCoord *pVertex = (StandardVertex.StaticOneTexCoord *)pVertices;

                    for (int n = 0; n < positions.Length; n++)
                    {
                        pVertex->Position  = positions[n];
                        pVertex->Normal    = normals[n];
                        pVertex->Tangent   = tangents[n];
                        pVertex->Color     = new ColorValue(1, 1, 1, 1);
                        pVertex->TexCoord0 = texCoords[n];

                        pVertex++;
                    }
                }
            }
        }
Exemplo n.º 3
0
        void UpdateConvexSweepHull()
        {
            var target = ConvexSweepTarget.Value;

            if (target != null)
            {
                var tr    = Transform.Value;
                var from  = tr.ToMatrix4();
                var to    = target.Transform.Value.ToMatrix4();
                var shape = Shape.Value;

                var update = hullVertices == null || !hullFrom.Equals(from, .000001) || !hullTo.Equals(to, .000001) || hullShape != shape;
                if (update)
                {
                    hullFrom  = from;
                    hullTo    = to;
                    hullShape = shape;

                    if (shape == ShapeEnum.Box)
                    {
                        var boxLocalVertices = new Bounds(tr.Scale * -.5, tr.Scale * .5).ToPoints();
                        UpdateSweepHullGeometry(boxLocalVertices);
                    }
                    else if (shape == ShapeEnum.Sphere)
                    {
                        var radius = Math.Max(tr.Scale.X, Math.Max(tr.Scale.Y, tr.Scale.Z)) * 0.5;
                        //!!!!12
                        SimpleMeshGenerator.GenerateSphere(radius, 12, 12, false, out Vector3[] sphereLocalVertices, out _);
                        UpdateSweepHullGeometry(sphereLocalVertices);
                    }
                }
            }
            else
            {
                hullVertices = null;
                hullIndices  = null;
                hullPlanes   = null;
            }
        }