Inheritance: MonoBehaviour
コード例 #1
0
        public static void N3DS_NW4C_GFX_ToOBJ(String BCMDLPath, int ModelIdx, String OBJPath)
        {
            CGFX c = new CGFX(File.ReadAllBytes(BCMDLPath));

            if (c.Data.Models == null || c.Data.Models.Length <= ModelIdx)
            {
                throw new Exception("Model does not exist in the specified CGFX file!");
            }
            CMDL Model = c.Data.Models[ModelIdx];
            OBJ  o     = Model.ToOBJ();

            o.MTLPath = Path.GetFileNameWithoutExtension(OBJPath) + ".mtl";
            MTL m = Model.ToMTL(Path.GetFileNameWithoutExtension(OBJPath) + "_Tex");

            byte[] d  = o.Write();
            byte[] d2 = m.Write();
            File.Create(OBJPath).Close();
            File.WriteAllBytes(OBJPath, d);
            File.Create(Path.ChangeExtension(OBJPath, "mtl")).Close();
            File.WriteAllBytes(Path.ChangeExtension(OBJPath, "mtl"), d2);
            Directory.CreateDirectory(Path.GetDirectoryName(OBJPath) + "\\" + Path.GetFileNameWithoutExtension(OBJPath) + "_Tex");
            foreach (var v in c.Data.Textures)
            {
                if (!(v is ImageTextureCtr))
                {
                    continue;
                }
                ((ImageTextureCtr)v).GetBitmap().Save(Path.GetDirectoryName(OBJPath) + "\\" + Path.GetFileNameWithoutExtension(OBJPath) + "_Tex\\" + v.Name + ".png");
            }
        }
コード例 #2
0
 public OBJWrapper(string path)
 {
     base_path = Path.GetDirectoryName(path);
     try
     {
         bool has_mtl = true;
         obj_data = new OBJ(File.ReadAllBytes(path));
         if (obj_data.MTLPath.Length > 0)
         {
             try
             {
                 obj_data.MTLPath.Replace("/", "\\");
                 mtl_data = new MTL(File.ReadAllBytes(base_path + "\\" + obj_data.MTLPath));
             }
             catch
             {
                 mtl_data = null;
                 has_mtl  = false;
             }
         }
         InitializeMaterials(has_mtl);
     }
     catch (Exception e)
     {
         MessageBox.Show("OBJ Wrapper Exception: \n\r" + e.ToString());
     }
 }
コード例 #3
0
ファイル: Intersects.cs プロジェクト: yhr28/3DCollisions
    public static bool OBJRaycast(OBJ model, Ray ray, out float t)
    {
        if (model.IsEmpty)
        {
            t = -1;
            return(false);
        }
        Matrix4 inverseWorld = Matrix4.Inverse(model.WorldMatrix);
        Vector3 newRayPos    = Matrix4.MultiplyPoint(inverseWorld, ray.Position.ToVector());
        Vector3 newRayNorm   = Matrix4.MultiplyVector(inverseWorld, ray.Normal);
        Ray     newRay       = new Ray(newRayPos, newRayNorm);

        //ray boundingbox
        if (!LinesAndRays.RaycastAABB(newRay, model.BoundingBox, out t))
        {
            return(false);
        }
        //ray boundingSphere
        if (!LinesAndRays.RaycastSphere(newRay, model.BoundingSphere, out t))
        {
            return(false);
        }

        return(LinesAndRays.RaycastBVH(newRay, model.BVHRoot, out t));
    }
コード例 #4
0
ファイル: box_recolor.cs プロジェクト: Hamzart/Elevatium
    public void setCOLOR()
    {
        if (btn_recolor == "none")
        {
            btn_recolor = "red";
            GetComponent <Image> ().sprite = colors [1];
        }
        else if (btn_recolor == "red")
        {
            btn_recolor = "green";
            GetComponent <Image> ().sprite = colors [3];
        }
        else if (btn_recolor == "green")
        {
            btn_recolor = "blue";
            GetComponent <Image> ().sprite = colors [2];
        }
        else if (btn_recolor == "blue")
        {
            btn_recolor = "none";
            GetComponent <Image> ().sprite = colors [0];
        }

        boxlist = GameObject.FindGameObjectsWithTag("box");

        foreach (GameObject OBJ in boxlist)
        {
            //print (OBJ.name);
            OBJ.SendMessage("ManageBox", 0, SendMessageOptions.DontRequireReceiver);
            //OBJ.GetComponent<Box> ().ManageBox ();
        }
    }
コード例 #5
0
ファイル: Intersects.cs プロジェクト: yhr28/3DCollisions
    public static bool OBJTriangleIntersect(Triangle triangle, OBJ model)
    {
        Matrix4  inverseWorld  = Matrix4.Inverse(model.WorldMatrix);
        Vector3  newTrianglep0 = Matrix4.MultiplyPoint(inverseWorld, triangle.p0.ToVector());
        Vector3  newTrianglep1 = Matrix4.MultiplyPoint(inverseWorld, triangle.p1.ToVector());
        Vector3  newTrianglep2 = Matrix4.MultiplyPoint(inverseWorld, triangle.p2.ToVector());
        Triangle newTriangle   = new Triangle(newTrianglep0, newTrianglep1, newTrianglep2);

        //triangle boundbox
        if (!Collisions.TriangleAABBIntersect(triangle, model.BoundingBox))
        {
            return(false);
        }
        //triangle sphere
        if (!Collisions.SphereIntersect(model.BoundingSphere, triangle))
        {
            return(false);
        }

        //triangle triangle
        foreach (Triangle t in model.Mesh)
        {
            if (Collisions.TriangleTriangleIntersection(t, triangle))
            {
                return(true);
            }
        }

        //passed all collisions
        return(false);
    }
