private static void SetPositionRotation(GameObject partGO, LXFMLDoc.Brick.Part part) { foreach (var bone in part.bones) { partGO.transform.localPosition = bone.position; partGO.transform.localRotation = bone.rotation; break; // no support for flex } }
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); }