示例#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);
        }
示例#2
0
        SubMeshVertex[] GenerateSubMeshVertices(Pair <ChannelTypes, SourceItem>[] inputs, int vertexCount,
                                                int[] indices, int startIndex)
        {
            SubMeshVertex[] itemVertices = new SubMeshVertex[vertexCount];

            int currentIndex = startIndex;

            for (int nVertex = 0; nVertex < itemVertices.Length; nVertex++)
            {
                SubMeshVertex vertex = new SubMeshVertex();

                foreach (Pair <ChannelTypes, SourceItem> input in inputs)
                {
                    ChannelTypes channelType = input.First;
                    SourceItem   source      = input.Second;

                    int indexValue = indices[currentIndex];
                    currentIndex++;

                    switch (channelType)
                    {
                    case ChannelTypes.POSITION:
                        vertex.position = source.GetItemVec3(indexValue);
                        break;

                    case ChannelTypes.NORMAL:
                        vertex.normal = source.GetItemVec3(indexValue);
                        break;

                    case ChannelTypes.TEXCOORD0:
                        vertex.texCoord0 = source.GetItemVec2(indexValue);
                        break;

                    case ChannelTypes.TEXCOORD1:
                        vertex.texCoord1 = source.GetItemVec2(indexValue);
                        break;

                    case ChannelTypes.TEXCOORD2:
                        vertex.texCoord2 = source.GetItemVec2(indexValue);
                        break;

                    case ChannelTypes.TEXCOORD3:
                        vertex.texCoord3 = source.GetItemVec2(indexValue);
                        break;

                    case ChannelTypes.COLOR:
                    {
                        Vec3 c = source.GetItemVec3(indexValue);;
                        vertex.color = new ColorValue(c.X, c.Y, c.Z, 1);
                    }
                    break;

                        //maybe need use "TEXTANGENT".
                        //case ChannelTypes.TANGENT:
                        //   vertex.tangent = source.GetItemVec3( indexValue );
                        //   break;
                    }
                }

                itemVertices[nVertex] = vertex;
            }

            return(itemVertices);
        }