예제 #1
0
        void AutodetectTree(ColladaObject obj, List <OutModel> parent, Dictionary <string, ColladaObject[]> autodetect)
        {
            if (!obj.AutodetectInclude)
            {
                return;
            }
            var mdl = new OutModel();

            mdl.Name = obj.Name;
            if (obj.Name.EndsWith("_lod0", StringComparison.InvariantCultureIgnoreCase))
            {
                mdl.Name = obj.Name.Remove(obj.Name.Length - 5, 5);
            }
            var geometry = autodetect[mdl.Name];

            foreach (var g in geometry)
            {
                if (g != null)
                {
                    mdl.LODs.Add(g);
                }
            }
            foreach (var child in obj.Children)
            {
                AutodetectTree(child, mdl.Children, autodetect);
            }
            parent.Add(mdl);
        }
예제 #2
0
 //Autodetected LOD: object with geometry + suffix _lod[0-9]
 int LodNumber(ColladaObject obj, out string name)
 {
     name = obj.Name;
     if (obj.Geometry == null) return -1;
     if (obj.Name.Length < 6) return 0;
     if (!char.IsDigit(obj.Name, obj.Name.Length - 1)) return 0;
     if (!CheckSuffix("_lodX", obj.Name, 4)) return 0;
     name = obj.Name.Substring(0, obj.Name.Length - "_lodX".Length);
     return int.Parse(obj.Name[obj.Name.Length - 1] + "");
 }
예제 #3
0
        static ColladaObject ProcessNode(CL.UpAxisType up, CL.library_geometries geom, CL.node n, bool isBlender)
        {
            var obj = new ColladaObject();

            obj.Name = n.name;
            obj.ID   = n.id;
            if (n.instance_geometry != null && n.instance_geometry.Length > 0)
            {
                //Geometry object
                if (n.instance_geometry.Length != 1)
                {
                    throw new Exception("How to handle multiple geometries/node?");
                }
                var uri = CheckURI(n.instance_geometry[0].url);
                var g   = geom.geometry.Where((x) => x.id == uri).First();
                if (g.Item is CL.mesh)
                {
                    obj.Geometry = GetGeometry(up, g, isBlender);
                }
                else if (g.Item is CL.spline)
                {
                    obj.Spline = GetSpline(up, g);
                }
            }
            if (n.Items.OfType <CL.matrix>().Any())
            {
                var tr = n.Items.OfType <CL.matrix>().First();
                obj.Transform = GetMatrix(up, tr.Text);
            }
            else
            {
                Matrix4 mat = Matrix4.Identity;
                foreach (var item in n.Items)
                {
                    if (item is CL.TargetableFloat3)
                    {
                        //var float3 =
                    }
                }
                obj.Transform = mat;
            }
            if (n.node1 != null && n.node1.Length > 0)
            {
                foreach (var node in n.node1)
                {
                    obj.Children.Add(ProcessNode(up, geom, node, isBlender));
                }
            }
            return(obj);
        }
예제 #4
0
 void GetLods(ColladaObject obj, Dictionary<string,ColladaObject[]> autodetect)
 {
     string objn;
     var num = LodNumber(obj, out objn);
     obj.AutodetectInclude = (num == 0);
     if(num != -1) {
        ColladaObject[] lods;
         if(!autodetect.TryGetValue(objn, out lods)) {
             lods = new ColladaObject[10];
             autodetect.Add(objn, lods);
         }
         lods[num] = obj;
     }
     foreach (var child in obj.Children)
         GetLods(child, autodetect);
 }
예제 #5
0
        void ColladaTree(ColladaObject obj, ref int i)
        {
            string tree_icon = "dummy";

            if (obj.Geometry != null)
            {
                tree_icon = "fix";
            }
            if (obj.Children.Count > 0)
            {
                var flags = TreeNodeFlags.OpenOnDoubleClick |
                            TreeNodeFlags.DefaultOpen |
                            TreeNodeFlags.OpenOnArrow;
                if (obj == selected)
                {
                    flags |= TreeNodeFlags.Selected;
                }
                var open = ImGui.TreeNodeEx(ImGuiExt.Pad(obj.Name + "##" + i++), flags);
                if (ImGuiNative.igIsItemClicked(0))
                {
                    selected = obj;
                }
                ColladaContextMenu();
                Theme.RenderTreeIcon(obj.Name, tree_icon, Color4.White);
                if (open)
                {
                    foreach (var child in obj.Children)
                    {
                        ColladaTree(child, ref i);
                    }
                    ImGui.TreePop();
                }
                i += 500;
            }
            else
            {
                if (ImGui.Selectable(ImGuiExt.Pad(obj.Name + "##" + i++), obj == selected))
                {
                    selected = obj;
                }
                ColladaContextMenu();
                Theme.RenderTreeIcon(obj.Name, tree_icon, Color4.White);
            }
        }
예제 #6
0
        static ColladaObject ProcessNode(CL.UpAxisType up, CL.library_geometries geom, CL.node n)
        {
            var obj = new ColladaObject();

            obj.Name = n.name;
            obj.ID   = n.id;
            if (n.instance_geometry != null && n.instance_geometry.Length > 0)
            {
                //Geometry object
                if (n.instance_geometry.Length != 1)
                {
                    throw new Exception("How to handle multiple geometries/node?");
                }
                var uri = CheckURI(n.instance_geometry[0].url);
                var g   = geom.geometry.Where((x) => x.id == uri).First();
                if (g.Item is CL.mesh)
                {
                    obj.Geometry = GetGeometry(up, g);
                }
                else if (g.Item is CL.spline)
                {
                    obj.Spline = GetSpline(up, g);
                }
            }
            if (n.Items.OfType <CL.matrix>().Any())
            {
                var tr = n.Items.OfType <CL.matrix>().First();
                obj.Transform = GetMatrix(tr.Text);
            }
            else
            {
                //TODO: Non-matrix transforms
            }
            if (n.node1 != null && n.node1.Length > 0)
            {
                foreach (var node in n.node1)
                {
                    obj.Children.Add(ProcessNode(up, geom, node));
                }
            }
            return(obj);
        }