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);
        }
        /////////////////////////////////////////

        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 )");
                }
            }

            int vert = SegmentsVertical;

            if (vert % 2 == 0)
            {
                vert++;
            }
            var radius = Radius.Value;
            var height = Height.Value;

            if (InsideOut)
            {
                radius = -radius;
                height = -height;
            }
            SimpleMeshGenerator.GenerateCapsule(Axis, (float)radius, (float)height, SegmentsHorizontal, vert, out Vector3F[] positions, out Vector3F[] normals, out Vector4F[] tangents, out Vector2F[] texCoords, out indices, out var faces);
Esempio n. 3
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++;
                    }
                }
            }
        }
Esempio n. 4
0
        //!!!!!by tesselation modifier?

        ////SegmentsHorizontal
        //Reference<int> segmentsHorizontal = 32;
        //[Serialize]
        //public virtual Reference<int> SegmentsHorizontal
        //{
        //	get
        //	{
        //		if( !string.IsNullOrEmpty( segmentsHorizontal.GetByReference ) )
        //			SegmentsHorizontal = segmentsHorizontal.GetValue( this );
        //		return segmentsHorizontal;
        //	}
        //	set
        //	{
        //		if( segmentsHorizontal == value ) return;
        //		segmentsHorizontal = value;
        //		SegmentsHorizontalChanged?.Invoke( this );
        //	}
        //}
        //public event Action<Component_MeshData_Parallelepiped> SegmentsHorizontalChanged;


        ////SegmentsVertical
        //Reference<int> segmentsVertical = 32;
        //[Serialize]
        //public virtual Reference<int> SegmentsVertical
        //{
        //	get
        //	{
        //		if( !string.IsNullOrEmpty( segmentsVertical.GetByReference ) )
        //			SegmentsVertical = segmentsVertical.GetValue( this );
        //		return segmentsVertical;
        //	}
        //	set
        //	{
        //		if( segmentsVertical == value ) return;
        //		segmentsVertical = value;
        //		SegmentsVerticalChanged?.Invoke( this );
        //	}
        //}
        //public event Action<Component_MeshData_Parallelepiped> SegmentsVerticalChanged;


        //!!!!полусферной
        //!!!!закрытость сферы как Shape volume


        /////////////////////////////////////////

        //[StructLayout( LayoutKind.Sequential )]
        //public struct Vertex
        //{
        //	public Vec3F position;
        //	public Vec3F normal;
        //	public Vec2F texCoord;
        //}

        /////////////////////////////////////////

        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 )");
                }
            }

            SimpleMeshGenerator.GenerateBox(Dimensions.Value.ToVector3F(), InsideOut, out Vector3F[] positions, out Vector3F[] normals, out Vector4F[] tangents, out Vector2F[] texCoords, out indices, out var faces);
        /////////////////////////////////////////

        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 )");
                }
            }

            SimpleMeshGenerator.GenerateTorus(Axis, Radius, Segments, Circumference, TubeRadius, TubeSegments, TubeCircumference, /*Smooth, */ InsideOut, out Vector3F[] positions, out Vector3F[] normals, out Vector4F[] tangents, out Vector2F[] texCoords, out indices, out var faces);
Esempio n. 6
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 )");
                }
            }

            SimpleMeshGenerator.GenerateStairs(Axis, Width, Height, Depth, Steps, Curvature, Radius, Sides, InsideOut, out Vector3F[] positions, out Vector3F[] normals, out Vector4F[] tangents, out Vector2F[] texCoords, out indices, out var faces);
Esempio n. 7
0
        ////InsideOut
        //ReferenceField<bool> _insideOut = false;
        //[DefaultValue( false )]
        //[Serialize]
        //public Reference<bool> InsideOut
        //{
        //	get
        //	{
        //		if( _insideOut.BeginGet() )
        //			InsideOut = _insideOut.Get( this );
        //		return _insideOut.value;
        //	}
        //	set
        //	{
        //		if( _insideOut.BeginSet( ref value ) )
        //		{
        //			try
        //			{
        //				InsideOutChanged?.Invoke( this );
        //				ShouldRecompileMesh();
        //			}
        //			finally { _insideOut.EndSet(); }
        //		}
        //	}
        //}
        //public event Action<Component_MeshGeometry_Plane> InsideOutChanged;

        //!!!!!by tesselation modifier?

        ////SegmentsHorizontal
        //Reference<int> segmentsHorizontal = 32;
        //[Serialize]
        //public virtual Reference<int> SegmentsHorizontal
        //{
        //	get
        //	{
        //		if( !string.IsNullOrEmpty( segmentsHorizontal.GetByReference ) )
        //			SegmentsHorizontal = segmentsHorizontal.GetValue( this );
        //		return segmentsHorizontal;
        //	}
        //	set
        //	{
        //		if( segmentsHorizontal == value ) return;
        //		segmentsHorizontal = value;
        //		SegmentsHorizontalChanged?.Invoke( this );
        //	}
        //}
        //public event Action<Component_MeshData_Parallelepiped> SegmentsHorizontalChanged;


        ////SegmentsVertical
        //Reference<int> segmentsVertical = 32;
        //[Serialize]
        //public virtual Reference<int> SegmentsVertical
        //{
        //	get
        //	{
        //		if( !string.IsNullOrEmpty( segmentsVertical.GetByReference ) )
        //			SegmentsVertical = segmentsVertical.GetValue( this );
        //		return segmentsVertical;
        //	}
        //	set
        //	{
        //		if( segmentsVertical == value ) return;
        //		segmentsVertical = value;
        //		SegmentsVerticalChanged?.Invoke( this );
        //	}
        //}
        //public event Action<Component_MeshData_Parallelepiped> SegmentsVerticalChanged;

        /////////////////////////////////////////

        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 )");
                }
            }

            var dimensions = Dimensions.Value;

            //if( InsideOut )
            //	dimensions = -dimensions;

            SimpleMeshGenerator.GenerateSegmentedPlane(Axis, dimensions.ToVector2F(), Segments.Value, UVTilesPerUnit.Value.ToVector2F(), UVTilesInTotal.Value.ToVector2F(), out Vector3F[] positions, out Vector3F[] normals, out Vector4F[] tangents, out Vector2F[] texCoords, out indices, out var faces);
Esempio n. 8
0
        public override void GetProceduralGeneratedData(ref VertexElement[] vertexStructure, ref byte[] vertices, ref int[] indices, ref Component_Material material, ref Component_Mesh.StructureClass structure)
        {
            var meshInSpace = Parent?.Parent as Component_MeshInSpace;
            var points      = GetPointPositions();

            if (meshInSpace != null && points.Length >= 3)
            {
                vertexStructure = StandardVertex.MakeStructure(StandardVertex.Components.StaticOneTexCoord, true, out int vertexSize);
                unsafe
                {
                    if (vertexSize != sizeof(StandardVertex.StaticOneTexCoord))
                    {
                        Log.Fatal("vertexSize != sizeof( StandardVertexF )");
                    }
                }

                SimpleMeshGenerator.GeneratePolygonBasedPolyhedron(points, Clockwise, Height, InsideOut, out Vector3[] positions, out Vector3[] normals, out Vector4[] tangents, out Vector2[] texCoords, out indices, out var faces);
Esempio n. 9
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;
            }
        }