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

        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);
예제 #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++;
                    }
                }
            }
        }
예제 #3
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);
예제 #5
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);
예제 #6
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);
예제 #7
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);
예제 #8
0
 public bool Equals(ref StandardVertex v, float epsilon)
 {
     if (!Position.Equals(ref v.Position, epsilon))
     {
         return(false);
     }
     if (!Normal.Equals(ref v.Normal, epsilon))
     {
         return(false);
     }
     if (!Tangent.Equals(ref v.Tangent, epsilon))
     {
         return(false);
     }
     if (!Color.Equals(ref v.Color, epsilon))
     {
         return(false);
     }
     if (!TexCoord0.Equals(ref v.TexCoord0, epsilon))
     {
         return(false);
     }
     if (!TexCoord1.Equals(ref v.TexCoord1, epsilon))
     {
         return(false);
     }
     if (!TexCoord2.Equals(ref v.TexCoord2, epsilon))
     {
         return(false);
     }
     if (!TexCoord3.Equals(ref v.TexCoord3, epsilon))
     {
         return(false);
     }
     if (BlendIndices != v.BlendIndices)
     {
         return(false);
     }
     if (!BlendWeights.Equals(ref v.BlendWeights, epsilon))
     {
         return(false);
     }
     return(true);
 }
예제 #9
0
            //

            public Item(RectangleF uv)
            {
                UV         = uv;
                EngineTime = Time.Current;

                var vertexStructure = StandardVertex.MakeStructure(StandardVertex.Components.StaticOneTexCoord, true, out int vertexSize);

                var positions = new Vector3F[] { new Vector3F(-0.5f, -0.5f, 0), new Vector3F(0.5f, -0.5f, 0), new Vector3F(0.5f, 0.5f, 0), new Vector3F(-0.5f, 0.5f, 0) };
                var texCoords = new Vector2F[] { uv.LeftTop, uv.RightTop, uv.RightBottom, uv.LeftBottom };

                var 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    = new Vector3F(0, 0, 1);
                            pVertex->Tangent   = new Vector4F(1, 0, 0, -1);
                            pVertex->Color     = new ColorValue(1, 1, 1, 1);
                            pVertex->TexCoord0 = texCoords[n];

                            pVertex++;
                        }
                    }
                }

                var mesh     = ComponentUtility.CreateComponent <Component_Mesh>(null, true, false);
                var geometry = mesh.CreateComponent <Component_MeshGeometry>();

                geometry.VertexStructure = vertexStructure;
                geometry.Vertices        = vertices;
                geometry.Indices         = new int[] { 0, 1, 2, 2, 3, 0 };
                mesh.Enabled             = true;

                Mesh = mesh;
            }
        public void SetVertexDataWithRemovingHoles(StandardVertex[] vertices, StandardVertex.Components vertexComponents)
        {
            int vertexSize;
            var structure = StandardVertex.MakeStructure(vertexComponents, true, out vertexSize);

            int destNormalOffset       = 0;
            int destTangentOffset      = 0;
            int destColorOffset        = 0;
            int destTexCoord0Offset    = 0;
            int destTexCoord1Offset    = 0;
            int destTexCoord2Offset    = 0;
            int destTexCoord3Offset    = 0;
            int destBlendIndicesOffset = 0;
            int destBlendWeightsOffset = 0;

            {
                foreach (var c in structure)
                {
                    switch (c.Semantic)
                    {
                    case VertexElementSemantic.Normal: destNormalOffset = c.Offset; break;

                    case VertexElementSemantic.Tangent: destTangentOffset = c.Offset; break;

                    case VertexElementSemantic.Color0: destColorOffset = c.Offset; break;

                    case VertexElementSemantic.TextureCoordinate0: destTexCoord0Offset = c.Offset; break;

                    case VertexElementSemantic.TextureCoordinate1: destTexCoord1Offset = c.Offset; break;

                    case VertexElementSemantic.TextureCoordinate2: destTexCoord2Offset = c.Offset; break;

                    case VertexElementSemantic.TextureCoordinate3: destTexCoord3Offset = c.Offset; break;

                    case VertexElementSemantic.BlendIndices: destBlendIndicesOffset = c.Offset; break;

                    case VertexElementSemantic.BlendWeights: destBlendWeightsOffset = c.Offset; break;
                    }
                }
            }

            byte[] destArray = new byte[vertices.Length * vertexSize];
            unsafe
            {
                fixed(byte *pDestArray = destArray)
                {
                    byte *destVertex = pDestArray;

                    for (int n = 0; n < vertices.Length; n++)
                    {
                        StandardVertex vertex = vertices[n];

                        *(Vector3F *)(destVertex + 0) = vertex.Position;

                        if ((vertexComponents & StandardVertex.Components.Normal) != 0)
                        {
                            *(Vector3F *)(destVertex + destNormalOffset) = vertex.Normal;
                        }
                        if ((vertexComponents & StandardVertex.Components.Tangent) != 0)
                        {
                            *(Vector4F *)(destVertex + destTangentOffset) = vertex.Tangent;
                        }
                        if ((vertexComponents & StandardVertex.Components.Color) != 0)
                        {
                            *(ColorValue *)(destVertex + destColorOffset) = vertex.Color;
                        }
                        if ((vertexComponents & StandardVertex.Components.TexCoord0) != 0)
                        {
                            *(Vector2F *)(destVertex + destTexCoord0Offset) = vertex.TexCoord0;
                        }
                        if ((vertexComponents & StandardVertex.Components.TexCoord1) != 0)
                        {
                            *(Vector2F *)(destVertex + destTexCoord1Offset) = vertex.TexCoord1;
                        }
                        if ((vertexComponents & StandardVertex.Components.TexCoord2) != 0)
                        {
                            *(Vector2F *)(destVertex + destTexCoord2Offset) = vertex.TexCoord2;
                        }
                        if ((vertexComponents & StandardVertex.Components.TexCoord3) != 0)
                        {
                            *(Vector2F *)(destVertex + destTexCoord3Offset) = vertex.TexCoord3;
                        }
                        if ((vertexComponents & StandardVertex.Components.BlendIndices) != 0)
                        {
                            *(Vector4I *)(destVertex + destBlendIndicesOffset) = vertex.BlendIndices;
                        }
                        if ((vertexComponents & StandardVertex.Components.BlendWeights) != 0)
                        {
                            *(Vector4F *)(destVertex + destBlendWeightsOffset) = vertex.BlendWeights;
                        }
                        destVertex += vertexSize;
                    }
                }
            }

            VertexStructure = structure;
            Vertices        = destArray;
        }
예제 #11
0
 public bool Equals(StandardVertex v, float epsilon)
 {
     return(Equals(ref v, epsilon));
 }