예제 #1
0
        bool ParseNodeInstanceGeometry(Mat4 nodeTransform, XmlNode instanceGeometry)
        {
            string url = XmlUtils.GetAttribute(instanceGeometry, "url");

            bool nodeTransformIdentity = nodeTransform.Equals(Mat4.Identity, .0001f);
            Quat nodeRotation          = nodeTransform.ToMat3().ToQuat().GetNormalize();

            string geometryId = GetIdFromURL(url);

            if (string.IsNullOrEmpty(geometryId))
            {
                Error("Invalid \"url\" attribute specified for \"instance_geometry\". Url: \"{0}\".", url);
                return(false);
            }

            GeometryItem geometry;

            if (!generatedGeometries.TryGetValue(geometryId, out geometry))
            {
                Error("Geometry with id \"{0}\" is not exists.", geometryId);
                return(false);
            }

            foreach (GeometryItem.SubMesh geometrySubMesh in geometry.SubMeshes)
            {
                SubMeshVertex[] newVertices = new SubMeshVertex[geometrySubMesh.Vertices.Length];

                for (int n = 0; n < newVertices.Length; n++)
                {
                    SubMeshVertex vertex = geometrySubMesh.Vertices[n];

                    if (!nodeTransformIdentity)
                    {
                        vertex.position = nodeTransform * vertex.position;
                        vertex.normal   = (nodeRotation * vertex.normal).GetNormalize();
                    }

                    newVertices[n] = vertex;
                }

                MySceneSubMesh sceneSubMesh = new MySceneSubMesh(newVertices, geometrySubMesh.Indices,
                                                                 geometrySubMesh.TextureCoordCount, geometrySubMesh.VertexColors, geometrySubMesh.Material);
                generatedSubMeshes.Add(sceneSubMesh);
            }

            return(true);
        }