コード例 #6
0
ファイル: Intersects.cs プロジェクト: yhr28/3DCollisions
    public static bool OBJPlaneIntersect(OBJ model, Plane plane)
    {
        Matrix4 inverseWorld = Matrix4.Inverse(model.WorldMatrix);
        Vector3 newPlaneNorm = Matrix4.MultiplyVector(inverseWorld, plane.Normal);
        Plane   newPlane     = new Plane(newPlaneNorm, plane.Distance);

        //plane bounding box
        if (!AABBPlaneIntersect(model.BoundingBox, newPlane))
        {
            return(false);
        }
        //plane bounding sphere
        if (!SpherePlaneIntersect(newPlane, model.BoundingSphere))
        {
            return(false);
        }
        //plane triangle
        foreach (Triangle triangle in model.Mesh)
        {
            if (Collisions.PlaneTriangleIntersection(newPlane, triangle))
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #7
0
ファイル: Intersects.cs プロジェクト: yhr28/3DCollisions
    public static bool OBJSphereIntersect(Sphere sphere, OBJ model)
    {
        Matrix4 inverseWorldMatrix = Matrix4.Inverse(model.WorldMatrix);

        Vector3 newSpherePos = Matrix4.MultiplyPoint(inverseWorldMatrix, sphere.Position.ToVector());
        // We have to scale the radius of the sphere! This is difficult. The new scalar is the old radius
        // multiplied by the largest scale component of the matrix
        float newSphereRad = sphere.Radius * System.Math.Abs(System.Math.Max(
                                                                 System.Math.Max(System.Math.Abs(inverseWorldMatrix[0, 0]), System.Math.Abs(inverseWorldMatrix[1, 1])),
                                                                 System.Math.Abs(inverseWorldMatrix[2, 2])));
        //make new sphere because old is a reference and we dont want to alter it
        Sphere translatedSphere = new Sphere(newSpherePos, newSphereRad);

        //broad phase collision
        if (!SphereAABBIntersect(model.BoundingBox, translatedSphere))
        {
            return(false);
        }
        //narrow phase
        for (int i = 0; i < model.Mesh.Length; i++)
        {
            if (Collisions.SphereIntersect(translatedSphere, model.Mesh[i]))
            {
                return(true);
            }
        }
        //no triangles intersected in narrow phase
        return(false);
    }
コード例 #8
0
        public bool Insert(OBJ obj)
        {
            //bounding sphere is model space, we need world
            Sphere worldSpaceSphere = new Sphere();

            worldSpaceSphere.Position = new Point(Matrix4.MultiplyPoint(obj.WorldMatrix, obj.BoundingSphere.Position.ToVector()));
            float scale = Math.Max(obj.WorldMatrix[0, 0], Math.Max(obj.WorldMatrix[1, 1], obj.WorldMatrix[2, 2]));

            worldSpaceSphere.Radius = obj.BoundingSphere.Radius * scale;
            if (Intersects.SphereAABBIntersect(worldSpaceSphere, Bounds))
            {
                //we know obj intersects node if a leaf
                //add to list, if not recurse
                if (Children != null)
                {
                    foreach (OctreeNode child in Children)
                    {
                        child.Insert(obj);
                    }
                }
                else
                {
                    Contents.Add(obj);
                }
                return(true);
            }
            return(false);
        }
コード例 #9
0
 /// <summary>Add an object to be counted</summary>
 internal virtual void Add(OBJ key, long time)
 {
     lock (this)
     {
         map[key] = time;
     }
 }
コード例 #10
0
        public static OBJ GetObjectType(HandleRef h)
        {
            OBJ result = GetObjectType((HGDIOBJ)h.Handle);

            GC.KeepAlive(h.Wrapper);
            return(result);
        }
コード例 #11
0
        public OBJ ToOBJ(out MTL mtl)
        {
            OBJ o = new OBJ();
            int v = 0;
            HashSet <String> matnames = new HashSet <string>();

            foreach (var vv in Planes)
            {
                Triangle t = GetTriangle(vv);
                o.Vertices.Add(t.PointA);
                o.Vertices.Add(t.PointB);
                o.Vertices.Add(t.PointC);
                var f = new OBJ.OBJFace();
                f.Material = "mat_" + vv.CollisionType.ToString("X") + "_ID";
                matnames.Add(f.Material);
                f.VertexIndieces.Add(v);
                f.VertexIndieces.Add(v + 1);
                f.VertexIndieces.Add(v + 2);
                o.Faces.Add(f);
                v += 3;
            }
            mtl = new MTL();
            Random r = new Random();

            foreach (string s in matnames)
            {
                MTL.MTLMaterial m = new MTL.MTLMaterial(s);
                m.AmbientColor  = Color.Black;
                m.SpecularColor = Color.FromArgb(85, 85, 85);
                m.DiffuseColor  = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
                mtl.Materials.Add(m);
            }
            o.optimizeVertexCount();
            return(o);
        }
コード例 #12
0
        public Modelled3DFloorTile(OBJ model, string textureName)
        {
            TextureName = textureName;
            var indices  = model.FacesByObjgroup.First(x => x.Value.Count > 0).Value;
            var outVerts = new List <TerrainParallaxVertex>();
            var outInds  = new List <int>();
            var dict     = new Dictionary <Tuple <int, int, int>, int>();

            var off = new Vector3(0.5f, 0, 0.5f);

            foreach (var ind in indices)
            {
                var tup = new Tuple <int, int, int>(ind[0], ind[1], ind[2]);
                int targ;
                if (!dict.TryGetValue(tup, out targ))
                {
                    //add a vertex
                    targ = outVerts.Count;
                    var tc = model.TextureCoords[ind[1] - 1];
                    tc.Y = 1 - tc.Y;
                    var vert = new TerrainParallaxVertex(model.Vertices[ind[0] - 1] + off, Vector4.One, tc, 0, model.Normals[ind[2] - 1]);
                    outVerts.Add(vert);
                    dict[tup] = targ;
                }
                outInds.Add(targ);
            }

            //todo: process using projector? (to cut at diagonals)

            Vertices = outVerts.ToArray();
            Indices  = outInds.ToArray();
        }
コード例 #13
0
        public static void MarioKart_MKDS_KCL_Generate(String OBJPath, String OutPath, Dictionary <String, ushort> TypeMapping)
        {
            MKDS.KCL      k        = new MKDS.KCL();
            OBJ           o        = new OBJ(File.ReadAllBytes(OBJPath));
            List <String> matnames = new List <string>();

            foreach (var v in o.Faces)
            {
                if (!matnames.Contains(v.Material))
                {
                    matnames.Add(v.Material);
                }
            }
            Dictionary <string, bool> Colli = new Dictionary <string, bool>();

            foreach (string s in matnames)
            {
                if (!TypeMapping.ContainsKey(s))
                {
                    TypeMapping.Add(s, 0);
                }
                Colli.Add(s, true);
            }
            k.FromOBJ(o, TypeMapping, Colli);
            File.Create(OutPath).Close();
            File.WriteAllBytes(OutPath, k.Write());
        }
コード例 #14
0
 public bool CreateFromFile()
 {
     System.Windows.Forms.OpenFileDialog f = new System.Windows.Forms.OpenFileDialog();
     f.Filter = OBJ.Identifier.GetFileFilter();
     if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
         f.FileName.Length > 0)
     {
         OBJ           o        = new OBJ(File.ReadAllBytes(f.FileName));
         List <String> matnames = new List <string>();
         foreach (var v in o.Faces)
         {
             if (!matnames.Contains(v.Material))
             {
                 matnames.Add(v.Material);
             }
         }
         UI.KCLCollisionTypeSelector ty = new UI.KCLCollisionTypeSelector(matnames.ToArray(), f.FileName);
         ty.DialogResult = System.Windows.Forms.DialogResult.None;
         ty.ShowDialog();
         while (ty.DialogResult != System.Windows.Forms.DialogResult.OK)
         {
             ;
         }
         FromOBJ(o, ty.Mapping, ty.Colli);
         return(true);
     }
     return(false);
 }
コード例 #15
0
        public override void Initialize(int width, int height)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.Light0);

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);

            GL.Light(LightName.Light0, LightParameter.Position, new float[] { 0.0f, 0.5f, 0.5f, 0.0f });
            GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0f, 1f, 0f, 1f });
            GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 0f, 1f, 0f, 1f });
            GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 1f, 1f, 1f, 1f });

            loader  = new OBJLoader("Assets/suzanne.obj");
            objs[0] = new OBJ(loader);
            objs[1] = new OBJ(loader);
            objs[2] = new OBJ(loader);

            objs[0].Scale = new Vector3(3.0f, 3.0f, 3.0f);

            objs[1].Position = new Vector3(6.0f, 6.0f, 6.0f);
            objs[1].Scale    = new Vector3(1.5f, 1.5f, 1.5f);

            objs[2].Position = new Vector3(-6.0f, -6.0f, -6.0f);
            objs[1].Scale    = new Vector3(1.5f, 1.5f, 1.5f);
            objs[2].Rotation = new Vector3(90.0f, 0.0f, 0.0f);
        }
