コード例 #1
0
        private static LXFMLDoc.BrickGroup FindGroup(LXFMLDoc lxfml, LXFMLDoc.Brick brick)
        {
            foreach (var group in lxfml.groups)
            {
                if (group.brickRefs.Contains(brick.refId))
                {
                    return(group);
                }
            }

            return(null);
        }
コード例 #2
0
        private static bool FindBrickInGroups(LXFMLDoc.Brick brick, LXFMLDoc.BrickGroup[] groups)
        {
            foreach (var group in groups)
            {
                if (Array.IndexOf(group.brickRefs, brick.refId) >= 0)
                {
                    return(true);
                }

                if (group.children != null && FindBrickInGroups(brick, group.children))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        public static LXFMLDoc.Brick PopulateBrick(XmlNode brickNode)
        {
            var brick = new LXFMLDoc.Brick();

            brick.designId = brickNode.Attributes["designID"].Value.Split(';')[0]; // TODO: Use version.
            brick.refId    = Convert.ToInt32(brickNode.Attributes["refID"].Value);
            if (brickNode.Attributes["uuid"] != null)
            {
                brick.uuid = brickNode.Attributes["uuid"].Value;
            }

            string mats = "";

            foreach (System.Xml.XmlNode item in brickNode.SelectNodes("Part"))
            {
                mats += item.Attributes["materials"].Value + ",";
            }

            mats = mats.Remove(mats.Length - 1);

            LXFMLDoc.Brick.Part[] parts = new LXFMLDoc.Brick.Part[brickNode.SelectNodes("Part").Count];

            for (int i = 0; i < brickNode.SelectNodes("Part").Count; i++)
            {
                var partNode = brickNode.SelectNodes("Part")[i];
                parts[i]               = new LXFMLDoc.Brick.Part();
                parts[i].refId         = Convert.ToInt32(partNode.Attributes["refID"].Value);
                parts[i].brickDesignId = brick.designId;
                parts[i].partDesignId  = partNode.Attributes["designID"].Value.Split(';')[0];                                // TODO: Use version.
                parts[i].materials     = ParseUtils.StringOfMaterialToMaterialArray(partNode.Attributes["materials"].Value); // TODO: Use shader id.

                var decoAttrib = partNode.Attributes["decoration"];
                if (decoAttrib != null)
                {
                    parts[i].decorations = ParseUtils.StringOfDecorationToDecorationArray(decoAttrib.Value);
                }

                var boneNodes = partNode.SelectNodes("Bone");
                parts[i].bones = new LXFMLDoc.Brick.Part.Bone[boneNodes.Count];

                foreach (XmlNode boneNode in boneNodes)
                {
                    var bone = new LXFMLDoc.Brick.Part.Bone();
                    bone.refId = Convert.ToInt32(boneNode.Attributes["refID"].Value);

                    var transformation = new Matrix4x4();
                    var mArr           = ParseUtils.StringToFloatArray(boneNode.Attributes["transformation"].Value);

                    for (var j = 0; j < 4; ++j)
                    {
                        transformation.SetRow(j, new Vector4(mArr[j * 3], mArr[j * 3 + 1], mArr[j * 3 + 2], 0));
                    }

                    bone.position = GetPosition(transformation);
                    bone.rotation = GetRotation(transformation);

                    parts[i].bones[0] = bone;
                }
            }

            brick.parts = parts;
            return(brick);
        }