コード例 #1
0
ファイル: effect.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "annotate":
                    if(Annotates == null)
                        Annotates	= new List<annotate>();
                    Annotates.Add(Doc.Load<annotate>(this,Child));
                    break;

                case "newparam":
                    if(Params == null)
                        Params	= new List<newparam>();
                    Params.Add(Doc.Load<newparam>(this,Child));
                    break;

                case "profile":
                    if(Profiles == null)
                        Profiles	= new List<profile>();
                    Profiles.Add(Doc.Load<profile>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #2
0
ファイル: animation.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "animation":
                    if(Childs == null)
                        Childs	= new List<animation>();
                    Childs.Add(Doc.Load<animation>(this,Child));
                    break;

                case "source":
                    if(Sources == null)
                        Sources	= new List<source>();
                    Sources.Add(Doc.Load<source>(this,Child));
                    break;

                case "sampler":
                    if(Samplers == null)
                        Samplers	= new List<sampler>();
                    Samplers.Add(Doc.Load<sampler>(this,Child));
                    break;

                case "channel":
                    if(Channels == null)
                        Channels	= new List<channel>();
                    Channels.Add(Doc.Load<channel>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #3
0
ファイル: node.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "lookat":
                    ChildNodes.Add(Doc.Load<lookat>(this,Child));
                    break;

                case "matrix":
                    ChildNodes.Add(Doc.Load<matrix>(this,Child));
                    break;

                case "rotate":
                    ChildNodes.Add(Doc.Load<rotate>(this,Child));
                    break;

                case "scale":
                    ChildNodes.Add(Doc.Load<scale>(this,Child));
                    break;

                case "skew":
                    ChildNodes.Add(Doc.Load<skew>(this,Child));
                    break;

                case "translate":
                    ChildNodes.Add(Doc.Load<translate>(this,Child));
                    break;

                case "instance_camera":
                    ChildNodes.Add(Doc.Load<instance_camera>(this,Child));
                    break;

                case "instance_controller":
                    ChildNodes.Add(Doc.Load<instance_controller>(this,Child));
                    break;

                case "instance_geometry":
                    ChildNodes.Add(Doc.Load<instance_geometry>(this,Child));
                    break;

                case "instance_light":
                    ChildNodes.Add(Doc.Load<instance_light>(this,Child));
                    break;

                case "instance_node":
                    ChildNodes.Add(Doc.Load<instance_node>(this,Child));
                    break;

                case "node":
                    ChildNodes.Add(Doc.Load<node>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #4
0
ファイル: optics.cs プロジェクト: miquik/leviatan-game
        void IHasTechChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "orthographic":
                    Projection	= Doc.Load<orthographic>(this,Child);
                    break;

                case "perspective":
                    Projection	= Doc.Load<perspective>(this,Child);
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #5
0
ファイル: camera.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "optics":
                    Optics	= Doc.Load<optics>(this,Child);
                    break;

                case "imager":
                    Imager	= Doc.Load<imager>(this,Child);
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #6
0
ファイル: accessor.cs プロジェクト: miquik/leviatan-game
 void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "param")
     {
         if(Params == null)
             Params	= new List<param>();
         Params.Add(Doc.Load<param>(this,Child));
     }
     else throw new Exception("Invalid Child Node");
 }
コード例 #7
0
        public void FromDAEFile(string file_name, int roomIndex)
        {
            int origRootRoomTableIndex = RootNode.RoomTableIndex;

            COLLADA dae = COLLADA.Load(file_name);

            m_Nodes   = new List <CollisionGroupNode>();
            Triangles = new List <CollisionTriangle>();
            LoadFromCollada(dae, roomIndex, origRootRoomTableIndex);
        }
コード例 #8
0
ファイル: vertices.cs プロジェクト: miquik/leviatan-game
 void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "input")
     {
         if(Inputs == null)
             Inputs	= new List<input>();
         Inputs.Add(Doc.Load<input>(this,Child));
     }
     else throw new Exception("Invalid Child Node");
 }
コード例 #9
0
ファイル: bind_material.cs プロジェクト: miquik/leviatan-game
 void IHasTechChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "instance_material")
     {
         if(Materials == null)
             Materials	= new List<instance_materials>();
         Materials.Add(Doc.Load<instance_materials>(this,Child));
     }
     else throw new Exception("Invalid Child Node");
 }
コード例 #10
0
ファイル: visual_scene.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "node":
                    if(Nodes == null)
                        Nodes	= new List<node>();
                    Nodes.Add(Doc.Load<node>(this,Child));
                    break;

                case "evaluate_scene":
                    if(EvaluateScenes == null)
                        EvaluateScenes	= new List<evaluate_scene>();
                    EvaluateScenes.Add(Doc.Load<evaluate_scene>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #11
0
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "instance_animation":
                    if(InstanceAnimations == null)
                        InstanceAnimations	= new List<instance_animation>();
                    InstanceAnimations.Add(Doc.Load<instance_animation>(this,Child));
                    break;

                case "instance_formula":
                    if(InstanceFormulas == null)
                        InstanceFormulas	= new List<instance_formula>();
                    InstanceFormulas.Add(Doc.Load<instance_formula>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #12
0
ファイル: bind_material.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "param":
                    if(Params == null)
                        Params	= new List<param>();
                    Params.Add(Doc.Load<param>(this,Child));
                    break;

                case "technique":
                    if(Technique == null)
                        Technique	= new List<technique>();
                    Technique.Add(Doc.Load<technique>(this,Child));
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #13
0
ファイル: image.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "renderable":
                    break;

                case "init_from":
                    InitData	= Doc.Load<init_from>(this,Child);
                    break;
            }
        }
コード例 #14
0
ファイル: source.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "bool_array":
                    Array	= Doc.Load<bool_array>(this,Child);
                    break;

                case "float_array":
                    Array	= Doc.Load<float_array>(this,Child);
                    break;

                case "IDREF_array":
                    Array	= Doc.Load<IDREF_array>(this,Child);
                    break;

                case "int_array":
                    Array	= Doc.Load<int_array>(this,Child);
                    break;

                case "Name_array":
                    Array	= Doc.Load<Name_array>(this,Child);
                    break;

                case "SIDREF_array":
                    Array	= Doc.Load<SIDREF_array>(this,Child);
                    break;

                case "token_array":
                    break;

                case "technique":
                    break;
            }
        }
コード例 #15
0
        public bool LoadFile(string FileName)
        {
            COLLADA collada = COLLADA.Load(FileName);

            foreach (var item in collada.Items)
            {
                if (item is library_geometries)
                {
                    LoadGeometry((library_geometries)item);
                }
            }

            return(true);
        }
コード例 #16
0
ファイル: asset.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "contributor":
                    if(Contributors == null)
                        Contributors	= new List<contributor>();
                    Contributors.Add(Doc.Load<contributor>(this,Child));
                    break;

                case "coverage":
                    break;

                case "created":
                    Created	= DateTime.Parse(Child.InnerText);
                    break;

                case "keywords":
                    Keywords	= Child.InnerText;
                    break;

                case "modified":
                    Modified	= DateTime.Parse(Child.InnerText);
                    break;

                case "revision":
                    Revision	= Child.InnerText;
                    break;

                case "subject":
                    Subject	= Child.InnerText;
                    break;

                case "title":
                    Title	= Child.InnerText;
                    break;

                case "unit":
                    Unit	= float.Parse(Child.Attributes["meter"].InnerText);
                    UnitType	= Child.Attributes["name"].InnerText;
                    break;

                case "up_axis":
                    UpAxis	= (SixAxis)Enum.Parse(typeof(SixAxis),Child.InnerText);
                    break;

                default:
                    throw new Exception("Invalid Child");
            }
        }
コード例 #17
0
ファイル: mesh.cs プロジェクト: miquik/leviatan-game
        protected override void InitChild(COLLADA Doc,XmlNode Child)
        {
            if(Child.Name == "vertices")
                Vertices	= Doc.Load<vertices>(this,Child);
            else
            {
                primitive_element PrmElement	= null;
                switch(Child.Name)
                {
                    case "lines":
                        PrmElement	= Doc.Load<lines>(this,Child);
                        break;

                    case "linestrips":
                        PrmElement	= Doc.Load<linestrips>(this,Child);
                        break;

                    case "polygons":
                        PrmElement	= Doc.Load<polygons>(this,Child);
                        break;

                    case "polylist":
                        PrmElement	= Doc.Load<polylist>(this,Child);
                        break;

                    case "triangles":
                        PrmElement	= Doc.Load<triangles>(this,Child);
                        break;

                    case "trifans":
                        PrmElement	= Doc.Load<trifans>(this,Child);
                        break;

                    case "tristrips":
                        PrmElement	= Doc.Load<tristrips>(this,Child);
                        break;

                    default:
                        throw new Exception("Invalid Child Node");
                }

                if(Primitives == null)
                    Primitives	= new List<primitive_element>();
                if(PrmElement != null)
                    Primitives.Add(PrmElement);
            }
        }
コード例 #18
0
ファイル: DAELoaderNode.cs プロジェクト: Marc56K/Collada14
        internal void Open(string fileName)
        {
            Context.LogInfo(this, "Loading " + fileName);

            FileName = fileName;
            Document = COLLADA.Load(fileName);

            LibVisualScenes = new DAELibraryVisualScenes();
            LibEffects      = new DAELibraryEffects();
            LibGeometries   = new DAELibraryGeometries();
            LibImages       = new DAELibraryImages();
            LibLights       = new DAELibraryLights();
            LibMaterials    = new DAELibraryMaterials();
            LibNodes        = new DAELibraryNodes();

            foreach (var item in Document.Items)
            {
                if (item is library_visual_scenes)
                {
                    LibVisualScenes.Init(item as library_visual_scenes);
                }
                else if (item is library_effects)
                {
                    LibEffects.Init(item as library_effects);
                }
                else if (item is library_geometries)
                {
                    LibGeometries.Init(item as library_geometries);
                }
                else if (item is library_images)
                {
                    LibImages.Init(item as library_images);
                }
                else if (item is library_lights)
                {
                    LibLights.Init(item as library_lights);
                }
                else if (item is library_materials)
                {
                    LibMaterials.Init(item as library_materials);
                }
                else if (item is library_nodes)
                {
                    LibNodes.Init(item as library_nodes);
                }
            }

            Context.LogInfo(this, "Loading " + fileName + " finished");
        }
 private Collada141.COLLADA Load(string meshLocation)
 {
     if (meshLocation.Contains("package://"))
     {
         string trimmed;
         string pkg         = (trimmed = meshLocation.Replace("package://", "")).Split('/')[0];
         string relpath     = trimmed.Replace(pkg, "");
         string pkgLocation = Resolve(pkg);
         return(COLLADA.Load(pkgLocation + "/" + relpath));
     }
     else
     {
         throw new NotImplementedException("Unhandled mesh location type");
     }
 }