コード例 #16
0
ファイル: button_sign.cs プロジェクト: Hamzart/Elevatium
    public void setDirection()
    {
        if (signDirection == "none")
        {
            signDirection = "left";
            GetComponent <Image> ().sprite = images [1];
        }
        else if (signDirection == "left")
        {
            signDirection = "right";
            GetComponent <Image> ().sprite = images [2];
        }
        else if (signDirection == "right")
        {
            signDirection = "back";
            GetComponent <Image> ().sprite = images [3];
        }
        else if (signDirection == "back")
        {
            signDirection = "none";
            GetComponent <Image> ().sprite = images [0];
        }

        //boxlist = GameObject.FindWithTag ("box");
        boxlist = GameObject.FindGameObjectsWithTag("box");

        foreach (GameObject OBJ in boxlist)
        {
            //print (OBJ.name);
            OBJ.SendMessage("ManageBox", 0, SendMessageOptions.DontRequireReceiver);
            //OBJ.GetComponent<Box> ().ManageBox ();
        }
    }
コード例 #17
0
 //Init function when we turn on this screen
 public void InitScreen()
 {
     foreach (GameObject OBJ in INIT_OBJECTS)
     {
         OBJ.SetActive(true);
     }
 }
コード例 #18
0
 /// <summary>Remove an object to be counted</summary>
 internal virtual void Remove(OBJ key)
 {
     lock (this)
     {
         Sharpen.Collections.Remove(map, key);
     }
 }
