예제 #1
0
        protected override void OnApplyToMeshData(Component_Mesh.CompiledData compiledData)
        {
            base.OnApplyToMeshData(compiledData);

            int aa = 0;

            foreach (var oper in compiledData.MeshData.RenderOperations)
            {
                aa = aa + 1;
                if (DataN == 0 || DataN == aa)
                {
                    oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out VertexElement positionElement);
                    var vertexBuffer = oper.VertexBuffers[positionElement.Source];
                    var positions    = vertexBuffer.ExtractChannel <Vector3F>(positionElement.Offset);

                    var newPositions = new Vector3F[positions.Length];
                    for (int n = 0; n < positions.Length; n = n + 1)
                    {
                        ProcessVertex(aa, ref positions[n], out newPositions[n]);
                    }

                    vertexBuffer.MakeCopyOfData();
                    vertexBuffer.WriteChannel(positionElement.Offset, newPositions);
                }
            }
        }
예제 #2
0
        protected override void OnApplyToMeshData(Component_Mesh.CompiledData compiledData)
        {
            base.OnApplyToMeshData(compiledData);

            float multiplier    = (float)Multiplier;
            float multiplier1   = (float)Multiplier1;
            float invMultiplier = 0;             //-multiplier;
            int   aa            = 0;

            foreach (var oper in compiledData.MeshData.RenderOperations)
            {
                //aa = aa + 1;
                //ScreenMessages.Add(aa.ToString()+")"+oper.VertexCount.ToString());
                //if(aa == 2) {
                oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out VertexElement positionElement);
                var vertexBuffer = oper.VertexBuffers[positionElement.Source];
                var positions    = vertexBuffer.ExtractChannel <Vector3F>(positionElement.Offset);

                var newPositions = new Vector3F[positions.Length];
                for (int n = 0; n < positions.Length; n = n + 1)
                {
                    ProcessVertex(multiplier, multiplier1, invMultiplier, n, ref positions[n], out newPositions[n]);
                }

                vertexBuffer.MakeCopyOfData();
                vertexBuffer.WriteChannel(positionElement.Offset, newPositions);
                //}
            }
        }
        internal void CompileDataOfThisObject(Component_Mesh.CompiledData compiledData)          // Component_Mesh mesh, Component_Mesh.CompiledData result )
        {
            VertexElement[] vertexStructureV = VertexStructure;
            UnwrappedUVEnum unwrappedUVV     = UnwrappedUV;

            byte[]             verticesV = Vertices;
            int[]              indicesV  = Indices;
            Component_Material materialV = Material;

            Component_Mesh.StructureClass structure = null;

            OnGetDataOfThisObject(ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);
            GetDataOfThisObjectEvent?.Invoke(this, ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);

            //add to result
            if (vertexStructureV != null && vertexStructureV.Length != 0 && verticesV != null && verticesV.Length != 0 && (indicesV == null || indicesV.Length != 0))
            {
                vertexStructureV.GetInfo(out var vertexSize, out var holes);
                //if( !holes )
                {
                    int vertexCount = verticesV.Length / vertexSize;

                    var op = new Component_RenderingPipeline.RenderSceneData.MeshDataRenderOperation(this);

                    op.VertexStructure = vertexStructureV;
                    op.VertexStructureContainsColor = op.VertexStructure.Any(e => e.Semantic == VertexElementSemantic.Color0);
                    op.UnwrappedUV = unwrappedUVV;

                    var vertexDeclaration = op.VertexStructure.CreateVertexDeclaration(0);
                    op.VertexBuffers     = new GpuVertexBuffer[] { GpuBufferManager.CreateVertexBuffer(verticesV, vertexDeclaration) };
                    op.VertexStartOffset = 0;
                    op.VertexCount       = vertexCount;

                    if (indicesV != null)
                    {
                        op.IndexBuffer      = GpuBufferManager.CreateIndexBuffer(indicesV);
                        op.IndexStartOffset = 0;
                        op.IndexCount       = indicesV.Length;
                    }

                    //!!!!так?
                    op.Material = materialV;

                    compiledData.MeshData.RenderOperations.Add(op);

                    //!!!!может мержить когда несколько. индексы MeshGeometry в RawVertices
                    if (compiledData.MeshData.Structure == null)
                    {
                        compiledData.MeshData.Structure = structure;
                    }
                }
                //else
                //{
                //	//!!!!!error
                //}
            }
        }
        protected override void OnApplyToMeshData(Component_Mesh.CompiledData compiledData)
        {
            base.OnApplyToMeshData(compiledData);

            var bounds = Bounds.Cleared;
            {
                foreach (var oper in compiledData.MeshData.RenderOperations)
                {
                    if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out var positionElement) && positionElement.Type == VertexElementType.Float3)
                    {
                        var vertexBuffer = oper.VertexBuffers[positionElement.Source];
                        var positions    = vertexBuffer.ExtractChannel <Vector3F>(positionElement.Offset);

                        foreach (var p in positions)
                        {
                            bounds.Add(p);
                        }
                    }
                }
                //calculated bounding box is not prepared at this time. must calculate by vertices position
                //var bounds = compiledData.SpaceBounds.CalculatedBoundingBox;

                //bounds.Expand( ExtendBounds );
            }

            var tiles = Tiles.Value;

            foreach (var oper in compiledData.MeshData.RenderOperations)
            {
                if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out var positionElement) && positionElement.Type == VertexElementType.Float3)
                {
                    if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Normal, out var normalElement) && normalElement.Type == VertexElementType.Float3)
                    {
                        if (oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.TextureCoordinate0, out var texCoordElement) && texCoordElement.Type == VertexElementType.Float2)
                        {
                            var positions = oper.VertexBuffers[positionElement.Source].ExtractChannel <Vector3F>(positionElement.Offset);
                            var normals   = oper.VertexBuffers[normalElement.Source].ExtractChannel <Vector3F>(normalElement.Offset);

                            var newTexCoords = new Vector2F[positions.Length];
                            for (int n = 0; n < newTexCoords.Length; n++)
                            {
                                ProcessVertex(ref tiles, ref bounds, ref positions[n], ref normals[n], out newTexCoords[n]);
                            }

                            var vertexBuffer = oper.VertexBuffers[texCoordElement.Source];
                            vertexBuffer.MakeCopyOfData();
                            vertexBuffer.WriteChannel(texCoordElement.Offset, newTexCoords);
                        }
                    }
                }
            }
        }
        protected override void OnApplyToMeshData(Component_Mesh.CompiledData compiledData)
        {
            base.OnApplyToMeshData(compiledData);

            float multiplier    = (float)Multiplier;
            float invMultiplier = multiplier != 0 ? (1.0f / multiplier) : 0;

            foreach (var oper in compiledData.MeshData.RenderOperations)
            {
                oper.VertexStructure.GetElementBySemantic(VertexElementSemantic.Position, out VertexElement positionElement);
                var vertexBuffer = oper.VertexBuffers[positionElement.Source];
                var positions    = vertexBuffer.ExtractChannel <Vector3F>(positionElement.Offset);

                var newPositions = new Vector3F[positions.Length];
                for (int n = 0; n < positions.Length; n++)
                {
                    ProcessVertex(multiplier, invMultiplier, ref positions[n], out newPositions[n]);
                }

                vertexBuffer.MakeCopyOfData();
                vertexBuffer.WriteChannel(positionElement.Offset, newPositions);
            }
        }
