예제 #1
0
        /// <summary> Populates this class private stuff </summary>
        /// <param name="text"> Splitted text representation of a JMS file </param>
        private void Populate(string[] text)
        {
            int i = 0;

            this.version = int.Parse(text[i++]);
            if (this.version != Constants.HALO_JMS_VERSION)
            {
                throw new NotSupportedException(
                          string.Format("Unsupported JMS version {0}", this.version)
                          );
            }

            this.checksum = int.Parse(text[i++]);

            // parsing nodes
            this.nodes = new JMSNode[int.Parse(text[i++])];

            for (int n = 0, N = this.nodes.Length; n < N; n++)
            {
                JMSNode node = new JMSNode();

                node.name = text[i++];

                node.parent_index = -1;
                node.first_child  = int.Parse(text[i++]);
                node.next_sibling = int.Parse(text[i++]);


                node.rotation = new Quaternion(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );

                node.position = new Vector3(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );

                this.nodes[n] = node;
            }

            // parsing materials
            this.materials = new JMSMaterial[int.Parse(text[i++])];

            for (int m = 0, M = this.materials.Length; m < M; m++)
            {
                JMSMaterial material = new JMSMaterial();

                material.name = text[i++];
                material.path = text[i++];

                this.materials[m] = material;
            }

            // parse markers
            this.markers = new JMSMarker[int.Parse(text[i++])];

            for (int m = 0, M = this.markers.Length; m < M; m++)
            {
                JMSMarker marker = new JMSMarker();

                marker.name        = text[i++];
                marker.permutation = "unnamed";


                marker.region = int.Parse(text[i++]);
                marker.parent = int.Parse(text[i++]);

                marker.rotation = new Quaternion(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );

                marker.position = new Vector3(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );

                marker.radius   = float.Parse(text[i++], CultureInfo.InvariantCulture);
                this.markers[m] = marker;
            }

            // parse regions
            this.regions = new string[int.Parse(text[i++])];

            for (int r = 0, R = this.regions.Length; r < R; r++)
            {
                this.regions[r] = text[i++];
            }

            // parse vertices
            this.vertices = new JMSVertex[int.Parse(text[i++])];

            for (int v = 0, V = this.vertices.Length; v < V; v++)
            {
                JMSVertex vertex = new JMSVertex();

                vertex.node0 = int.Parse(text[i++]);

                vertex.position = new Vector3(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );

                // as Moses' reclaimer has commented out, normals are clamped by tool.exe
                vertex.normal = new Vector3(
                    Math.Min(Mathf.Max(float.Parse(text[i++], CultureInfo.InvariantCulture), -1.0f), 1.0f),
                    Math.Min(Mathf.Max(float.Parse(text[i++], CultureInfo.InvariantCulture), -1.0f), 1.0f),
                    Math.Min(Mathf.Max(float.Parse(text[i++], CultureInfo.InvariantCulture), -1.0f), 1.0f)
                    );

                vertex.node1       = int.Parse(text[i++]);
                vertex.node1weight = float.Parse(text[i++]);

                vertex.uv = new Vector2(
                    float.Parse(text[i++], CultureInfo.InvariantCulture),
                    float.Parse(text[i++], CultureInfo.InvariantCulture)
                    );
                i++;                 // skip useless w component

                vertex.tangent  = new Vector3(0f, 1f, 0f);
                vertex.binormal = new Vector3(1f, 0f, 0f);

                this.vertices[v] = vertex;
            }

            // parse triangles
            this.triangles = new JMSTriangle[int.Parse(text[i++])];

            for (int t = 0, T = this.triangles.Length; t < T; t++)
            {
                JMSTriangle triangle = new JMSTriangle();

                triangle.region = int.Parse(text[i++]);
                triangle.shader = int.Parse(text[i++]);

                triangle.vertices = new int[] {
                    int.Parse(text[i++]),
                    int.Parse(text[i++]),
                    int.Parse(text[i++])
                };

                this.triangles[t] = triangle;
            }

            return;
        }
예제 #2
0
        public void Populate(string[] text)
        {
            int i = 0;

            Func <float>  readFloat  = () => float.Parse(text[i++], CultureInfo.InvariantCulture);
            Func <int>    readInt    = () => int.Parse(text[i++], CultureInfo.InvariantCulture);
            Func <string> readString = () => text[i++];

            this.version = readInt();
            if (this.version != 16392)
            {
                throw new NotSupportedException(string.Format("Unsupported {0} version", this.version));
            }

            this.frame_count = readInt();
            this.frame_rate  = readInt();

            {
                int actors;
                if ((actors = readInt()) != 1)
                {
                    throw new NotSupportedException(string.Format("Only one actor is supported ATM. {0} provided", actors));
                }
            }
            this.actor = readString();

            this.nodes = new JMSNode[readInt()];
            /* checksum = */ readInt();

            for (int n = 0, N = this.nodes.Length; n < N; n++)
            {
                var node = new JMSNode();

                node.name         = readString();
                node.first_child  = readInt();
                node.next_sibling = readInt();
                node.parent_index = -1;

                this.nodes[n] = node;
            }

            this.keyframes = new JMANodeState[this.frame_count, this.nodes.Length];

            for (int f = 0, F = frame_count; f < F; f++)
            {
                for (int n = 0, N = this.nodes.Length; n < N; n++)
                {
                    JMANodeState state = new JMANodeState();

                    state.position = new Vector3(
                        readFloat(), readFloat(), readFloat()
                        );

                    state.rotation = new Quaternion(
                        readFloat(), readFloat(), readFloat(), readFloat()
                        );
                    state.scale = readFloat();

                    this.keyframes[f, n] = state;
                }
            }
        }