コード例 #19
0
ファイル: FSOMEditor.cs プロジェクト: yuripourre-forks/FreeSO
 private void OBJToFSOM(OBJ obj)
 {
     GameThread.NextUpdate(x =>
     {
         var mesh = new DGRP3DMesh(ActiveDGRP, obj, Client.GameFacade.GraphicsDevice);
         if (IffMode)
         {
             var fsom = ActiveObject.Resource.Get <FSOM>(ActiveDGRP.ChunkID);
             if (fsom == null)
             {
                 fsom                = new FSOM();
                 fsom.ChunkLabel     = "OBJ Import Mesh";
                 fsom.ChunkID        = ActiveDGRP.ChunkID;
                 fsom.ChunkProcessed = true;
                 fsom.ChunkType      = "FSOM";
                 fsom.AddedByPatch   = true;
                 (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(fsom);
             }
             Content.Content.Get().Changes.QueueResMod(new ResAction(() =>
             {
                 fsom.SetMesh(mesh);
                 Content.Content.Get().RCMeshes.ClearCache(ActiveDGRP);
                 Debug3D.ForceUpdate();
             }, fsom));
         }
         else
         {
             Content.Content.Get().RCMeshes.Replace(ActiveDGRP, mesh);
             Debug3D.ForceUpdate();
         }
     });
 }
コード例 #20
0
        public void LoadModel(string filename)
        {
            try
            {
                switch (Path.GetExtension(filename).ToLower())
                {
                case ".obj":
                    OBJ obj = OBJ.FromFile(filename);
                    ctr = CtrModel.FromObj(obj);
                    break;

                case ".ply":
                    ctr = CtrModel.FromPly(filename);
                    break;

                default:
                    MessageBox.Show("Unsupported model.");
                    break;
                }

                UpdateUI();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #21
0
        public static HGDIOBJ GetCurrentObject(IHandle hdc, OBJ type)
        {
            HGDIOBJ result = GetCurrentObject((HDC)hdc.Handle, type);

            GC.KeepAlive(hdc);
            return(result);
        }
コード例 #22
0
        public static void EnsureTilesLoaded()
        {
            if (PoolTiles != null)
            {
                return;
            }
            PoolTiles = new Modelled3DFloorTile[16];
            for (int i = 0; i < 16; i++)
            {
                using (var file = File.Open($"Content/3D/floor/pool_hq_{i}.obj", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var obj = new OBJ(file);
                    PoolTiles[i] = new Modelled3DFloorTile(obj, "pool.png");
                }
            }

            CornerTiles = new Modelled3DFloorTile[4];
            for (int i = 0; i < 4; i++)
            {
                using (var file = File.Open($"Content/3D/floor/poolcorner_hq_{i}.obj", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var obj = new OBJ(file);
                    CornerTiles[i] = new Modelled3DFloorTile(obj, "pool.png");
                }
            }
        }
コード例 #23
0
    // Use this for initialization
    void Awake()
    {
        tibiaModel = GameObject.Find("tibiamodel");
        femurModel = GameObject.Find("femurmodel");
        //ObjScript1 = GameObject.Find("tibiamodel").GetComponent<OBJ>();
        ObjScript2 = GameObject.Find("femurmodel").GetComponent <OBJ>();
        rutaExe    = Application.persistentDataPath + "/Casos/1/";
        Debug.Log(rutaExe);
        //Debug.Log("file:///" + rutaExe + "tibiaClean.obj");

        //StartCoroutine(ObjScript1.Load("file:///" + rutaExe + "tibiaFinal.obj"));
        StartCoroutine(ObjScript2.Load("file:///" + rutaExe + "tubo2.obj"));
        rigids        = readRigids(rutaExe + "rigids.txt");
        matriz        = readMatriz(rutaExe + "matriz.csv"); // femur pos, femur rigid rot,femur model rot,  tibia pos, tibia rigid rot, tibia model rot
        posFemur      = new Vector3((float)Convert.ToDouble(matriz[0][0]), (float)Convert.ToDouble(matriz[0][1]), (float)Convert.ToDouble(matriz[0][2]));
        rotRigidFemur = new Quaternion((float)Convert.ToDouble(matriz[1][0]), (float)Convert.ToDouble(matriz[1][1]), (float)Convert.ToDouble(matriz[1][2]), (float)Convert.ToDouble(matriz[1][3]));
        rotModelFemur = new Quaternion((float)Convert.ToDouble(matriz[2][0]), (float)Convert.ToDouble(matriz[2][1]), (float)Convert.ToDouble(matriz[2][2]), (float)Convert.ToDouble(matriz[2][3]));
        posTibia      = new Vector3((float)Convert.ToDouble(matriz[3][0]), (float)Convert.ToDouble(matriz[3][1]), (float)Convert.ToDouble(matriz[3][2]));
        rotRigidTibia = new Quaternion((float)Convert.ToDouble(matriz[4][0]), (float)Convert.ToDouble(matriz[4][1]), (float)Convert.ToDouble(matriz[4][2]), (float)Convert.ToDouble(matriz[4][3]));
        rotModelTibia = new Quaternion((float)Convert.ToDouble(matriz[5][0]), (float)Convert.ToDouble(matriz[5][1]), (float)Convert.ToDouble(matriz[5][2]), (float)Convert.ToDouble(matriz[5][3]));
        puntos        = readPuntos(rutaExe + "puntos.csv"); //punto1a, punto1b, punto2a, punto2b ,punto3a, punto3b,punto4a, punto4b
        punto1A       = new Vector3((float)Convert.ToDouble(puntos[0][0]), (float)Convert.ToDouble(puntos[0][1]), (float)Convert.ToDouble(puntos[0][2]));
        punto1B       = new Vector3((float)Convert.ToDouble(puntos[1][0]), (float)Convert.ToDouble(puntos[1][1]), (float)Convert.ToDouble(puntos[1][2]));
        punto2A       = new Vector3((float)Convert.ToDouble(puntos[2][0]), (float)Convert.ToDouble(puntos[2][1]), (float)Convert.ToDouble(puntos[2][2]));
        punto2B       = new Vector3((float)Convert.ToDouble(puntos[3][0]), (float)Convert.ToDouble(puntos[3][1]), (float)Convert.ToDouble(puntos[3][2]));
        punto3A       = new Vector3((float)Convert.ToDouble(puntos[4][0]), (float)Convert.ToDouble(puntos[4][1]), (float)Convert.ToDouble(puntos[4][2]));
        punto3B       = new Vector3((float)Convert.ToDouble(puntos[5][0]), (float)Convert.ToDouble(puntos[5][1]), (float)Convert.ToDouble(puntos[5][2]));
        punto4A       = new Vector3((float)Convert.ToDouble(puntos[6][0]), (float)Convert.ToDouble(puntos[6][1]), (float)Convert.ToDouble(puntos[6][2]));
        punto4B       = new Vector3((float)Convert.ToDouble(puntos[7][0]), (float)Convert.ToDouble(puntos[7][1]), (float)Convert.ToDouble(puntos[7][2]));
        diaDis        = readDiaDis(rutaExe + "diadis.txt");
        //StartCoroutine("loadBundle");
    }
コード例 #24
0
 public void roundVertexPositions(OBJ obj)
 {
     for (int i = 0; i < obj.Vertices.Count; i++)
     {
         Vector3 v = obj.Vertices[i];
         obj.Vertices[i] = new Vector3((float)Math.Round(v.X, 2), (float)Math.Round(v.Y, 2), (float)Math.Round(v.Z, 2));
     }
 }
コード例 #25
0
            public override bool Test(IActor a, OBJ target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
            {
                if (isAutonomous)
                {
                    return(false);
                }

                return(DebugEnabler.Settings.mEnabled);
            }
コード例 #26
0
ファイル: CityFoliage.cs プロジェクト: HarryFreeMyLand/newso
        public Tuple <DGRP3DVert[], int[]> LoadModel(string model)
        {
            OBJ obj;

            using (var str = File.Open($"Content/3D/{model}", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                obj = new OBJ(str);
            }

            var indices  = obj.FacesByObjgroup.First(x => x.Value.Count > 0).Value;
            var outVerts = new List <DGRP3DVert>();
            var outInds  = new List <int>();
            var dict     = new Dictionary <Tuple <int, int>, int>();

            foreach (var ind in indices)
            {
                var tup = new Tuple <int, int>(ind[0], ind[1]);
                int targ;
                if (!dict.TryGetValue(tup, out targ))
                {
                    //add a vertex
                    targ = outVerts.Count;
                    var vert = new DGRP3DVert(obj.Vertices[ind[0] - 1], Vector3.Zero, obj.TextureCoords[ind[1] - 1]);
                    vert.TextureCoordinate.Y = 1 - vert.TextureCoordinate.Y;
                    outVerts.Add(vert);
                    dict[tup] = targ;
                }
                outInds.Add(targ);
            }

            var triBase = new int[outInds.Count / 3][];

            for (int i = 0; i < triBase.Length; i++)
            {
                triBase[i] = new int[] { outInds[i * 3], outInds[i * 3 + 1], outInds[i * 3 + 2] }
            }
            ;

            var ordered = triBase.OrderBy(x => outVerts[x[0]].Position.Y + outVerts[x[1]].Position.Y + outVerts[x[2]].Position.Y);

            outInds.Clear();
            foreach (var item in ordered)
            {
                outInds.AddRange(item);
            }

            return(new Tuple <DGRP3DVert[], int[]>(outVerts.ToArray(), outInds.ToArray()));
        }

        Dictionary <Color, int> ForestTypes = new Dictionary <Color, int>()
        {
            { new Color(0, 0x6A, 0x28), 0 }, //heavy forest
            { new Color(0, 0xEB, 0x42), 1 }, //light forest
            { new Color(255, 0xFC, 0), 2 },  //palm
            { new Color(255, 0, 0), 3 },     //cacti
            { new Color(0, 0, 0), -1 }  //nothing; no forest
        };
コード例 #27
0
    void LoadUserImprot(string message)
    {
        SetLastInactive();
        userimport = new GameObject("UserImport" + userimporottaltol);
        OBJLoader  = userimport.AddComponent <OBJ>();
        STLLoader  = userimport.AddComponent <STL>();
        Dictionary <int, string> map = MSGCenter.UnFormatMessage(message);
        //string[] s = message.Split('*');
        string serverpath = map[1];

        if (map.ContainsKey(2))
        {
            string md5 = map[2];
            CreatModel(md5);
        }
        if (serverpath.IsObj())
        {
            TTUIPage.ShowPage <UINotice>("请使用stl格式的模型");
            //pcpath = "file:///" + pcpath;
            //try
            //{
            //    OBJLoader.Load(pcpath, (result) =>
            //    {
            //        MatchingModelNormal(userimport,v, hasposvalue);
            //        userimport.AddComponent<MeshCollider>();
            //        MSGCenter.Execute(Enums.ModelPath.Result.ToString(), result );
            //    });
            //}
            //catch (System.Exception e)
            //{
            //    MSGCenter.Execute(Enums.ModelPath.Result.ToString(), e.ToString() );
            //    throw;
            //}
        }
        else if (serverpath.IsStl())
        {
            string stlpath = Tool.LocalModelonSavePath + PlayerDataCenter.Currentillnessdata.ID + ".stl";// mm.pdata.LocalUserModelPath;//
            if (!Tool.CheckFileExist(stlpath))
            {
                MyWebRequest.Instance.DownloadFileFromWed(serverpath, Tool.LocalModelonSavePath, PlayerDataCenter.Currentillnessdata.ID + ".stl"
                                                          , (suc, str) =>
                {
                    TTUIPage.ShowPage <UINotice>(Tool.DownloadDir + str);
                    if (suc)
                    {
                        TTUIPage.ClosePage <UINotice>();
                        CreatStlInstance(stlpath);
                    }
                });
            }
            else
            {
                CreatStlInstance(stlpath);
            }
        }
    }
コード例 #28
0
        public static void ScaleOBJ(string in_obj, string out_obj, float scale)
        {
            var obj = new OBJ(in_obj);

            for (int i = 0; i < obj.Vertices.Count; i++)
            {
                obj.Vertices[i] = Vector3.Multiply(obj.Vertices[i], scale);
            }
            obj.Write(out_obj);
        }
コード例 #29
0
ファイル: GameManager.cs プロジェクト: Absidion/Irkalla
 //This will destroy all Normal objects
 public void DestroyAllNormal()
 {
     foreach (GameObject OBJ in m_NormalObjects)
     {
         OBJ.SetActive(false);
         Debug.Log(OBJ.name.ToString() + " Destroyed");
         Destroy(OBJ);
     }
     m_NormalObjects.Clear();
 }
コード例 #30
0
ファイル: MainForm.cs プロジェクト: rjayhub/CTR-tools
        public MainForm()
        {
            InitializeComponent();

            this.Text         = $"{this.Text} - {Meta.GetVersion()}";
            labelVersion.Text = Meta.GetVersion();
            signLabel.Text    = Meta.GetSignature();

            OBJ.FixCulture();
        }
コード例 #31
0
 public static void MarioKart_MKDS_KCL_Generate(String OBJPath, String OutPath, Dictionary<String, ushort> TypeMapping)
 {
     MKDS.KCL k = new MKDS.KCL();
     OBJ o = new OBJ(File.ReadAllBytes(OBJPath));
     List<String> matnames = new List<string>();
     foreach (var v in o.Faces) if (!matnames.Contains(v.Material)) matnames.Add(v.Material);
     Dictionary<string, bool> Colli = new Dictionary<string,bool>();
     foreach (string s in matnames)
     {
         if (!TypeMapping.ContainsKey(s)) TypeMapping.Add(s, 0);
         Colli.Add(s, true);
     }
     k.FromOBJ(o, TypeMapping, Colli);
     File.Create(OutPath).Close();
     File.WriteAllBytes(OutPath, k.Write());
 }
コード例 #32
0
ファイル: CMDL.cs プロジェクト: Ermelber/EveryFileExplorer
        public OBJ ToOBJ()
        {
            var o = new OBJ();
            int v = 0;
            int vn = 0;
            int vt = 0;
            //int vc = 0;
            int ff = 0;
            var m = this;
            //foreach (CMDL m in Models)
            {
                foreach (var vv in m.Shapes)
                {
                    Polygon p = vv.GetVertexData(m);
                    var mat = m.Materials[m.Meshes[ff].MaterialIndex];

                    int TexCoord = -1;
                    if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)// && mat.TextureCoordiators[0].SourceCoordinate == 0)
                    {
                        if (mat.TextureCoordiators[0].SourceCoordinate == 0) TexCoord = 0;
                        else if (mat.TextureCoordiators[0].SourceCoordinate == 1) TexCoord = 1;
                        else TexCoord = 2;
                    }

                    foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
                    {
                        Vector3[] defs = q.GetFaceData();
                        foreach (Vector3 d in defs)
                        {
                            OBJ.OBJFace f = new OBJ.OBJFace();
                            f.Material = mat.Name;
                            o.Vertices.Add(p.Vertex[(int)d.X]);
                            o.Vertices.Add(p.Vertex[(int)d.Y]);
                            o.Vertices.Add(p.Vertex[(int)d.Z]);
                            f.VertexIndieces.Add(v);
                            f.VertexIndieces.Add(v + 1);
                            f.VertexIndieces.Add(v + 2);
                            v += 3;
                            if (p.Normals != null)
                            {
                                o.Normals.Add(p.Normals[(int)d.X]);
                                o.Normals.Add(p.Normals[(int)d.Y]);
                                o.Normals.Add(p.Normals[(int)d.Z]);
                                f.NormalIndieces.Add(vn);
                                f.NormalIndieces.Add(vn + 1);
                                f.NormalIndieces.Add(vn + 2);
                                vn += 3;
                            }
                            if (TexCoord == 0)
                            {
                                o.TexCoords.Add(p.TexCoords[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                            }
                            else if (TexCoord == 1)
                            {
                                o.TexCoords.Add(p.TexCoords2[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords2[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords2[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                            }
                            else if (TexCoord == 2)
                            {
                                o.TexCoords.Add(p.TexCoords3[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords3[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                                o.TexCoords.Add(p.TexCoords3[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
                            }
                            else goto cont;
                            f.TexCoordIndieces.Add(vt);
                            f.TexCoordIndieces.Add(vt + 1);
                            f.TexCoordIndieces.Add(vt + 2);
                            vt += 3;
                        cont:
                            /*if (p.Colors != null)
                            {
                                o.VertexColors.Add(p.Colors[(int)d.X]);
                                o.VertexColors.Add(p.Colors[(int)d.Y]);
                                o.VertexColors.Add(p.Colors[(int)d.Z]);
                                f.VertexColorIndieces.Add(vc);
                                f.VertexColorIndieces.Add(vc + 1);
                                f.VertexColorIndieces.Add(vc + 2);
                                vc += 3;
                            }*/
                            o.Faces.Add(f);
                        }
                    }
                    ff++;
                }
            }
            return o;
        }
コード例 #33
0
 public OBJ ToOBJ()
 {
     OBJ o = new OBJ();
     foreach (var v in Triangles)
     {
         int baseidx = o.Vertices.Count;
         o.Vertices.AddRange(v.Vertices);
         o.TexCoords.AddRange(v.TexCoords);
         for (int i = 0; i < v.Vertices.Count; i += 3)
         {
             OBJ.OBJFace f = new OBJ.OBJFace();
             f.Material = "M" + v.MaterialId + "M";
             f.VertexIndieces.Add(baseidx + i);
             f.VertexIndieces.Add(baseidx + i + 1);
             f.VertexIndieces.Add(baseidx + i + 2);
             f.TexCoordIndieces.Add(baseidx + i);
             f.TexCoordIndieces.Add(baseidx + i + 1);
             f.TexCoordIndieces.Add(baseidx + i + 2);
             o.Faces.Add(f);
         }
     }
     return o;
 }
コード例 #34
0
    public void Alteration(Vector3 position, Vector3 scale, OBJ obj, SFX sfx, Color color)
    {
        // Get point in terrain location
        Matrix4x4 matrix = transform.worldToLocalMatrix;
        position = matrix.MultiplyPoint(position);
        scale = matrix.MultiplyVector(scale);
        Bounds bounds = new Bounds(position, scale);

        int sX = (int)scale.x/2+1,
            sY = (int)scale.y/2+1,
            sZ = (int)scale.z/2+1,
            bX = Mathf.Max((int)position.x-sX, 1),
            bY = Mathf.Max((int)position.y-sY, 1),
            bZ = Mathf.Max((int)position.z-sZ, 1),
            eX = Mathf.Min((int)position.x+sX+2, width-2),
            eY = Mathf.Min((int)position.y+sY+2, height-2),
            eZ = Mathf.Min((int)position.z+sZ+2, depth-2);

        // inverse effect for subtraction or erosion
        if(sfx==SFX.SUB || sfx==SFX.EROSION)
            for(int x=bX; x<eX; x++)
            for(int y=bY; y<eY; y++)
            for(int z=bZ; z<eZ; z++)
                _map[x,y,z] = (byte)(255-_map[x,y,z]);

        // Begin of effect

        switch(sfx)
        {
        case SFX.ADD :
        case SFX.SUB :
            switch(obj)
            {
            case OBJ.CUBE   : AddCube  (bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.SPHERE : AddSphere(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.RANDOM : AddRandom(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            }
            break;
        case SFX.DILATION :
        case SFX.EROSION :
            switch(obj)
            {
            case OBJ.CUBE   : DilationCube  (bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.SPHERE : DilationSphere(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.RANDOM : DilationRandom(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            }
            break;
        case SFX.PAINT :
            switch(obj)
            {
            case OBJ.CUBE   : PaintCube  (bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.SPHERE : PaintSphere(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            case OBJ.RANDOM : PaintRandom(bounds, bX, bY, bZ, eX, eY, eZ, color);	break;
            }
            break;
        }

        // End effect

        // inverse effect for subtraction or erosion
        if(sfx==SFX.SUB || sfx==SFX.EROSION)
            for(int x=bX; x<eX; x++)
            for(int y=bY; y<eY; y++)
            for(int z=bZ; z<eZ; z++)
                _map[x,y,z] = (byte)(255-_map[x,y,z]);

        // rebuild map in this bounds
        bounds.SetMinMax(new Vector3(bX, bY, bZ), new Vector3(eX, eY, eZ));
        ReBuild(bounds);
    }
コード例 #35
0
 public static void FromOBJ(CGFX c, String OBJPath, String ModelName = "EFEModel")
 {
     OBJ Model = new OBJ(File.ReadAllBytes(OBJPath));
     if (Model.MTLPath == null) throw new Exception("Model without materials not supported!");
     String MtlPath = Path.GetDirectoryName(OBJPath) + "\\" + Model.MTLPath;
     MTL MatLib = new MTL(File.ReadAllBytes(MtlPath));
     List<String> MatNames = new List<string>();
     foreach (var f in Model.Faces)
     {
         if (!MatNames.Contains(f.Material)) MatNames.Add(f.Material);
     }
     Bitmap[] Textures = new Bitmap[MatLib.Materials.Count];
     int q = 0;
     int NrTextures = 0;
     foreach (var v in MatLib.Materials)
     {
         if (!MatNames.Contains(v.Name)) { q++; continue; }
         if (v.DiffuseMapPath != null)
         {
             Textures[q] = new Bitmap(new MemoryStream(File.ReadAllBytes(Path.GetDirectoryName(MtlPath) + "\\" + v.DiffuseMapPath)));
             NrTextures++;
         }
         q++;
     }
     c.Data.Dictionaries[0] = new DICT();
     c.Data.Dictionaries[0].Add(ModelName);
     c.Data.Models = new CMDL[1];
     c.Data.Models[0] = new CMDL(ModelName);
     CMDL cmdl = c.Data.Models[0];
     //Mesh Node Visibility
     {
         cmdl.NrMeshNodes = 1;
         cmdl.MeshNodeVisibilitiesDict = new DICT();
         cmdl.MeshNodeVisibilitiesDict.Add("CompleteModel");
         cmdl.MeshNodeVisibilities = new CMDL.MeshNodeVisibilityCtr[] { new CMDL.MeshNodeVisibilityCtr("CompleteModel") };
     }
     //Meshes
     {
         cmdl.NrMeshes = (uint)MatNames.Count;
         cmdl.Meshes = new CMDL.Mesh[MatNames.Count];
         for (int i = 0; i < MatNames.Count; i++)
         {
             cmdl.Meshes[i] = new CMDL.Mesh();
             cmdl.Meshes[i].MeshNodeName = "CompleteModel";
             cmdl.Meshes[i].MaterialIndex = (uint)i;
             cmdl.Meshes[i].ShapeIndex = (uint)i;
         }
     }
     //Materials
     {
         cmdl.NrMaterials = (uint)MatNames.Count;
         cmdl.MaterialsDict = new DICT();
         cmdl.Materials = new CMDL.MTOB[MatNames.Count];
         for (int i = 0; i < MatNames.Count; i++)
         {
             cmdl.MaterialsDict.Add(MatNames[i]);
             cmdl.Materials[i] = new CMDL.MTOB(MatNames[i]);
             cmdl.Materials[i].FragShader.TextureCombiners[0].SrcRgb = 0xEE0;
             cmdl.Materials[i].FragShader.TextureCombiners[0].SrcAlpha = 0xEE0;
             for (int qq = 1; qq < 6; qq++)
             {
                 cmdl.Materials[i].FragShader.TextureCombiners[qq].SrcRgb = 0xEEF;
                 cmdl.Materials[i].FragShader.TextureCombiners[qq].SrcAlpha = 0xEEF;
             }
             Bitmap tex = Textures[MatLib.Materials.IndexOf(MatLib.GetMaterialByName(MatNames[i]))];
             if (tex != null)
             {
                 cmdl.Materials[i].NrActiveTextureCoordiators = 1;
                 cmdl.Materials[i].TextureCoordiators[0].Scale = new LibEveryFileExplorer.Collections.Vector2(1, 1);
                 cmdl.Materials[i].Tex0 = new CMDL.MTOB.TexInfo(MatNames[i]);
                 cmdl.Materials[i].FragShader.TextureCombiners[0].SrcRgb = 0xE30;
                 cmdl.Materials[i].FragShader.TextureCombiners[0].SrcAlpha = 0xE30;
                 cmdl.Materials[i].FragShader.TextureCombiners[0].CombineRgb = 1;
                 cmdl.Materials[i].FragShader.TextureCombiners[0].CombineAlpha = 1;
             }
         }
     }
     //Shapes
     {
         cmdl.NrShapes = (uint)MatNames.Count;
         cmdl.Shapes = new CMDL.SeparateDataShape[MatNames.Count];
         for (int i = 0; i < MatNames.Count; i++)
         {
             cmdl.Shapes[i] = new CMDL.SeparateDataShape();
             Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
             Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
             int nrfaces = 0;
             bool texcoords = false;
             foreach (var f in Model.Faces)
             {
                 if (f.Material != MatNames[i]) continue;
                 nrfaces++;
                 if (f.TexCoordIndieces.Count > 0) texcoords = true;
                 foreach (var qqq in f.VertexIndieces)
                 {
                     if (Model.Vertices[qqq].X < min.X) min.X = Model.Vertices[qqq].X;
                     if (Model.Vertices[qqq].Y < min.Y) min.Y = Model.Vertices[qqq].Y;
                     if (Model.Vertices[qqq].Z < min.Z) min.Z = Model.Vertices[qqq].Z;
                     if (Model.Vertices[qqq].X > max.X) max.X = Model.Vertices[qqq].X;
                     if (Model.Vertices[qqq].Y > max.Y) max.Y = Model.Vertices[qqq].Y;
                     if (Model.Vertices[qqq].Z > max.Z) max.Z = Model.Vertices[qqq].Z;
                 }
             }
             ((OrientedBoundingBox)cmdl.Shapes[i].BoundingBox).CenterPosition = (min + max) / 2;
             ((OrientedBoundingBox)cmdl.Shapes[i].BoundingBox).Size = max - min;
             cmdl.Shapes[i].NrPrimitiveSets = 1;
             cmdl.Shapes[i].PrimitiveSets = new CMDL.SeparateDataShape.PrimitiveSet[1];
             cmdl.Shapes[i].PrimitiveSets[0] = new CMDL.SeparateDataShape.PrimitiveSet();
             cmdl.Shapes[i].PrimitiveSets[0].NrPrimitives = 1;
             cmdl.Shapes[i].PrimitiveSets[0].Primitives = new CMDL.SeparateDataShape.PrimitiveSet.Primitive[1];
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0] = new CMDL.SeparateDataShape.PrimitiveSet.Primitive();
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].NrBufferObjects = 1;
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].BufferObjects = new uint[] { 0 };
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].NrIndexStreams = 1;
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams = new CMDL.SeparateDataShape.PrimitiveSet.Primitive.IndexStreamCtr[1];
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0] = new CMDL.SeparateDataShape.PrimitiveSet.Primitive.IndexStreamCtr();
             if (nrfaces * 3 > 255) cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FormatType = 0x1403;
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceDataLength = (uint)(nrfaces * 3 * ((nrfaces * 3 > 255) ? 2 : 1));
             cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData = new byte[cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceDataLength];
             int offs = 0;
             int idx = 0;
             foreach (var f in Model.Faces)
             {
                 if (f.Material != MatNames[i]) continue;
                 if (nrfaces * 3 > 255)
                 {
                     IOUtil.WriteU16LE(cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData, offs, (ushort)idx);
                     IOUtil.WriteU16LE(cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData, offs + 2, (ushort)(idx + 1));
                     IOUtil.WriteU16LE(cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData, offs + 4, (ushort)(idx + 2));
                     offs += 2 * 3;
                 }
                 else
                 {
                     cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData[idx] = (byte)idx;
                     cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData[idx + 1] = (byte)(idx + 1);
                     cmdl.Shapes[i].PrimitiveSets[0].Primitives[0].IndexStreams[0].FaceData[idx + 2] = (byte)(idx + 2);
                     offs += 3;
                 }
                 idx += 3;
             }
             cmdl.Shapes[i].NrVertexAttributes = 2;
             cmdl.Shapes[i].VertexAttributes = new CMDL.SeparateDataShape.VertexAttributeCtr[2];
             //interleaved
             cmdl.Shapes[i].VertexAttributes[0] = new CMDL.SeparateDataShape.InterleavedVertexStreamCtr();
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).NrVertexStreams = (texcoords ? 2u : 1u);
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexStreams = new CMDL.SeparateDataShape.InterleavedVertexStreamCtr.VertexStreamCtr[texcoords ? 2 : 1];
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexStreams[0] = new CMDL.SeparateDataShape.InterleavedVertexStreamCtr.VertexStreamCtr(CMDL.SeparateDataShape.VertexAttributeCtr.VertexAttributeUsage.Position, CMDL.SeparateDataShape.DataType.GL_FLOAT, 3, 0);
             if (texcoords) ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexStreams[1] = new CMDL.SeparateDataShape.InterleavedVertexStreamCtr.VertexStreamCtr(CMDL.SeparateDataShape.VertexAttributeCtr.VertexAttributeUsage.TextureCoordinate0, CMDL.SeparateDataShape.DataType.GL_FLOAT, 2, 12);
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexDataEntrySize = (texcoords ? 20u : 12u);
             byte[] Result = new byte[nrfaces * 3 * ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexDataEntrySize];
             offs = 0;
             foreach (var f in Model.Faces)
             {
                 if (f.Material != MatNames[i]) continue;
                 for (int qqq = 0; qqq < 3; qqq++)
                 {
                     Vector3 Pos = Model.Vertices[f.VertexIndieces[qqq]];
                     IOUtil.WriteSingleLE(Result, offs, Pos.X);
                     IOUtil.WriteSingleLE(Result, offs + 4, Pos.Y);
                     IOUtil.WriteSingleLE(Result, offs + 8, Pos.Z);
                     offs += 12;
                     if (texcoords)
                     {
                         Vector2 Tex = Model.TexCoords[f.TexCoordIndieces[qqq]];
                         IOUtil.WriteSingleLE(Result, offs, Tex.X);
                         IOUtil.WriteSingleLE(Result, offs + 4, Tex.Y);
                         offs += 8;
                     }
                 }
             }
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexStreamLength = (uint)Result.Length;
             ((CMDL.SeparateDataShape.InterleavedVertexStreamCtr)cmdl.Shapes[i].VertexAttributes[0]).VertexStream = Result;
             //color
             cmdl.Shapes[i].VertexAttributes[1] = new CMDL.SeparateDataShape.VertexParamAttributeCtr(CMDL.SeparateDataShape.VertexAttributeCtr.VertexAttributeUsage.Color, 1, 1, 1, MatLib.GetMaterialByName(MatNames[i]).Alpha);
         }
     }
     if (NrTextures != 0)
     {
         c.Data.Dictionaries[1] = new DICT();
         c.Data.Textures = new TXOB[NrTextures];
         int qqq = 0;
         int idx = 0;
         foreach (Bitmap b in Textures)
         {
             if (b == null) { qqq++; continue; }
             c.Data.Dictionaries[1].Add(MatLib.Materials[qqq].Name);
             c.Data.Textures[idx] = new ImageTextureCtr(MatLib.Materials[qqq].Name, b, GPU.Textures.ImageFormat.ETC1A4);
             idx++;
             qqq++;
         }
     }
 }