예제 #6
0
 public void AddMesh(Component_Mesh.CompiledData meshData, Matrix4 transform, bool wireframe, bool culling)
 {
     AddMesh(meshData, ref transform, wireframe, culling);
 }
예제 #7
0
 //bool transformAlreadyAppliedRelativeCameraOffset
 public abstract void AddMesh(Component_Mesh.CompiledData meshData, ref Matrix4 transform, bool wireframe, bool culling);
        /////////////////////////////////////////

        void DrawUV(Viewport viewport)
        {
            var meshData = GetSelectedLOD();

            if (Mesh.EditorDisplayUV >= 0 && Mesh.EditorDisplayUV < 4)
            {
                StandardVertex.Components component = StandardVertex.Components.TexCoord0;
                if (Mesh.EditorDisplayUV == 0)
                {
                    component = StandardVertex.Components.TexCoord0;
                }
                else if (Mesh.EditorDisplayUV == 1)
                {
                    component = StandardVertex.Components.TexCoord1;
                }
                else if (Mesh.EditorDisplayUV == 2)
                {
                    component = StandardVertex.Components.TexCoord2;
                }
                else if (Mesh.EditorDisplayUV == 3)
                {
                    component = StandardVertex.Components.TexCoord3;
                }

                if ((meshData.ExtractedVerticesComponents & component) != 0)
                {
                    var uvArray = (Vector2F[])StandardVertex.ExtractOneComponentArray(meshData.ExtractedVertices, component);

                    //bool valid = Array.Exists( uvArray, item => item != Vec2F.Zero );
                    //if( valid )
                    //{

                    //check old cache
                    if (cachedDisplayUV_Triangles != null)
                    {
                        if (cachedDisplayUV != Mesh.EditorDisplayUV || cachedDisplayUV_MeshData != meshData)
                        {
                            cachedDisplayUV_Triangles = null;
                            cachedDisplayUV_Lines     = null;
                        }
                    }

                    Vector2F screenMultiplier = new Vector2F(viewport.CanvasRenderer.AspectRatioInv * .8f, 0.8f);
                    Vector2F screenOffset     = new Vector2F(1.0f - screenMultiplier.X - 0.01f, 1.0f - screenMultiplier.Y - 0.01f);

                    Vector2F Convert(Vector2F v)
                    {
                        return(v * screenMultiplier + screenOffset);
                    };

                    //update
                    if (cachedDisplayUV_Triangles == null)
                    {
                        cachedDisplayUV          = Mesh.EditorDisplayUV;
                        cachedDisplayUV_MeshData = meshData;

                        var indices = meshData.ExtractedIndices;

                        //!!!!показывать те, которые за границами 0-1.


                        var uvArrayConverted = new Vector2F[uvArray.Length];
                        for (int n = 0; n < uvArrayConverted.Length; n++)
                        {
                            uvArrayConverted[n] = Convert(uvArray[n]);
                        }

                        var trianglesColor = new ColorValue(0, 1, 0, 0.5);
                        var linesColor     = new ColorValue(1, 1, 1);

                        //triangles
                        {
                            var triangles = new List <CanvasRenderer.TriangleVertex>(indices.Length / 3);

                            for (int triangle = 0; triangle < indices.Length / 3; triangle++)
                            {
                                int index0 = indices[triangle * 3 + 0];
                                int index1 = indices[triangle * 3 + 1];
                                int index2 = indices[triangle * 3 + 2];

                                Vector2F v0 = uvArrayConverted[index0];
                                Vector2F v1 = uvArrayConverted[index1];
                                Vector2F v2 = uvArrayConverted[index2];

                                triangles.Add(new CanvasRenderer.TriangleVertex(v0, trianglesColor));
                                triangles.Add(new CanvasRenderer.TriangleVertex(v1, trianglesColor));
                                triangles.Add(new CanvasRenderer.TriangleVertex(v2, trianglesColor));
                            }

                            cachedDisplayUV_Triangles = triangles.ToArray();
                        }

                        //lines
                        {
                            int[] lineIndices = MathAlgorithms.TriangleListToLineList(indices);

                            var lines = new List <CanvasRenderer.LineItem>(lineIndices.Length / 2);
                            for (int nLine = 0; nLine < lineIndices.Length / 2; nLine++)
                            {
                                var v0 = uvArrayConverted[lineIndices[nLine * 2 + 0]];
                                var v1 = uvArrayConverted[lineIndices[nLine * 2 + 1]];
                                lines.Add(new CanvasRenderer.LineItem(v0, v1, linesColor));
                            }

                            var vertices = new CanvasRenderer.TriangleVertex[lines.Count * 2];
                            for (int n = 0; n < lines.Count; n++)
                            {
                                var line = lines[n];
                                vertices[n * 2 + 0] = new CanvasRenderer.TriangleVertex(line.start, line.color, Vector2F.Zero);
                                vertices[n * 2 + 1] = new CanvasRenderer.TriangleVertex(line.end, line.color, Vector2F.Zero);
                            }

                            cachedDisplayUV_Lines = vertices;
                        }
                    }

                    //draw
                    if (cachedDisplayUV_Triangles != null)
                    {
                        viewport.CanvasRenderer.AddQuad(new RectangleF(Convert(Vector2F.Zero), Convert(Vector2F.One)), new ColorValue(0, 0, 0, .5));
                        viewport.CanvasRenderer.AddTriangles(cachedDisplayUV_Triangles);
                        viewport.CanvasRenderer.AddLines(cachedDisplayUV_Lines);
                    }
                }
            }
        }
 public void ApplyToMeshData(Component_Mesh.CompiledData compiledData)
 {
     OnApplyToMeshData(compiledData);
     ApplyToMeshDataEvent?.Invoke(this, compiledData);
 }
