コード例 #1
0
        /// <summary>
        /// Creates a mesh shape for serialising <paramref name="shapeComponent"/> and its associated mesh data.
        /// </summary>
        /// <param name="shapeComponent">The component to create a shape for.</param>
        /// <returns>A shape instance suitable for configuring to generate serialisation messages.</returns>
        protected override Shapes.Shape CreateSerialisationShape(ShapeComponent shapeComponent)
        {
            MeshDataComponent meshData = shapeComponent.GetComponent <MeshDataComponent>();

            if (meshData != null)
            {
                ObjectAttributes attr = new ObjectAttributes();
                EncodeAttributes(ref attr, shapeComponent.gameObject, shapeComponent);

                Shapes.MeshShape mesh = new Shapes.MeshShape(meshData.DrawType,
                                                             Maths.Vector3Ext.FromUnity(meshData.Vertices),
                                                             meshData.Indices,
                                                             shapeComponent.ObjectID,
                                                             shapeComponent.Category,
                                                             Maths.Vector3.Zero,
                                                             Maths.Quaternion.Identity,
                                                             Maths.Vector3.One);
                mesh.SetAttributes(attr);
                mesh.CalculateNormals = meshData.CalculateNormals;
                if (!meshData.CalculateNormals && meshData.Normals != null && meshData.Normals.Length > 0)
                {
                    mesh.Normals = Maths.Vector3Ext.FromUnity(meshData.Normals);
                }

                return(mesh);
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Creates a mesh shape for serialising <paramref name="shapeComponent"/> and its associated mesh data.
        /// </summary>
        /// <param name="shapeComponent">The component to create a shape for.</param>
        /// <returns>A shape instance suitable for configuring to generate serialisation messages.</returns>
        protected override Shapes.Shape CreateSerialisationShape(ShapeCache cache, int shapeIndex, CreateMessage shapeData)
        {
            MeshEntry  meshEntry = cache.GetShapeDataByIndex <MeshEntry>(shapeIndex);
            RenderMesh mesh      = meshEntry.Mesh;

            Debug.Log($"serialise mesh. Normals? {mesh.HasNormals}");

            Shapes.MeshShape meshShape = new Shapes.MeshShape(meshEntry.Mesh.DrawType,
                                                              Maths.Vector3Ext.FromUnity(mesh.Vertices),
                                                              mesh.Indices,
                                                              shapeData.ObjectID, shapeData.Category);

            if (mesh.HasNormals && !meshEntry.CalculateNormals)
            {
                // We have normals which were not locally calculated.
                meshShape.Normals = Tes.Maths.Vector3Ext.FromUnity(mesh.Normals);
            }

            meshShape.SetAttributes(shapeData.Attributes);
            return(meshShape);
        }