コード例 #20
0
ファイル: CollisionMesh.cs プロジェクト: FrasseFreak/Winditor
        /// <summary>
        /// Creates a collision mesh from the given file, handling COLLADA DAE files only.
        /// </summary>
        /// <param name="world">World containing the collision mesh</param>
        /// <param name="file_name">File to load the model from</param>
        /// <param name="roomIndex">The room number to give to the new collision mesh</param>
        /// <param name="roomTableIndex">The room table index to give to all collision groups in the new collision mesh (hack)</param>
        public WCollisionMesh(WWorld world, string file_name, int roomIndex, int roomTableIndex) : base(world)
        {
            Init();
            FileName = Path.GetFileNameWithoutExtension(file_name);

            if (file_name.EndsWith(".dae"))
            {
                COLLADA dae = COLLADA.Load(file_name);
                LoadFromCollada(dae, roomIndex, roomTableIndex);
            }
            else
            {
                throw new Exception($"File is not a DAE: {file_name}");
            }
        }
コード例 #21
0
ファイル: light.cs プロジェクト: miquik/leviatan-game
        void IHasTechChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "ambient":
                    LightSource	= Doc.Load<ambient>(this,Child);
                    break;

                case "directional":
                    LightSource	= Doc.Load<directional>(this,Child);
                    break;

                case "point":
                    LightSource	= Doc.Load<point>(this,Child);
                    break;

                case "spot":
                    LightSource	= Doc.Load<spot>(this,Child);
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #22
0
ファイル: CollisionMesh.cs プロジェクト: LordNed/Winditor
        /// <summary>
        /// Creates a collision mesh from the given file, handling COLLADA DAE files only.
        /// </summary>
        /// <param name="world">World containing the collision mesh</param>
        /// <param name="file_name">File to load the model from</param>
        /// <param name="roomIndex">The room number to give to the new collision mesh</param>
        /// <param name="roomTableIndex">The room table index to give to all collision groups in the new collision mesh (hack)</param>
        public WCollisionMesh(WWorld world, string file_name, int roomIndex, int roomTableIndex) : base(world)
        {
            Init();
            FileName = Path.GetFileNameWithoutExtension(file_name);

            if (file_name.EndsWith(".dae"))
            {
                COLLADA dae = COLLADA.Load(file_name);
                LoadFromCollada(dae, roomIndex, roomTableIndex);
            }
            else
            {
                LoadFromObj(File.ReadAllLines(file_name), roomIndex, roomTableIndex);
            }
        }
コード例 #23
0
ファイル: scene.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "instance_physics_scene":
                    break;

                case "instance_visual_scene":
                    VisualScene	= Doc.Load<instance_visual_scene>(this,Child);
                    break;

                case "instance_kinematics_scene":
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #24
0
        /// <summary>
        /// Creates a collision mesh from the given file, handling both COLLADA DAE and DZB files.
        /// </summary>
        /// <param name="world">World containing the collision mesh</param>
        /// <param name="file_name">File to load the model from</param>
        public WCollisionMesh(WWorld world, string file_name) : base(world)
        {
            Init();
            FileName = Path.GetFileNameWithoutExtension(file_name);

            if (file_name.EndsWith(".dae"))
            {
                COLLADA dae = COLLADA.Load(file_name);
                LoadFromCollada(dae);
            }
            else if (file_name.EndsWith(".dzb"))
            {
                using (EndianBinaryReader reader = new EndianBinaryReader(File.ReadAllBytes(file_name), Endian.Big))
                {
                    LoadFromDZB(reader);
                }
            }
        }
コード例 #25
0
ファイル: newparam.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "annotate":
                    if(Annotates == null)
                        Annotates	= new List<annotate>();
                    Annotates.Add(Doc.Load<annotate>(this,Child));
                    break;
                case "semantic":
                    Semantic	= Child.Value;
                    break;
                case "modifier":
                    Modifier	= (modifier)Enum.Parse(typeof(modifier),Child.Value);
                    break;

                case "float":
                    Value	= float.Parse(Child.Value);
                    break;

                case "float2":
                case "float3":
                case "float4":
                    char[] Splitter	= {' ','\n'};
                    string[] V	= Child.Value.Split(Splitter,StringSplitOptions.RemoveEmptyEntries);

                    Value	= new float[V.Length];

                    int i	= 0;
                    while(i < V.Length)
                    {
                        (Value as float[])[i]	= float.Parse(V[i]);
                        i++;
                    }

                    break;

                case "sampler2D":
                    break;
            }
        }
コード例 #26
0
ファイル: geometry.cs プロジェクト: miquik/leviatan-game
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "convex_mesh":
                    break;

                case "mesh":
                    Geometric	= Doc.Load<mesh>(this,Child);
                    break;

                case "spline":
                    break;

                case "brep":
                    break;

                default:
                    throw new Exception("Invalid Child Node");
            }
        }
コード例 #27
0
        void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
        {
            switch(Child.Name)
            {
                case "input":
                    if(Inputs == null)
                        Inputs	= new List<input>();

                    input I	= Doc.Load<input>(this,Child);
                    Inputs.Add(I);

                    if(MaxOffset < I.Offset + 1)
                        MaxOffset	= I.Offset + 1;
                    break;

                case "p":
                    char[] Splitter	= {' ','\n'};
                    string[] V	= Child.InnerText.Split(Splitter,StringSplitOptions.RemoveEmptyEntries);

                    P	= new uint[MaxOffset,V.Length / MaxOffset];

                    int i	= 0;
                    while(i < MaxOffset)
                    {
                        int  j	= 0;
                        while(j < P.GetLength(1))
                        {
                            P[i,j]	= uint.Parse(V[i + (j * MaxOffset)]);
                            j++;
                        }

                        i++;
                    }
                    break;

                default:
                    InitChild(Doc,Child);
                    break;
            }
        }
コード例 #28
0
ファイル: source.cs プロジェクト: miquik/leviatan-game
 void IHasTechChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "accessor")
         Accessor	= Doc.Load<accessor>(this,Child);
     else throw new Exception("Invalid Child Node");
 }
