public Collada(IEnumerable <List <Triangle> > meshes, Joint rootjoint, IEnumerable <XElement> extradata, string path, DateTime creattime, DateTime modtime) { basepath = path; List <Geometry> geometries = new List <Geometry>(); List <Node> scenenodes = new List <Node>(); List <Node> modelnodes = new List <Node>(); List <SkinController> controllers = new List <SkinController>(); Skeleton skeleton = rootjoint == null ? null : new Skeleton("model_skel", rootjoint); Animation animation = rootjoint == null ? null : skeleton.GetAnimatedBones().Count() != 0 ? new Animation(skeleton) : null; List <InstanceBase> instnodes = new List <InstanceBase>(); foreach (List <Triangle> mesh in meshes.Where(m => m.Count != 0)) { Geometry geometry = new Geometry(this, CreateSymbol("model_mesh"), mesh); Node node = new Node(geometry.ID + "_node", geometry.GetInstance()); geometries.Add(geometry); if (skeleton != null) { SkinController controller = new SkinController(geometry, skeleton); controllers.Add(controller); node = new Node(controller.ID + "_node", controller.GetInstance()); } modelnodes.Add(node); } Node modelroot = new Node("model", modelnodes, skeleton); scenenodes.Add(modelroot); this.Add( new XElement(ns + "COLLADA", new XAttribute("version", "1.4.1"), new XElement(ns + "asset", new XElement(ns + "contributor", new XElement(ns + "author", "IonFx") ), new XElement(ns + "created", creattime.ToString("O")), new XElement(ns + "modified", modtime.ToString("O")), new XElement(ns + "up_axis", "Z_UP") ), new XElement(ns + "library_images", Materials.Values.Select(m => m.Effect.Image)), new XElement(ns + "library_effects", Materials.Values.Select(m => m.Effect)), new XElement(ns + "library_materials", Materials.Values), new XElement(ns + "library_geometries", geometries, extradata == null ? null : new XElement(ns + "extra", new XElement(ns + "technique", new XAttribute("profile", "RS5-Extra"), extradata ) ) ), controllers.Count == 0 ? null : new XElement(ns + "library_controllers", controllers), animation == null ? null : new XElement(ns + "library_animations", animation), new XElement(ns + "library_visual_scenes", new XElement(ns + "visual_scene", new XAttribute("id", "visual_scene"), scenenodes ) ), new XElement(ns + "scene", new XElement(ns + "instance_visual_scene", new XAttribute("url", "#visual_scene") ) ) ) ); }
public JointInfluence(Joint joint, double influence) { Joint = joint; Influence = influence; }
public static void Save(string filename, IEnumerable <List <Triangle> > meshes, Joint rootjoint, IEnumerable <XElement> extradata, DateTime creattime, DateTime modtime) { string dir = Path.GetDirectoryName(filename); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string path = Path.Combine(".", Path.Combine(Path.GetDirectoryName(filename).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(d => d != "." && d != "..").Select(d => "..").ToArray())); XDocument doc = new Collada(meshes, rootjoint, extradata, path, creattime, modtime); doc.Save(filename); File.SetLastWriteTimeUtc(filename, modtime); }
public Skeleton(string skeletonname, Joint joint) : base(skeletonname, joint, new XAttribute("name", skeletonname)) { this.SkeletonName = skeletonname; }
protected Bone(string skeletonname, Joint joint, params object[] content) : base(skeletonname + "_" + joint.Symbol, content) { this.SID = joint.Symbol; this.Joint = joint; this.ChildBones = joint.Children.Select(j => new Bone(skeletonname, j)).ToArray(); this.Transform = new Matrix("transform", joint.InitialPose); this.Add( new XAttribute("sid", SID), new XAttribute("type", "JOINT"), Transform, ChildBones ); }
public Collada(IEnumerable<List<Triangle>> meshes, Joint rootjoint, IEnumerable<XElement> extradata, string path, DateTime creattime, DateTime modtime) { basepath = path; List<Geometry> geometries = new List<Geometry>(); List<Node> scenenodes = new List<Node>(); List<Node> modelnodes = new List<Node>(); List<SkinController> controllers = new List<SkinController>(); Skeleton skeleton = rootjoint == null ? null : new Skeleton("model_skel", rootjoint); Animation animation = rootjoint == null ? null : skeleton.GetAnimatedBones().Count() != 0 ? new Animation(skeleton) : null; List<InstanceBase> instnodes = new List<InstanceBase>(); foreach (List<Triangle> mesh in meshes.Where(m => m.Count != 0)) { Geometry geometry = new Geometry(this, CreateSymbol("model_mesh"), mesh); Node node = new Node(geometry.ID + "_node", geometry.GetInstance()); geometries.Add(geometry); if (skeleton != null) { SkinController controller = new SkinController(geometry, skeleton); controllers.Add(controller); node = new Node(controller.ID + "_node", controller.GetInstance()); } modelnodes.Add(node); } Node modelroot = new Node("model", modelnodes, skeleton); scenenodes.Add(modelroot); this.Add( new XElement(ns + "COLLADA", new XAttribute("version", "1.4.1"), new XElement(ns + "asset", new XElement(ns + "contributor", new XElement(ns + "author", "IonFx") ), new XElement(ns + "created", creattime.ToString("O")), new XElement(ns + "modified", modtime.ToString("O")), new XElement(ns + "up_axis", "Z_UP") ), new XElement(ns + "library_images", Materials.Values.Select(m => m.Effect.Image)), new XElement(ns + "library_effects", Materials.Values.Select(m => m.Effect)), new XElement(ns + "library_materials", Materials.Values), new XElement(ns + "library_geometries", geometries, extradata == null ? null : new XElement(ns + "extra", new XElement(ns + "technique", new XAttribute("profile", "RS5-Extra"), extradata ) ) ), controllers.Count == 0 ? null : new XElement(ns + "library_controllers", controllers), animation == null ? null : new XElement(ns + "library_animations", animation), new XElement(ns + "library_visual_scenes", new XElement(ns + "visual_scene", new XAttribute("id", "visual_scene"), scenenodes ) ), new XElement(ns + "scene", new XElement(ns + "instance_visual_scene", new XAttribute("url", "#visual_scene") ) ) ) ); }
public static void Save(string filename, IEnumerable<List<Triangle>> meshes, Joint rootjoint, IEnumerable<XElement> extradata, DateTime creattime, DateTime modtime) { string dir = Path.GetDirectoryName(filename); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string path = Path.Combine(".", Path.Combine(Path.GetDirectoryName(filename).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(d => d != "." && d != "..").Select(d => "..").ToArray())); XDocument doc = new Collada(meshes, rootjoint, extradata, path, creattime, modtime); doc.Save(filename); File.SetLastWriteTimeUtc(filename, modtime); }
public Joint(Joint joint) : this(joint.Symbol, joint.Name, joint.ReverseBindingMatrix, joint.InitialPose, joint.Children, joint.Animation) { }