예제 #10
0
 protected virtual void OnApplyToMeshData(Component_Mesh.CompiledData compiledData)
 {
 }
예제 #11
0
        internal void CompileDataOfThisObject(Component_Mesh.CompiledData compiledData)          // Component_Mesh mesh, Component_Mesh.CompiledData result )
        {
            VertexElement[] vertexStructureV = VertexStructure;
            UnwrappedUVEnum unwrappedUVV     = UnwrappedUV;

            byte[]             verticesV = Vertices;
            int[]              indicesV  = Indices;
            Component_Material materialV = Material;

            Component_Mesh.StructureClass structure = null;

            OnGetDataOfThisObject(ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);
            GetDataOfThisObjectEvent?.Invoke(this, ref vertexStructureV, ref verticesV, ref indicesV, ref materialV, ref structure);

            //add to result
            if (vertexStructureV != null && vertexStructureV.Length != 0 && verticesV != null && verticesV.Length != 0 && (indicesV == null || indicesV.Length != 0))
            {
                //!!!!еще чтобы был с позициями?

                vertexStructureV.GetInfo(out var vertexSize, out var holes);
                //if( !holes )
                {
                    int vertexCount = verticesV.Length / vertexSize;

                    var op = new Component_RenderingPipeline.RenderSceneData.MeshDataRenderOperation(this);

                    op.VertexStructure = vertexStructureV;

                    op.VertexStructureContainsColor = op.VertexStructure.Any(e => e.Semantic == VertexElementSemantic.Color0);
                    ////disable if all data equal zero. it is means no data.
                    //if( op.VertexStructureContainsColor )
                    //{
                    //	if( vertexStructureV.GetElementBySemantic( VertexElementSemantic.Color0, out var element ) )
                    //	{
                    //		var size = element.GetSizeInBytes();
                    //		int vertexOffset = element.Offset;
                    //		for( int nVertex = 0; nVertex < vertexCount; nVertex++ )
                    //		{
                    //			for( int n = 0; n < size; n++ )
                    //			{
                    //				if( verticesV[ vertexOffset + n ] != 0 )
                    //				{
                    //					//found non zero
                    //					goto exit;
                    //				}
                    //			}
                    //			vertexOffset += vertexSize;
                    //		}
                    //		op.VertexStructureContainsColor = false;
                    //		exit:;
                    //	}
                    //}

                    op.UnwrappedUV = unwrappedUVV;

                    var vertexDeclaration = op.VertexStructure.CreateVertexDeclaration(0);
                    op.VertexBuffers     = new GpuVertexBuffer[] { GpuBufferManager.CreateVertexBuffer(verticesV, vertexDeclaration) };
                    op.VertexStartOffset = 0;
                    op.VertexCount       = vertexCount;

                    if (indicesV != null)
                    {
                        op.IndexBuffer      = GpuBufferManager.CreateIndexBuffer(indicesV);
                        op.IndexStartOffset = 0;
                        op.IndexCount       = indicesV.Length;
                    }

                    //!!!!так?
                    op.Material = materialV;

                    compiledData.MeshData.RenderOperations.Add(op);

                    //!!!!может мержить когда несколько. индексы MeshGeometry в RawVertices
                    if (compiledData.MeshData.Structure == null)
                    {
                        compiledData.MeshData.Structure = structure;
                    }

                    //var op = new Component_Mesh.CompiledData.RenderOperation();
                    //op.creator = this;

                    //op.vertexStructure = vertexStructureV;
                    //List<GpuVertexBuffer> l = new List<GpuVertexBuffer>();

                    ////!!!!make copy of arrays?

                    //var vertexDeclaration = op.vertexStructure.CreateVertexDeclaration( 0 );

                    //l.Add( GpuBufferManager.CreateVertexBuffer( verticesV, vertexDeclaration, false ) );
                    //op.vertexBuffers = l;
                    //op.vertexStartOffset = 0;
                    //op.vertexCount = vertexCount;

                    //if( indicesV != null )
                    //{
                    //	op.indexBuffer = GpuBufferManager.CreateIndexBuffer( indicesV, false );
                    //	op.indexStartOffset = 0;
                    //	op.indexCount = indicesV.Length;
                    //}

                    ////!!!!так?
                    //op.material = materialV;

                    //var item = new Component_Mesh.CompiledData.RenderOperationItem();
                    //item.operation = op;
                    ////!!!!
                    ////item.transform = TransformOfData;//TransformRelativeToParent;
                    //compiledData.RenderOperations.Add( item );

                    ////op.transform = Transform;
                    ////compiledData.RenderOperations.Add( op );
                }
                //else
                //{
                //	//!!!!!error
                //}
            }
        }