コード例 #29
0
        public static List <ModelConverterDataCollada> ReadDAEFile(string FileName)
        {
            COLLADA model = COLLADA.Load(FileName);
            List <ModelConverterDataCollada> DAEObjectList = new List <ModelConverterDataCollada>();

            List <material> ColladaMaterialList = new List <material>();
            List <string[]> EffectList          = new List <string[]>();
            List <image>    ImageList           = new List <image>();

            // Iterate on libraries
            foreach (var item in model.Items)
            {
                if (item is library_images images)
                {
                    if (images == null)
                    {
                        continue;
                    }

                    foreach (image i in images.image)
                    {
                        ImageList.Add(i);
                    }
                    //image.id effects get texture by id
                    //image.name dont know what this does
                    //image.image full image path
                }
                else if (item is library_effects effects)
                {
                    if (effects == null)
                    {
                        continue;
                    }

                    foreach (effect ef in effects.effect)
                    {
                        string[] TempEffect = new string[2];

                        TempEffect[0] = ef.id;

                        foreach (effectFx_profile_abstractProfile_COMMON prof in ef.Items)
                        {
                            try
                            {
                                TempEffect[1] = ((common_color_or_texture_typeTexture)((effectFx_profile_abstractProfile_COMMONTechniquePhong)prof.technique.Item).diffuse.Item).texture;

                                EffectList.Add(TempEffect);//name of effect, id of texture
                            }
                            catch { }
                        }
                    }
                }
                else if (item is library_materials materials)
                {
                    if (materials == null)
                    {
                        continue;
                    }

                    // Iterate on materials in library_materials
                    foreach (var mat in materials.material)
                    {
                        ColladaMaterialList.Add(mat);
                    }
                }
                else if (item is library_geometries geometries)
                {
                    if (geometries == null)
                    {
                        continue;
                    }

                    foreach (geometry geom in geometries.geometry)
                    {
                        var mesh = geom.Item as mesh;
                        if (mesh == null)
                        {
                            continue;
                        }

                        ModelConverterDataCollada TempObject = new ModelConverterDataCollada
                        {
                            ObjectName = geom.id.Split('-').FirstOrDefault()
                        };

                        // Dump source[] for geom
                        foreach (source source in mesh.source)
                        {
                            var float_array = source.Item as float_array;
                            if (float_array == null)
                            {
                                continue;
                            }

                            if (source.id.ToLower().Contains("position"))
                            {
                                List <float> Vpos = new List <float>();
                                foreach (var mesh_source_value in float_array.Values)
                                {
                                    Vpos.Add((float)mesh_source_value);
                                    if (Vpos.Count == 3)
                                    {
                                        TempObject.PositionVertexList.Add(new Vector3(Vpos[0], Vpos[1], Vpos[2]));
                                        Vpos.Clear();
                                    }
                                }
                            }
                            else if (source.id.ToLower().Contains("normal"))
                            {
                                List <float> Vpos = new List <float>();
                                foreach (var mesh_source_value in float_array.Values)
                                {
                                    Vpos.Add((float)mesh_source_value);
                                    if (Vpos.Count == 3)
                                    {
                                        TempObject.NormalList.Add(new Vector3(Vpos[0], Vpos[1], Vpos[2]));
                                        Vpos.Clear();
                                    }
                                }
                            }
                            else if (source.id.ToLower().Contains("uv"))
                            {
                                List <float> Vpos = new List <float>();
                                foreach (var mesh_source_value in float_array.Values)
                                {
                                    Vpos.Add((float)mesh_source_value);
                                    if (Vpos.Count == 2)
                                    {
                                        TempObject.TexCoordList.Add(new Vector2(Vpos[0], Vpos[1]));
                                        Vpos.Clear();
                                    }
                                }
                            }
                            else if (source.id.ToLower().Contains("color"))
                            {
                                List <float> Vpos = new List <float>();
                                foreach (var mesh_source_value in float_array.Values)
                                {
                                    Vpos.Add((float)mesh_source_value);
                                    if (Vpos.Count == 4)
                                    {
                                        TempObject.VColorList.Add(new Color(Vpos[0], Vpos[1], Vpos[2], Vpos[3]));
                                        Vpos.Clear();
                                    }
                                }
                            }
                        }

                        foreach (var meshItem in mesh.Items)
                        {
                            if (meshItem is triangles triangles)
                            {
                                TriangleListCollada tl = new TriangleListCollada();

                                List <string> TriangleData = triangles.p.Split().ToList();
                                TriangleData.Remove("");

                                if (TempObject.VColorList.Count != 0)
                                {
                                    for (int i = 0; i < TriangleData.Count(); i += 12)
                                    {
                                        Triangle t = new Triangle
                                        {
                                            vertex1  = Convert.ToInt32(TriangleData[i]),
                                            normal1  = Convert.ToInt32(TriangleData[i + 1]),
                                            UVCoord1 = Convert.ToInt32(TriangleData[i + 2]),
                                            Color1   = Convert.ToInt32(TriangleData[i + 3]),
                                            vertex2  = Convert.ToInt32(TriangleData[i + 4]),
                                            normal2  = Convert.ToInt32(TriangleData[i + 5]),
                                            UVCoord2 = Convert.ToInt32(TriangleData[i + 6]),
                                            Color2   = Convert.ToInt32(TriangleData[i + 7]),
                                            vertex3  = Convert.ToInt32(TriangleData[i + 8]),
                                            normal3  = Convert.ToInt32(TriangleData[i + 9]),
                                            UVCoord3 = Convert.ToInt32(TriangleData[i + 10]),
                                            Color3   = Convert.ToInt32(TriangleData[i + 11])
                                        };

                                        tl.TriangleList.Add(t);
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < TriangleData.Count(); i += 9)
                                    {
                                        Triangle t = new Triangle
                                        {
                                            vertex1  = Convert.ToInt32(TriangleData[i]),
                                            normal1  = Convert.ToInt32(TriangleData[i + 1]),
                                            UVCoord1 = Convert.ToInt32(TriangleData[i + 2]),
                                            vertex2  = Convert.ToInt32(TriangleData[i + 3]),
                                            normal2  = Convert.ToInt32(TriangleData[i + 4]),
                                            UVCoord2 = Convert.ToInt32(TriangleData[i + 5]),
                                            vertex3  = Convert.ToInt32(TriangleData[i + 6]),
                                            normal3  = Convert.ToInt32(TriangleData[i + 7]),
                                            UVCoord3 = Convert.ToInt32(TriangleData[i + 8]),
                                        };

                                        tl.TriangleList.Add(t);
                                    }
                                }

                                for (int i = 0; i < ColladaMaterialList.Count(); i++)
                                {
                                    if (ColladaMaterialList[i].id == triangles.material)
                                    {
                                        for (int j = 0; j < EffectList.Count; j++)
                                        {
                                            if (EffectList[j][0] == ColladaMaterialList[i].instance_effect.url.Substring(1))
                                            {
                                                for (int k = 0; k < ImageList.Count(); k++)
                                                {
                                                    if (ImageList[k].id == EffectList[j][1])
                                                    {
                                                        tl.TextureName = Path.GetFileNameWithoutExtension((string)ImageList[k].Item);
                                                        //if (!MaterialStream.Contains(tl.TextureName))
                                                        //MaterialStream.Add(tl.TextureName);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                if (TempObject.VColorList.Count == 0)
                                {
                                    TempObject.VColorList.Add(Color.White);
                                }

                                TempObject.TriangleListList.Add(tl);
                            }
                        }

                        DAEObjectList.Add(TempObject);
                    }
                }
                else if (item is library_visual_scenes scene)
                {
                    if (scene == null)
                    {
                        continue;
                    }

                    foreach (visual_scene vscene in scene.visual_scene)
                    {
                        foreach (node vscene_node in vscene.node)
                        {
                            foreach (var tm in vscene_node.Items)
                            {
                                if (tm is matrix)
                                {
                                    for (int j = 0; j < DAEObjectList.Count; j++)
                                    {
                                        if (DAEObjectList[j].ObjectName == vscene_node.sid)
                                        {
                                            DAEObjectList[j].GetMatrix((matrix)tm);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(DAEObjectList);
        }
コード例 #30
0
 public static STGenericScene Read(string fileName, DAE.ImportSettings settings = null)
 {
     return(Read(COLLADA.Load(fileName), settings));
 }
コード例 #31
0
ファイル: DAE.cs プロジェクト: jakeroo123/Switch-Toolbox
        public bool LoadFile(string FileName)
        {
            GlobalTransform = Matrix4.Identity;

            COLLADA collada = COLLADA.Load(FileName);


            //Check axis up
            if (collada.asset != null)
            {
                switch (collada.asset.up_axis)
                {
                case UpAxisType.X_UP:
                    GlobalTransform = Matrix4.CreateRotationX(90);
                    break;

                case UpAxisType.Y_UP:
                    GlobalTransform = Matrix4.CreateRotationY(90);
                    break;

                case UpAxisType.Z_UP:
                    GlobalTransform = Matrix4.CreateRotationZ(90);
                    break;
                }

                if (collada.asset.unit != null)
                {
                    var amount = collada.asset.unit.meter;
                    var type   = collada.asset.unit.name;
                    if (type == "meter")
                    {
                    }
                    else if (type == "centimeter")
                    {
                    }
                }
            }

            foreach (var item in collada.Items)
            {
                if (item is library_controllers)
                {
                    LoadControllers((library_controllers)item);
                }
                if (item is library_geometries)
                {
                    LoadGeometry((library_geometries)item);
                }
                if (item is library_images)
                {
                    LoadImages((library_images)item);
                }
                if (item is library_controllers)
                {
                    LoadControllers((library_controllers)item);
                }
                if (item is library_nodes)
                {
                    LoadNodes((library_nodes)item);
                }
                if (item is library_visual_scenes)
                {
                    LoadVisualScenes((library_visual_scenes)item);
                }
            }

            return(true);
        }
コード例 #32
0
ファイル: KSPPart.cs プロジェクト: duk3luk3/KSPEdit
        public KSPPartAttrib(TextReader stream)
        {
            int    lineIdx = 0;
            String line;

            Regex r = new Regex(@"((\s)*(?<Key>([^\=^\s^\n]+))[\s^\n] \= (\s)*(?<Value>([^\n^\s]+(\n){0,1})))", RegexOptions.Compiled | RegexOptions.ExplicitCapture);

            List <String[]> extraLines = new List <string[]>();

            while ((line = stream.ReadLine()) != "")
            {
                lineIdx++;

                if (line.Substring(0, 1) == "//")
                {
                    continue;
                }

                var match = r.Match(line);

                var key = match.Groups["Key"].Value;
                var val = match.Groups["Value"].Value;

                switch (key.Trim())
                {
                case "name":
                    name = val;
                    break;

                case "module":
                    if (!Enum.TryParse <KSPPartModule>(val, out module))
                    {
                        throw new Exception(String.Format("Module string '{0}' could not be parsed into a module known to this program. (Line {1})", val, lineIdx));
                    }
                    break;

                case "author":
                    author = val;
                    break;

                case "mesh":
                    mesh = COLLADA.Load(val);
                    break;

                case "scale":
                    try
                    {
                        scale = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("scale string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "texture":
                    texture = val;
                    break;

                case "specPower":
                    try
                    {
                        specPower = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("specPower string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "rimFalloff":
                    try
                    {
                        rimFalloff = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("rimFalloff string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "alphaCutoff":
                    try
                    {
                        alphaCutoff = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("alphaCutoff string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "iconCenter":
                    var comps = val.Split(',');
                    try
                    {
                        double x = Double.Parse(comps[0].Trim());
                        double y = Double.Parse(comps[1].Trim());
                        double z = Double.Parse(comps[2].Trim());

                        iconCenter = new Point3()
                        {
                            x = x, y = y, z = z
                        };
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("iconCenter string '{0}' could not be parsed into doubles. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "cost":
                    try
                    {
                        cost = Int32.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("cost string '{0}' could not be parsed into Int32. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "category":
                    try
                    {
                        category = Int32.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("category string '{0}' could not be parsed into Int32. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "subcategory":
                    try
                    {
                        subcategory = Int32.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("subcategory string '{0}' could not be parsed into Int32. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "title":
                    title = val;
                    break;

                case "manufacturer":
                    manufacturer = val;
                    break;

                case "description":
                    description = val;
                    break;

                case "attachRules":
                    try
                    {
                        comps = val.Split(',');

                        attachmentStack          = (comps[0].Trim() == "1");
                        attachmentSurf           = (comps[1].Trim() == "1");
                        attachmentAllowStack     = (comps[2].Trim() == "1");
                        attachmentAllowSurf      = (comps[3].Trim() == "1");
                        attachmentAllowCollision = (comps[4].Trim() == "1");
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("attachRules string '{0}' could not be parsed into valid attachment rules. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "mass":
                    try
                    {
                        mass = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("mass string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "dragModelType":
                    dragModelType = val;
                    break;

                case "maximum_drag":
                    try
                    {
                        maximum_drag = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("maximum_drag string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "minimum_drag":
                    try
                    {
                        minimum_drag = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("minimum_drag string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "angularDrag ":
                    try
                    {
                        angularDrag = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("angularDrag string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "crashTolerance":
                    try
                    {
                        crashTolerance = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("crashTolerance string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                case "maxTemp":
                    try
                    {
                        maxTemp = Double.Parse(val.Trim());
                    }
                    catch (Exception e)
                    {
                        throw new Exception(String.Format("maxTemp string '{0}' could not be parsed into a double value. (Line {1})", val, lineIdx), e);
                    }
                    break;

                default:
                    if (val.Substring(0, 4) == "node")
                    {
                        try{
                            comps = val.Split(',');

                            double x = Double.Parse(comps[0].Trim());
                            double y = Double.Parse(comps[1].Trim());
                            double z = Double.Parse(comps[2].Trim());

                            double vx = Double.Parse(comps[3].Trim());
                            double vy = Double.Parse(comps[4].Trim());
                            double vz = Double.Parse(comps[5].Trim());

                            nodeDefinitions.Add(new KSPAttribNodeDefinition()
                            {
                                Name = key, Position = new Point3()
                                {
                                    x = x, y = y, z = z
                                }, UpVector = new Point3()
                                {
                                    x = vx, y = vy, z = vz
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            throw new Exception(String.Format("node string '{0}' ({2}) could not be parsed into doubles. (Line {1})", val, lineIdx, key), e);
                        }
                    }
                    else if (val.Trim() != "")
                    {
                        extraLines.Add(new string[] { key, val });
                    }
                    break;
                }
            }
            switch (module)
            {
            case KSPPartModule.AdvSASModule:
                break;

            case KSPPartModule.FuelLine:
                break;

            case KSPPartModule.FuelTank:
                break;

            case KSPPartModule.LiquidEngine:
                break;

            case KSPPartModule.CommandPod:
                break;

            case KSPPartModule.Parachutes:
                break;

            case KSPPartModule.RadialDecoupler:
                break;

            case KSPPartModule.RCSModule:
                break;

            case KSPPartModule.RCSFuelTank:
                break;

            case KSPPartModule.SASModule:
                break;

            case KSPPartModule.SolidRocket:
                break;

            case KSPPartModule.Decoupler:
                break;

            case KSPPartModule.Strut:
                break;

            case KSPPartModule.StrutConnector:
                break;

            case KSPPartModule.Winglet:
                break;

            case KSPPartModule.ControlSurface:
                break;

            default:
                throw new Exception(String.Format("No specific part parser for module '{0}'. Well, that's awkward. (We're in KSPEdit.Model.KSPPartAttrib btw, if you feel like reporting this)", module.ToString()));
                break;
            }
        }
コード例 #33
0
ファイル: material.cs プロジェクト: miquik/leviatan-game
 void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "instance_effect")
         Effect	= Doc.Load<instance_effect>(this,Child);
     else throw new Exception("Invalid Child Node");
 }
コード例 #34
0
ファイル: Root.cs プロジェクト: xenogenesi/lslib
        public void ImportFromCollada(string inputPath)
        {
            var collada = COLLADA.Load(inputPath);

            ImportArtToolInfo(collada);
            ImportExporterInfo(collada);
            FromFileName = inputPath;

            Skeletons     = new List <Skeleton>();
            VertexDatas   = new List <VertexData>();
            TriTopologies = new List <TriTopology>();
            Meshes        = new List <Mesh>();
            Models        = new List <Model>();
            TrackGroups   = new List <TrackGroup>();
            Animations    = new List <Animation>();

            ColladaGeometries = new Dictionary <string, Mesh>();
            SkinnedMeshes     = new HashSet <string>();

            var collGeometries = new List <geometry>();
            var collSkins      = new List <skin>();
            var collAnimations = new List <animation>();
            var rootBones      = new List <node>();

            // Import skinning controllers after skeleton and geometry loading has finished, as
            // we reference both of them during skin import
            foreach (var item in collada.Items)
            {
                if (item is library_controllers)
                {
                    var controllers = item as library_controllers;
                    if (controllers.controller != null)
                    {
                        foreach (var controller in controllers.controller)
                        {
                            if (controller.Item is skin)
                            {
                                collSkins.Add(controller.Item as skin);
                                SkinnedMeshes.Add((controller.Item as skin).source1.Substring(1));
                            }
                            else
                            {
                                Utils.Warn(String.Format("Controller {0} is unsupported and will be ignored", controller.Item.GetType().Name));
                            }
                        }
                    }
                }
                else if (item is library_visual_scenes)
                {
                    var scenes = item as library_visual_scenes;
                    if (scenes.visual_scene != null)
                    {
                        foreach (var scene in scenes.visual_scene)
                        {
                            foreach (var node in scene.node)
                            {
                                FindRootBones(null, node, rootBones);
                            }
                        }
                    }
                }
                else if (item is library_geometries)
                {
                    var geometries = item as library_geometries;
                    if (geometries.geometry != null)
                    {
                        foreach (var geometry in geometries.geometry)
                        {
                            if (geometry.Item is mesh)
                            {
                                collGeometries.Add(geometry);
                            }
                            else
                            {
                                Utils.Warn(String.Format("Geometry type {0} is unsupported and will be ignored", geometry.Item.GetType().Name));
                            }
                        }
                    }
                }
                else if (item is library_animations)
                {
                    var animations = item as library_animations;
                    if (animations.animation != null)
                    {
                        collAnimations.AddRange(animations.animation);
                    }
                }
                else
                {
                    Utils.Warn(String.Format("Library {0} is unsupported and will be ignored", item.GetType().Name));
                }
            }

            foreach (var bone in rootBones)
            {
                var skeleton = Skeleton.FromCollada(bone);
                Skeletons.Add(skeleton);
            }

            foreach (var geometry in collGeometries)
            {
                var mesh = ImportMesh(geometry.name, geometry.Item as mesh, FindVertexFormat(geometry));
                ColladaGeometries.Add(geometry.id, mesh);
            }

            // Import skinning controllers after skeleton and geometry loading has finished, as
            // we reference both of them during skin import
            foreach (var skin in collSkins)
            {
                ImportSkin(skin);
            }

            if (collAnimations.Count > 0)
            {
                ImportAnimations(collAnimations);
            }

            var rootModel = new Model();

            rootModel.Name = "Unnamed"; // TODO
            if (Skeletons.Count > 0)
            {
                rootModel.Skeleton = Skeletons[0];
                rootModel.Name     = rootModel.Skeleton.Bones[0].Name;
            }
            rootModel.InitialPlacement = new Transform();
            rootModel.MeshBindings     = new List <MeshBinding>();
            foreach (var mesh in Meshes)
            {
                var binding = new MeshBinding();
                binding.Mesh = mesh;
                rootModel.MeshBindings.Add(binding);
            }

            Models.Add(rootModel);
            // TODO: make this an option!
            if (Skeletons.Count > 0)
            {
                Skeletons[0].UpdateInverseWorldTransforms();
            }
            PostLoad();
        }
コード例 #35
0
        public Root Import(string inputPath)
        {
            var collada = COLLADA.Load(inputPath);
            var root    = new Root();

            root.ArtToolInfo = ImportArtToolInfo(collada);
            if (!Options.StripMetadata)
            {
                root.ExporterInfo = ImportExporterInfo(collada);
            }

            root.FromFileName = inputPath;

            root.Skeletons     = new List <Skeleton>();
            root.VertexDatas   = new List <VertexData>();
            root.TriTopologies = new List <TriTopology>();
            root.Meshes        = new List <Mesh>();
            root.Models        = new List <Model>();
            root.TrackGroups   = new List <TrackGroup>();
            root.Animations    = new List <Animation>();

            ColladaGeometries = new Dictionary <string, Mesh>();
            SkinnedMeshes     = new HashSet <string>();

            var collGeometries = new List <geometry>();
            var collSkins      = new List <skin>();
            var collAnimations = new List <animation>();
            var rootBones      = new List <RootBoneInfo>();

            // Import skinning controllers after skeleton and geometry loading has finished, as
            // we reference both of them during skin import
            foreach (var item in collada.Items)
            {
                if (item is library_controllers)
                {
                    var controllers = item as library_controllers;
                    if (controllers.controller != null)
                    {
                        foreach (var controller in controllers.controller)
                        {
                            if (controller.Item is skin)
                            {
                                collSkins.Add(controller.Item as skin);
                                SkinnedMeshes.Add((controller.Item as skin).source1.Substring(1));
                            }
                            else
                            {
                                Utils.Warn(String.Format("Controller {0} is unsupported and will be ignored", controller.Item.GetType().Name));
                            }
                        }
                    }
                }
                else if (item is library_visual_scenes)
                {
                    var scenes = item as library_visual_scenes;
                    if (scenes.visual_scene != null)
                    {
                        foreach (var scene in scenes.visual_scene)
                        {
                            if (scene.node != null)
                            {
                                foreach (var node in scene.node)
                                {
                                    FindRootBones(new List <node>(), node, rootBones);
                                }
                            }
                        }
                    }
                }
                else if (item is library_geometries)
                {
                    var geometries = item as library_geometries;
                    if (geometries.geometry != null)
                    {
                        foreach (var geometry in geometries.geometry)
                        {
                            if (geometry.Item is mesh)
                            {
                                collGeometries.Add(geometry);
                            }
                            else
                            {
                                Utils.Warn(String.Format("Geometry type {0} is unsupported and will be ignored", geometry.Item.GetType().Name));
                            }
                        }
                    }
                }
                else if (item is library_animations)
                {
                    var animations = item as library_animations;
                    if (animations.animation != null)
                    {
                        collAnimations.AddRange(animations.animation);
                    }
                }
                else
                {
                    Utils.Warn(String.Format("Library {0} is unsupported and will be ignored", item.GetType().Name));
                }
            }

            foreach (var bone in rootBones)
            {
                var skeleton      = Skeleton.FromCollada(bone.Bone);
                var rootTransform = NodeHelpers.GetTransformHierarchy(bone.Parents);
                skeleton.TransformRoots(rootTransform.Inverted());
                root.Skeletons.Add(skeleton);
            }

            foreach (var geometry in collGeometries)
            {
                VertexDescriptor vertexFormat = null;
                // Use the override vertex format, if one was specified
                Options.VertexFormats.TryGetValue(geometry.name, out vertexFormat);
                var mesh = ImportMesh(root, geometry.name, geometry, geometry.Item as mesh, vertexFormat);
                ColladaGeometries.Add(geometry.id, mesh);
            }

            // Import skinning controllers after skeleton and geometry loading has finished, as
            // we reference both of them during skin import
            if (rootBones.Count > 0)
            {
                foreach (var skin in collSkins)
                {
                    ImportSkin(root, skin);
                }
            }

            if (collAnimations.Count > 0)
            {
                ImportAnimations(collAnimations, root, root.Skeletons.FirstOrDefault());
            }

            var rootModel = new Model();

            rootModel.Name = "Unnamed"; // TODO
            if (root.Skeletons.Count > 0)
            {
                rootModel.Skeleton = root.Skeletons[0];
                rootModel.Name     = rootModel.Skeleton.Bones[0].Name;
            }
            rootModel.InitialPlacement = new Transform();
            rootModel.MeshBindings     = new List <MeshBinding>();
            foreach (var mesh in root.Meshes)
            {
                var binding = new MeshBinding();
                binding.Mesh = mesh;
                rootModel.MeshBindings.Add(binding);
            }

            root.Models.Add(rootModel);
            // TODO: make this an option!
            if (root.Skeletons.Count > 0)
            {
                root.Skeletons[0].UpdateWorldTransforms();
            }
            root.ZUp = ZUp;
            root.PostLoad(GR2.Header.DefaultTag);

            this.UpdateUserDefinedProperties(root);

            return(root);
        }
コード例 #36
0
 public static STGenericScene Read(System.IO.Stream stream, DAE.ImportSettings settings = null)
 {
     return(Read(COLLADA.Load(stream), settings));
 }
コード例 #37
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (!File.Exists(sFileName))
            {
                MessageBox.Show("Unable to access " + sFileName + "!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            bool   rep        = false;
            int    offsets    = 0;
            string trisall    = "";
            string vertstring = "";

            string[] vertexids        = { };
            string   normalsid        = "";
            string   normalsstring    = "";
            string   texcoordid       = "";
            string   texcoordstring   = "";
            int      textriarraycount = 0;
            int      textricount      = 0;

            int[] textriarray = new int[File.ReadAllLines("settings.bmfo")[2].Split().Length];
            int[,] tris = new int[0, 0];
            int vertexoffset   = 0;
            int texcoordoffset = 0;
            int normaloffset   = 0;
            int coloroffset    = 0;

            float[,] bind_float_matrix = new float[0, 0];
            byte[,] output             = new byte[0, 0];
            COLLADA model = COLLADA.Load(sFileName);

            foreach (var item in model.Items)
            {
                var geometries = item as library_geometries;
                if (geometries == null)
                {
                    continue;
                }
                foreach (var geom in geometries.geometry)
                {
                    var mesh = geom.Item as mesh;
                    if (mesh == null)
                    {
                        continue;
                    }
                    if (1 != 0)
                    {
                        var meshItem        = mesh.vertices;
                        var vertices        = meshItem as vertices;
                        var inputs          = vertices.input;
                        int vertexidnumbers = inputs.Length;
                        vertexids       = new string[vertexidnumbers];
                        vertexidnumbers = 0;
                        foreach (var input in inputs)
                        {
                            vertexids[vertexidnumbers] = input.source;
                        }
                        vertexidnumbers++;
                    }
                    foreach (var meshItem in mesh.Items)
                    {
                        try
                        {
                            textriarray[textriarraycount] = textricount / 3;
                        }
                        catch
                        {
                            break;
                        }
                        textriarraycount++;
                        var triangles = meshItem as polylist;
                        var inputs    = triangles.input;
                        offsets = 0;
                        foreach (var input in inputs)
                        {
                            if (input.semantic == "VERTEX")
                            {
                                vertexoffset = offsets;
                            }
                            else if (input.semantic == "TEXCOORD")
                            {
                                texcoordid     = input.source;
                                texcoordoffset = offsets;
                            }
                            else if (input.semantic == "NORMAL")
                            {
                                normalsid    = input.source;
                                normaloffset = offsets;
                            }

                            offsets++;
                        }
                        trisall = trisall + triangles.p + " ";
                        foreach (var hmmm in triangles.p.Split())
                        {
                            textricount++;
                        }
                    }
                    foreach (var source in mesh.source)
                    {
                        foreach (var vertexid in vertexids)
                        {
                            if (vertexid == "#" + source.id)
                            {
                                var verts = source.Item as float_array;
                                foreach (var vert in verts.Values)
                                {
                                    vertstring = vertstring + vert + " ";
                                }
                            }
                        }
                        if (normalsid == "#" + source.id)
                        {
                            var normalsarray = source.Item as float_array;
                            foreach (var normal in normalsarray.Values)
                            {
                                normalsstring = normalsstring + normal + " ";
                            }
                        }
                        else if (texcoordid == "#" + source.id)
                        {
                            var texcoordsarray = source.Item as float_array;
                            foreach (var texcoord in texcoordsarray.Values)
                            {
                                texcoordstring = texcoordstring + texcoord + " ";
                            }
                        }
                    }
                    foreach (var meshItem in mesh.Items)
                    {
                        if (meshItem is polylist && rep == false)
                        {
                            string   trisold2 = trisall;
                            string[] trisold  = trisold2.Split();
                            tris = new int[offsets, (trisold.Length + 1 / (offsets + 1))];
                            int currenttri   = 0;
                            int currentelem  = 0;
                            int currentelem2 = 0;
                            foreach (string elem in trisold)
                            {
                                if (currentelem == offsets - 1)
                                {
                                    currentelem2++;
                                }
                                if (int.TryParse(elem, out int result))
                                {
                                    tris[currenttri % offsets, currentelem2] = result;
                                    //MessageBox.Show("tris[" + (currenttri%offsets).ToString() + ", " + currentelem2 + "] = " + result.ToString());
                                }
                                currentelem = currenttri % offsets;
                                currenttri++;
                            }
                            rep = true;
                        }
                    }
                }

                var controllers = item as library_controllers;
                if (controllers == null)
                {
                    continue;
                }
                foreach (var control in controllers.controller)
                {
                    string bind_name = "";
                    var    skins     = item as skin;
                    if (skins == null)
                    {
                        continue;
                    }
                    var joints = item as skinJoints;
                    foreach (var joint in joints.input)
                    {
                        if (joint.semantic == "INV_BIND_MATRIX")
                        {
                            bind_name = joint.source;
                        }
                    }
                    foreach (var source in skins.source)
                    {
                        if (bind_name == "#" + source.id)
                        {
                            var bind_poses = source.Item as float_array;
                            bind_float_matrix = new float[16, bind_poses.count / 16];
                            int iter  = 0;
                            int iter2 = 0;
                            foreach (var poses in bind_poses.Values)
                            {
                                bind_float_matrix[iter, iter2] = (float)poses;
                                iter++;
                                if (iter == 16)
                                {
                                    iter2++;
                                    iter = 0;
                                }
                            }
                        }
                    }
                }

                output = new byte[16, bind_float_matrix.GetLength(1)];
                var visual_scenes = item as library_visual_scenes;
                if (visual_scenes == null)
                {
                    continue;
                }
                foreach (var visual_scene in visual_scenes.visual_scene)
                {
                    var nodes = visual_scene.node as node[];
                    if (nodes == null)
                    {
                        continue;
                    }
                    foreach (var node in nodes)
                    {
                        if (node.id == "Armature")
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load(sFileName);
                            XmlNodeList list      = doc.SelectNodes("library_visual_scenes/visual_scene/node[@id=\"Armature\"]");
                            string      nodething = "library_visual_scenes/visual_scene/node";
                            int         nodecount = list.Count;
                            int         iterthing = 0;
                            for (int j = 0; j < nodecount; j++)
                            {
                                XmlNode elem = list[j];
                                if (1 > 0)
                                {
                                    string childid    = elem.Name;
                                    int    countchild = doc.SelectNodes(nodething + "[@name=\"" + childid + "\"]").Count;
                                    byte[] toBytes    = new byte[16];
                                    byte[] toBytes3   = Encoding.ASCII.GetBytes(childid);
                                    int    iter1      = 0;
                                    foreach (byte bytee in toBytes3)
                                    {
                                        toBytes[iter1] = bytee;
                                        iter1++;
                                    }
                                    output[0, iterthing]  = (byte)((countchild >> 8) & 0xff);
                                    output[1, iterthing]  = (byte)(countchild & 0xff);
                                    output[2, iterthing]  = toBytes[0];
                                    output[3, iterthing]  = toBytes[1];
                                    output[4, iterthing]  = toBytes[2];
                                    output[5, iterthing]  = toBytes[3];
                                    output[6, iterthing]  = toBytes[4];
                                    output[7, iterthing]  = toBytes[5];
                                    output[8, iterthing]  = toBytes[6];
                                    output[9, iterthing]  = toBytes[7];
                                    output[10, iterthing] = toBytes[8];
                                    output[11, iterthing] = toBytes[9];
                                    output[12, iterthing] = toBytes[10];
                                    output[13, iterthing] = toBytes[11];
                                    output[14, iterthing] = toBytes[12];
                                    output[15, iterthing] = toBytes[13];
                                    iterthing++;
                                }
                                while (1 > 0)
                                {
                                    nodething = nodething + "/node";
                                    if (doc.SelectNodes(nodething).Count != 0)
                                    {
                                        string childid    = doc.SelectSingleNode(nodething).Name;
                                        int    countchild = doc.SelectNodes(nodething + "[@name=\"" + childid + "\"]").Count;
                                        byte[] toBytes    = new byte[16];
                                        byte[] toBytes3   = Encoding.ASCII.GetBytes(childid);
                                        int    iter1      = 0;
                                        foreach (byte bytee in toBytes3)
                                        {
                                            toBytes[iter1] = bytee;
                                            iter1++;
                                        }
                                        output[0, iterthing]  = (byte)((countchild >> 8) & 0xff);
                                        output[1, iterthing]  = (byte)(countchild & 0xff);
                                        output[2, iterthing]  = toBytes[0];
                                        output[3, iterthing]  = toBytes[1];
                                        output[4, iterthing]  = toBytes[2];
                                        output[5, iterthing]  = toBytes[3];
                                        output[6, iterthing]  = toBytes[4];
                                        output[7, iterthing]  = toBytes[5];
                                        output[8, iterthing]  = toBytes[6];
                                        output[9, iterthing]  = toBytes[7];
                                        output[10, iterthing] = toBytes[8];
                                        output[11, iterthing] = toBytes[9];
                                        output[12, iterthing] = toBytes[10];
                                        output[13, iterthing] = toBytes[11];
                                        output[14, iterthing] = toBytes[12];
                                        output[15, iterthing] = toBytes[13];
                                        iterthing++;
                                    }
                                    else
                                    {
                                        nodething = "library_visual_scenes/visual_scene/node";
                                        string childid  = doc.SelectSingleNode(nodething).Name;
                                        byte[] toBytes  = new byte[16];
                                        byte[] toBytes3 = Encoding.ASCII.GetBytes(childid);
                                        int    iter1    = 0;
                                        foreach (byte bytee in toBytes3)
                                        {
                                            toBytes[iter1] = bytee;
                                            iter1++;
                                        }
                                        output[0, iterthing]  = 0;
                                        output[1, iterthing]  = 0;
                                        output[2, iterthing]  = toBytes[0];
                                        output[3, iterthing]  = toBytes[1];
                                        output[4, iterthing]  = toBytes[2];
                                        output[5, iterthing]  = toBytes[3];
                                        output[6, iterthing]  = toBytes[4];
                                        output[7, iterthing]  = toBytes[5];
                                        output[8, iterthing]  = toBytes[6];
                                        output[9, iterthing]  = toBytes[7];
                                        output[10, iterthing] = toBytes[8];
                                        output[11, iterthing] = toBytes[9];
                                        output[12, iterthing] = toBytes[10];
                                        output[13, iterthing] = toBytes[11];
                                        output[14, iterthing] = toBytes[12];
                                        output[15, iterthing] = toBytes[13];
                                        break;
                                    }
                                }
                                iterthing++;
                            }
                        }
                    }
                }
            }

            int scaling = int.Parse(File.ReadAllLines("settings.bmfo")[4]);

            string[]     vertarray     = vertstring.Split();
            string[]     normalarray   = normalsstring.Split();
            string[]     texcoordarray = texcoordstring.Split();
            MemoryStream BMF           = new MemoryStream();
            int          vertheader    = 0;
            string       FileName      = File.ReadAllLines("settings.bmfo")[1] + "/" + Path.GetFileNameWithoutExtension(sFileName).Replace(' ', '_') + ".bmf";

            using (FileStream fs = File.Create(FileName))
            {
            }
            BMF.Write(new byte[] {
                0x00,
                0x00,
                0x00,
                0x28,
                //adding this if i ever want to change this part
                0x00,
                0x00,
                0x00,
                0x00,
                //(byte)((tricount >> 8) & 0xff),
                //(byte)(tricount & 0xff),
                //(byte)((trioffset >> 8) & 0xff),
                //(byte)(trioffset & 0xff),
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF
            }, 0, 16);
            BMF.Write(new byte[] {
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF
            }, 0, 16);
            BMF.Write(new byte[] {
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF,
                0x00,
                0x00,
                0xFF,
                0xFF
            }, 0, 16);
            BMF.Write(new byte[] {
                0x47,
                0x45,
                0x4E,
                0x45,
                0x52,
                0x41,
                0x54,
                0x45,
                0x44,
                0x00,
                0x42,
                0x59,
                0x00,
                0x00,
                0x00,
                0x00
            }, 0, 16);
            BMF.Write(new byte[] {
                0x44,
                0x41,
                0x45,
                0x32,
                0x42,
                0x4D,
                0x46,
                0x00,
                0x00,
                0x00,
                0x56,
                0x45,
                0x52,
                0x54,
                0x53,
                0x3A
            }, 0, 16);
            int i         = 0;
            int iterb     = 0;
            int iterrerew = 0;

            while (1 < 2)
            {
                //cheap texcord fix
                if (iterrerew < textriarray.Length && iterb == textriarray[iterrerew] / 3)
                {
                    iterrerew++;
                }
                iterb++;

                //vertex1
                int    vtxx1, vtxy1, vtxz1;
                double dvtxx1 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i] * 3]) * scaling);
                if (dvtxx1 > -1)
                {
                    vtxx1 = (int)dvtxx1;
                }
                else
                {
                    vtxx1 = (int)(65535 + dvtxx1);
                }
                double dvtxy1 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i] * 3 + 1]) * scaling);
                if (dvtxy1 > -1)
                {
                    vtxy1 = (int)dvtxy1;
                }
                else
                {
                    vtxy1 = (int)(65535 + dvtxy1);
                }
                double dvtxz1 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i] * 3 + 2]) * scaling);
                if (dvtxz1 > -1)
                {
                    vtxz1 = (int)dvtxz1;
                }
                else
                {
                    vtxz1 = (int)(65535 + dvtxz1);
                }
                //texcoord1
                float tcu11 = float.Parse(texcoordarray[tris[texcoordoffset, i] * 2]);
                short tcu1  = Convert.ToInt16(tcu11 * (xy[iterrerew - 1] >> 16) * 32);
                float tcv11 = float.Parse(texcoordarray[tris[texcoordoffset, i] * 2 + 1]);
                short tcv1  = Convert.ToInt16(tcv11 * (xy[iterrerew - 1] & 0xFFFF) * 32);
                //normals1
                double dn11 = Math.Round(float.Parse(normalarray[tris[normaloffset, i] * 3]) * 127);
                double dn21 = Math.Round(float.Parse(normalarray[tris[normaloffset, i] * 3 + 1]) * 127);
                double dn31 = Math.Round(float.Parse(normalarray[tris[normaloffset, i] * 3 + 2]) * 127);


                //vertex2
                int    vtxx2, vtxy2, vtxz2;
                double dvtxx2 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 1] * 3]) * scaling);
                if (dvtxx2 > -1)
                {
                    vtxx2 = (int)dvtxx2;
                }
                else
                {
                    vtxx2 = (int)(65535 + dvtxx2);
                }
                double dvtxy2 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 1] * 3 + 1]) * scaling);
                if (dvtxy2 > -1)
                {
                    vtxy2 = (int)dvtxy2;
                }
                else
                {
                    vtxy2 = (int)(65535 + dvtxy2);
                }
                double dvtxz2 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 1] * 3 + 2]) * scaling);
                if (dvtxz2 > -1)
                {
                    vtxz2 = (int)dvtxz2;
                }
                else
                {
                    vtxz2 = (int)(65535 + dvtxz2);
                }
                //texcoord2
                float tcu12 = float.Parse(texcoordarray[tris[texcoordoffset, i + 1] * 2]);
                short tcu2  = Convert.ToInt16(tcu12 * (xy[iterrerew - 1] >> 16) * 32);
                float tcv12 = float.Parse(texcoordarray[tris[texcoordoffset, i + 1] * 2 + 1]);
                short tcv2  = Convert.ToInt16(tcv12 * (xy[iterrerew - 1] & 0xFFFF) * 32);
                //normals2
                double dn12 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 1] * 3]) * 127);
                double dn22 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 1] * 3 + 1]) * 127);
                double dn32 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 1] * 3 + 2]) * 127);


                //vertex3
                int    vtxx3, vtxy3, vtxz3;
                double dvtxx3 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 2] * 3]) * scaling);
                if (dvtxx3 > -1)
                {
                    vtxx3 = (int)dvtxx3;
                }
                else
                {
                    vtxx3 = (int)(65535 + dvtxx3);
                }
                double dvtxy3 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 2] * 3 + 1]) * scaling);
                if (dvtxy3 > -1)
                {
                    vtxy3 = (int)dvtxy3;
                }
                else
                {
                    vtxy3 = (int)(65535 + dvtxy3);
                }
                double dvtxz3 = Math.Round(float.Parse(vertarray[tris[vertexoffset, i + 2] * 3 + 2]) * scaling);
                if (dvtxz2 > -1)
                {
                    vtxz3 = (int)dvtxz3;
                }
                else
                {
                    vtxz3 = (int)(65535 + dvtxz3);
                }
                //texcoord2
                float tcu13 = float.Parse(texcoordarray[tris[texcoordoffset, i + 2] * 2]);
                short tcu3  = Convert.ToInt16(tcu13 * (xy[iterrerew - 1] >> 16) * 32);
                float tcv13 = float.Parse(texcoordarray[tris[texcoordoffset, i + 2] * 2 + 1]);
                short tcv3  = Convert.ToInt16(tcv13 * (xy[iterrerew - 1] & 0xFFFF) * 32);
                //normals2
                double dn13 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 2] * 3]) * 127);
                double dn23 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 2] * 3 + 1]) * 127);
                double dn33 = Math.Round(float.Parse(normalarray[tris[normaloffset, i + 2] * 3 + 2]) * 127);



                byte[] vert1 =
                {
                    (byte)((vtxx1 >> 8) & 0xff),
                    (byte)(vtxx1 & 0xff),
                    (byte)((vtxy1 >> 8) & 0xff),
                    (byte)(vtxy1 & 0xff),
                    (byte)((vtxz1 >> 8) & 0xff),
                    (byte)(vtxz1 & 0xff),
                    0x00,
                    0x00,
                    (byte)((tcu1 >> 8) & 0xff),
                    (byte)(tcu1 & 0xff),
                    (byte)((tcv1 >> 8) & 0xff),
                    (byte)(tcv1 & 0xff),
                    (byte)dn11,
                    (byte)dn21,
                    (byte)dn31,
                    0xFF
                };

                byte[] vert2 =
                {
                    (byte)((vtxx2 >> 8) & 0xff),
                    (byte)(vtxx2 & 0xff),
                    (byte)((vtxy2 >> 8) & 0xff),
                    (byte)(vtxy2 & 0xff),
                    (byte)((vtxz2 >> 8) & 0xff),
                    (byte)(vtxz2 & 0xff),
                    0x00,
                    0x00,
                    (byte)((tcu2 >> 8) & 0xff),
                    (byte)(tcu2 & 0xff),
                    (byte)((tcv2 >> 8) & 0xff),
                    (byte)(tcv2 & 0xff),
                    (byte)dn12,
                    (byte)dn22,
                    (byte)dn32,
                    0xFF
                };

                byte[] vert3 =
                {
                    (byte)((vtxx3 >> 8) & 0xff),
                    (byte)(vtxx3 & 0xff),
                    (byte)((vtxy3 >> 8) & 0xff),
                    (byte)(vtxy3 & 0xff),
                    (byte)((vtxz3 >> 8) & 0xff),
                    (byte)(vtxz3 & 0xff),
                    0x00,
                    0x00,
                    (byte)((tcu3 >> 8) & 0xff),
                    (byte)(tcu3 & 0xff),
                    (byte)((tcv3 >> 8) & 0xff),
                    (byte)(tcv3 & 0xff),
                    (byte)dn13,
                    (byte)dn23,
                    (byte)dn33,
                    0xFF
                };
                if (Enumerable.SequenceEqual(vert1, vert2) && Enumerable.SequenceEqual(vert2, vert3))
                {
                }
                else
                {
                    BMF.Write(new byte[] {
                        //vert1
                        (byte)((vtxx1 >> 8) & 0xff),
                        (byte)(vtxx1 & 0xff),
                        (byte)((vtxy1 >> 8) & 0xff),
                        (byte)(vtxy1 & 0xff),
                        (byte)((vtxz1 >> 8) & 0xff),
                        (byte)(vtxz1 & 0xff),
                        0x00,
                        0x00,
                        (byte)((tcu1 >> 8) & 0xff),
                        (byte)(tcu1 & 0xff),
                        (byte)((tcv1 >> 8) & 0xff),
                        (byte)(tcv1 & 0xff),
                        (byte)dn11,
                        (byte)dn21,
                        (byte)dn31,
                        0xFF,

                        //vert2
                        (byte)((vtxx2 >> 8) & 0xff),
                        (byte)(vtxx2 & 0xff),
                        (byte)((vtxy2 >> 8) & 0xff),
                        (byte)(vtxy2 & 0xff),
                        (byte)((vtxz2 >> 8) & 0xff),
                        (byte)(vtxz2 & 0xff),
                        0x00,
                        0x00,
                        (byte)((tcu2 >> 8) & 0xff),
                        (byte)(tcu2 & 0xff),
                        (byte)((tcv2 >> 8) & 0xff),
                        (byte)(tcv2 & 0xff),
                        (byte)dn12,
                        (byte)dn22,
                        (byte)dn32,
                        0xFF,

                        //vert3
                        (byte)((vtxx3 >> 8) & 0xff),
                        (byte)(vtxx3 & 0xff),
                        (byte)((vtxy3 >> 8) & 0xff),
                        (byte)(vtxy3 & 0xff),
                        (byte)((vtxz3 >> 8) & 0xff),
                        (byte)(vtxz3 & 0xff),
                        0x00,
                        0x00,
                        (byte)((tcu3 >> 8) & 0xff),
                        (byte)(tcu3 & 0xff),
                        (byte)((tcv3 >> 8) & 0xff),
                        (byte)(tcv3 & 0xff),
                        (byte)dn13,
                        (byte)dn23,
                        (byte)dn33,
                        0xFF
                    }, 0, 48);
                    vertheader++;
                }
                i += 3;
                if (i >= tris.GetLength(1) - 2)
                {
                    break;
                }
            }
            if (File.ReadAllLines("settings.bmfo")[5] == "YES")
            {
            }
            if (File.ReadAllLines("settings.bmfo")[2] != "")
            {
                string[] textures     = File.ReadAllLines("settings.bmfo")[2].Split();
                int      iterationals = 0;
                foreach (string texture in textures)
                {
                    byte[] toBytes  = new byte[16];
                    byte[] toBytes3 = Encoding.ASCII.GetBytes(Path.GetFileNameWithoutExtension(texture));
                    int    iter1    = 0;
                    foreach (byte bytee in toBytes3)
                    {
                        toBytes[iter1] = bytee;
                        iter1++;
                    }
                    BMF.Write(new byte[] {
                        (byte)((textriarray[iterationals] / 3 >> 8) & 0xff),
                        (byte)(textriarray[iterationals] / 3 & 0xff),
                        toBytes[0],
                        toBytes[1],
                        toBytes[2],
                        toBytes[3],
                        toBytes[4],
                        toBytes[5],
                        toBytes[6],
                        toBytes[7],
                        toBytes[8],
                        toBytes[9],
                        toBytes[0xa],
                        toBytes[0xb],
                        toBytes[0xc],
                        toBytes[0xd]
                    }, 0, 16);
                    iterationals++;
                }
                byte[] toBytes1 = new byte[16];
                byte[] toBytes4 = Encoding.ASCII.GetBytes("texturedUnlit");
                int    iter2    = 0;
                foreach (byte bytee in toBytes4)
                {
                    toBytes1[iter2] = bytee;
                    iter2++;
                }
                BMF.Write(new byte[] {
                    0x00,
                    0x00,
                    toBytes1[0],
                    toBytes1[1],
                    toBytes1[2],
                    toBytes1[3],
                    toBytes1[4],
                    toBytes1[5],
                    toBytes1[6],
                    toBytes1[7],
                    toBytes1[8],
                    toBytes1[9],
                    toBytes1[0xa],
                    toBytes1[0xb],
                    toBytes1[0xc],
                    0x00
                }, 0, 16);
            }
            //write triangles

            /*
             *
             * gotta remember re adding this code generator as an option later on
             *
             * BMF.Write(new byte[] {
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x00,
             *  0x54,
             *  0x52,
             *  0x49,
             *  0x53,
             *  0x3A
             * }, 0, 16);
             * if (texcoords == true)
             * {
             *  float[] tridata = new float[tricount/2];
             *  int valz = 0;
             *  foreach(float td in tridata)
             *  {
             *      BMF.Write(new byte[] {
             *              (byte)((valz >> 8) & 0xff),
             *              (byte)(valz & 0xff),
             *              (byte)((valz + 1 >> 8) & 0xff),
             *              (byte)(valz + 1 & 0xff),
             *              (byte)((valz + 2 >> 8) & 0xff),
             *              (byte)(valz + 2 & 0xff),
             *              0x00,
             *              0x00,
             *              (byte)((valz + 3 >> 8) & 0xff),
             *              (byte)(valz + 3 & 0xff),
             *              (byte)((valz + 4 >> 8) & 0xff),
             *              (byte)(valz + 4 & 0xff),
             *              (byte)((valz + 5 >> 8) & 0xff),
             *              (byte)(valz + 5 & 0xff),
             *              0x00,
             *              0x00
             * }, 0, 16);
             *      valz += 6;
             *  }
             * }*/
            for (int j = 0; j < output.GetLength(1); j++)
            {
                BMF.Write(new byte[] {
                    output[0, j],
                    output[1, j],
                    output[2, j],
                    output[3, j],
                    output[4, j],
                    output[5, j],
                    output[6, j],
                    output[7, j],
                    output[8, j],
                    output[9, j],
                    output[10, j],
                    output[11, j],
                    output[12, j],
                    output[13, j],
                    output[14, j],
                    output[15, j],
                }, 0, 16);
            }

            FileStream bmffile = new FileStream(FileName, FileMode.Open);

            BMF.WriteTo(bmffile);
            bmffile.Dispose();
            //fix verts (temp)
            vertheader = vertheader * 3;
            byte[] array = File.ReadAllBytes(FileName);
            array[0] = (byte)((vertheader >> 8) & 0xff);
            array[1] = (byte)(vertheader & 0xff);
            File.WriteAllBytes(FileName, array);
        }
