Exemplo n.º 1
0
        /// <summary>
        /// Creates a mesh set shape for serialising the mesh and its resource references.
        /// </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)
        {
            // Start by building the resource list.
            int partCount          = shapeComponent.transform.childCount;
            ObjectAttributes attrs = new ObjectAttributes();

            Shapes.MeshSet meshSet = new Shapes.MeshSet(shapeComponent.ObjectID, shapeComponent.Category);
            EncodeAttributes(ref attrs, shapeComponent.gameObject, shapeComponent);
            meshSet.SetAttributes(attrs);
            for (int i = 0; i < partCount; ++i)
            {
                // Write the mesh ID
                ShapeComponent partSrc = shapeComponent.transform.GetChild(i).GetComponent <ShapeComponent>();
                if (partSrc != null)
                {
                    MeshResourcePlaceholder part = new MeshResourcePlaceholder(partSrc.ObjectID);
                    // Encode attributes into target format.
                    EncodeAttributes(ref attrs, partSrc.gameObject, partSrc);
                    // And convert to matrix.
                    meshSet.AddPart(part, attrs.GetTransform());
                }
                else
                {
                    Log.Error("Failed to extract child {0} for mesh set {1}.", i, shapeComponent.name);
                    return(null);
                }
            }
            return(meshSet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a mesh set shape for serialising the mesh and its resource references.
        /// </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)
        {
            // Start by building the resource list.
            PartSet partSet = cache.GetShapeDataByIndex <PartSet>(shapeIndex);

            Shapes.MeshSet meshSet = new Shapes.MeshSet(shapeData.ObjectID, shapeData.Category);
            meshSet.SetAttributes(shapeData.Attributes);
            for (int i = 0; i < partSet.MeshIDs.Length; ++i)
            {
                MeshResourcePlaceholder part = new MeshResourcePlaceholder(partSet.MeshIDs[i]);
                meshSet.AddPart(part, Tes.Maths.Matrix4Ext.FromUnity(partSet.Transforms[i]));
            }
            return(meshSet);
        }