Exemple #1
0
        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")
                                                       )
                                          )
                             )
                );
        }
Exemple #2
0
        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")
                        )
                    )
                )
            );
        }