コード例 #38
0
 void IHasChildNode.InitChildNode(COLLADA Doc,XmlNode Child)
 {
     if(Child.Name == "source")
         Source	= Doc.Load<source>(this,Child);
     else InitChild(Doc,Child);
 }
コード例 #39
0
        public static STGenericScene Read(string fileName, DAE.ImportSettings settings = null)
        {
            if (settings == null)
            {
                settings = new DAE.ImportSettings();
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            STGenericScene Scene = new STGenericScene();

            COLLADA      collada      = COLLADA.Load(fileName);
            ColladaScene colladaScene = new ColladaScene(collada, settings);

            //Usually there is only one scene, but it can be possible some tools use multiple per model
            //Each one contains node hiearchies for bones and meshes
            foreach (var scene in colladaScene.scenes.visual_scene)
            {
                var  model = new STGenericModel(scene.name);
                Node Root  = LoadScene(scene, model, colladaScene);
                Scene.Models.Add(model);

                if (colladaScene.materials != null)
                {
                    foreach (var mat in colladaScene.materials.material)
                    {
                        model.Materials.Add(LoadMaterial(mat));
                    }
                }
                else
                {
                    model.Materials.Add(new STGenericMaterial()
                    {
                        Name = "Dummy"
                    });
                }

                if (model.Skeleton.Bones.Count == 0)
                {
                    model.Skeleton.Bones.Add(new STBone(model.Skeleton, "root"));
                }

                if (settings.FixDuplicateNames)
                {
                    //Adjust duplicate names

                    /*    foreach (var mesh in model.Meshes)
                     *  {
                     *      var names = model.Meshes.Select(x => x.Name).ToList();
                     *      mesh.Name = Utility.RenameDuplicateString(names, mesh.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var mat in model.Materials)
                     *  {
                     *      var names = model.Materials.Select(x => x.Name).ToList();
                     *      mat.Name = Utility.RenameDuplicateString(names, mat.Name, 0, 2);
                     *  }
                     *
                     *  foreach (var bone in model.Skeleton.Bones)
                     *  {
                     *      var names = model.Skeleton.Bones.Select(x => x.Name).ToList();
                     *      bone.Name = Utility.RenameDuplicateString(names, bone.Name, 0, 2);
                     *  }*/
                }
            }

            sw.Stop();
            Console.WriteLine("Elapsed={0}", sw.Elapsed);

            return(Scene);
        }
コード例 #40
0
    bool handleLink(XElement link)
    {
        if (link.Attribute("name").Value == "left_gripper")
        {
            Debug.Log("thing");
        }

        XElement visual;
        //get pose outside of visual for gazebo
        XElement pose = link.Element("pose");

        if ((visual = link.Element("visual")) != null)
        {
            XElement origin   = visual.Element("origin");
            XElement geometry = visual.Element("geometry");
            XElement material = visual.Element("material");
            string   xyz      = origin == null ? pose == null ? null : pose.Value : origin.Attribute("xyz").Value;
            //string materialName = material == null ? null : material.Attribute("name") == null ? null : material.Attribute("name").Value;


            //make a function that can return an array of floats given an element value
            //hackey shit - gets relevant rpy rotation and xyz transform from the link
            float[] rpy_rot  = null;
            string  localRot = visual.Element("origin") == null ? null : visual.Element("origin").Attribute("rpy") == null ? null : visual.Element("origin").Attribute("rpy").Value;
            if (localRot != null)
            {
                string[] poses = localRot.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                rpy_rot = new float[poses.Length];
                for (int index = 0; index < poses.Length; ++index)
                {
                    if (!float.TryParse(poses[index], out rpy_rot[index]))
                    {
                        rpy_rot[index] = 0;
                    }
                }
            }//may be incorect shifting of rpy
            Vector3 rpy_v = rpy_rot == null ? Vector3.zero : new Vector3(rpy_rot[0] * 57.3f, rpy_rot[2] * 57.3f, rpy_rot[1] * 57.3f);

            float[] xyz_pos  = null;
            string  localPos = visual.Element("origin") == null ? null : visual.Element("origin").Attribute("xyz") == null ? null : visual.Element("origin").Attribute("xyz").Value;
            if (localPos != null)
            {
                string[] poses = localPos.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                xyz_pos = new float[poses.Length];
                for (int index = 0; index < poses.Length; ++index)
                {
                    if (!float.TryParse(poses[index], out xyz_pos[index]))
                    {
                        xyz_pos[index] = 0;
                    }
                }
            }
            Vector3 xyz_v = xyz_pos == null ? Vector3.zero :  new Vector3(-xyz_pos[1], xyz_pos[2], xyz_pos[0]);
            //hackey shit


            Color?color = null;
            if (material != null)
            {
                color = handleMaterial(material);
            }

            if (geometry != null)
            {
                //handle mesh
                XElement mesh;
                if ((mesh = geometry.Element("mesh")) != null)
                {
                    string path = mesh.Attribute("filename") == null?mesh.Element("uri") == null ? null : mesh.Element("uri").Value : mesh.Attribute("filename").Value;

                    if (path != null)
                    {
                        if (path.StartsWith("package://"))
                        {
                            path = path.Remove(0, 10);
                        }

                        COLLADA foundDae = null;
                        string  dataPath = Application.dataPath;

                        if (path.EndsWith(".dae"))
                        {
                            foundDae = COLLADA.Load(dataPath + "/Resources/" + ResourcesFolder + "/" + path);
                            path     = path.Substring(0, path.LastIndexOf("."));
                        }

                        if (path.EndsWith(".DAE"))
                        {
                            foundDae = COLLADA.Load(dataPath + "/Resources/" + ResourcesFolder + "/" + path);
                            path     = path.Substring(0, path.LastIndexOf("."));
                        }

                        //We currently can't load stl so check if we added a dae model
                        if (path.EndsWith(".stl") || path.EndsWith(".STL"))
                        {
                            string stl2Dae = System.IO.Path.ChangeExtension(path, ".dae");
                            Debug.Log("[LoadMesh][handleLink] We don't support STL so trying DAE: " + stl2Dae);
                            if (File.Exists(dataPath + "/Resources/" + ResourcesFolder + "/" + stl2Dae))
                            {
                                Debug.Log("[LoadMesh][handleLink] Found a DAE model: " + stl2Dae);

                                path     = stl2Dae;
                                foundDae = COLLADA.Load(dataPath + "/Resources/" + ResourcesFolder + "/" + path);
                                path     = path.Substring(0, path.LastIndexOf("."));
                            }
                        }

                        try {
                            UnityEngine.Object foundMesh = Resources.Load(ResourcesFolder + "/" + path) as GameObject;

                            //handle rotations based on what axis is up for the mesh, this should fix most problems but
                            //a better solution may need to be persued.  Potentially rewriting the meshes to be some specific orientation (probably Z)
                            //and reloading them.
                            if (foundDae != null)
                            {
                                switch (foundDae.asset.up_axis)
                                {
                                case (UpAxisType.Z_UP):
                                    rpy_v += new Vector3(0f, 90f, 0f);
                                    break;

                                case (UpAxisType.X_UP):
                                    //NA at the moment
                                    break;

                                case (UpAxisType.Y_UP):
                                    rpy_v += new Vector3(-90f, 90f, 0f);
                                    break;

                                default:
                                    //NA at the moment
                                    break;
                                }
                            }

                            if (foundMesh != null)
                            {
                                GameObject go = Instantiate(foundMesh as GameObject);
                                if (link.Attribute("name").Value == "pedestal")
                                {
                                    Debug.Log("thin");
                                }


                                //crunch this down into a simpler chunk of code to eliminate repetition
                                if (go.transform.childCount == 0)
                                {
                                    go.transform.localPosition += xyz_v;
                                    go.transform.localRotation  = Quaternion.Euler(rpy_v + go.transform.localEulerAngles);

                                    GameObject goParent = new GameObject();
                                    goParent.transform.parent = transform;
                                    goParent.name             = link.Attribute("name").Value;
                                    links.Add(goParent);
                                    go.transform.parent = goParent.transform;

                                    //this sucks,
                                    // in some cases the urdf is declaring a mesh but not all the meshes that the dae needs
                                    // if (go.GetComponent<MeshRenderer>() != null && color != null)
                                    //    go.GetComponent<MeshRenderer>().material.color = color.Value;
                                }
                                else
                                {
                                    foreach (Transform tf in go.transform)
                                    {
                                        if (tf.name == "Lamp" || tf.name == "Camera")
                                        {
                                            Destroy(tf.gameObject);
                                            continue;
                                        }
                                        tf.transform.localPosition += xyz_v;
                                        tf.transform.localRotation  = Quaternion.Euler(tf.transform.localEulerAngles + go.transform.localEulerAngles + rpy_v);

                                        //this sucks,
                                        // in some cases the urdf is declaring a mesh but not all the meshes that the dae needs
                                        // if (tf.GetComponent<MeshRenderer>() != null && color != null)
                                        //   tf.GetComponent<MeshRenderer>().material.color = color.Value;
                                    }
                                    go.name             = link.Attribute("name").Value;
                                    go.transform.parent = transform;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogWarning(e);
                        }
                    }
                }

                //handle shapes (Cubes, Cylinders)
                XElement shape;
                if ((shape = geometry.Element("box")) != null)
                {
                    string   dimensions = shape.Attribute("size").Value;
                    string[] components = dimensions.Split(' ');
                    float    x, y, z;
                    if (float.TryParse(components[0], out x) && float.TryParse(components[1], out y) && float.TryParse(components[2], out z))
                    {
                        GameObject parent = new GameObject();
                        GameObject go     = GameObject.CreatePrimitive(PrimitiveType.Cube);

                        parent.name             = link.Attribute("name").Value;
                        parent.transform.parent = transform;
                        go.transform.parent     = parent.transform;
                        go.transform.localScale = new Vector3(y, z, x);

                        if (xyz_pos != null)
                        {
                            go.transform.localPosition += new Vector3(-xyz_pos[1], xyz_pos[2], xyz_pos[0]);
                        }

                        if (rpy_rot != null)
                        {
                            go.transform.localRotation = Quaternion.Euler(new Vector3(rpy_rot[1] * 57.3f, rpy_rot[2] * 57.3f, -rpy_rot[0] * 57.3f));
                        }

                        if (go.GetComponent <MeshRenderer>() != null && color != null)
                        {
                            go.GetComponent <MeshRenderer>().material.color = color.Value;
                        }
                        //links.Add(go.name, new link(go, xyz));
                    }
                }

                if ((shape = geometry.Element("cylinder")) != null)
                {
                    string length = shape.Attribute("length").Value;
                    string radius = shape.Attribute("radius").Value;
                    float  fLength, fRadius;
                    if (float.TryParse(length, out fLength) && float.TryParse(radius, out fRadius))
                    {
                        GameObject parent = new GameObject();
                        GameObject go     = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                        parent.name             = link.Attribute("name").Value;
                        parent.transform.parent = transform;
                        go.transform.parent     = parent.transform;
                        go.transform.localScale = new Vector3(fRadius * 2, fLength / 2, fRadius * 2);

                        if (xyz_pos != null)
                        {
                            go.transform.localPosition += new Vector3(-xyz_pos[1], xyz_pos[2], xyz_pos[0]);
                        }

                        if (rpy_rot != null)
                        {
                            go.transform.localRotation = Quaternion.Euler(new Vector3(rpy_rot[1] * 57.3f, rpy_rot[2] * 57.3f, -rpy_rot[0] * 57.3f));
                        }


                        if (go.GetComponent <MeshRenderer>() != null && color != null)
                        {
                            go.GetComponent <MeshRenderer>().material.color = color.Value;
                        }
                    }
                }
            }
        }
        else
        {
            GameObject go = new GameObject();
            go.transform.parent = transform;
            go.name             = link.Attribute("name").Value;
        }
        return(true);
    }