Пример #1
0
        public Vivid3D.Scene.GraphNode3D ImportMesh(string file, Vivid3D.Scene.SceneGraph3D graph)
        {
            gr = graph;
            _F = new FileStream(file, FileMode.Open, FileAccess.Read);

            if (_F == null)
            {
                Console.WriteLine("Unable to open V3DM file.");
                return(null);
            }
            _R = new BinaryReader(_F);

            // CheckHeader ( );

            Vivid3D.Scene.GraphEntity3D root = new Vivid3D.Scene.GraphEntity3D
            {
                LocalTurn = Matrix4.Identity
            };

            int nc = ReadInt();

            Console.WriteLine("TopLevelNodes:" + nc);

            for (int i = 0; i < nc; i++)
            {
                root.Add(ReadNodes( ));
            }

            return(root);

            return(null);
        }
Пример #2
0
        private Vivid3D.Scene.GraphEntity3D ReadNodes( )
        {
            Vivid3D.Scene.GraphEntity3D vn = new Vivid3D.Scene.GraphEntity3D();

            string node_name = ReadString( );

            Console.WriteLine("Node:" + node_name);
            vn.Name = node_name;
            OpenTK.Matrix4 lmat = ReadMatrix4( );
            Matrix4        omat = ReadMatrix4();
            Matrix4        wmat = ReadMatrix4();
            Matrix4        nmat = ReadMatrix4();
            Quaternion     qr   = ReadQuat();
            //mat.Transpose ( );
            Matrix4 mat = Matrix4.Identity;

            vn.LocalPos = FixP(mat.ExtractTranslation( ));
            //vn.LocalPos = new Vector3 ( vn.LocalPos.X, -vn.LocalPos.Y, vn.LocalPos.Z );
            //vn.LocalScale = mat.ExtractScale ( );
            mat = mat.ClearTranslation( );
            mat = mat.ClearScale( );
            //mat.Transpose ( );
            //Vector4 c0= mat.Column1;
            //mat.Column1 = mat.Column2;
            //mat.Column2 = c0;
            //float cx = mat.Column0.X;
            //Vector4 c0 = mat.Column0;
            //c0.X = c0.Y;
            //c0.Y = cx;
            // mat.Column0 = c0;
            //mat.Column0.X = mat.Column0.Y;
            Matrix4 lm = Matrix4.CreateFromQuaternion(qr);

            //vn.LocalTurn = Ma mat; //mat;// Matrix4.Identity;
            vn.LocalTurn = lmat;
            //Console.WriteLine ( "Quat:" + qr );
            int eType = ReadInt();

            switch (eType)
            {
            case 1:
                Vivid3D.Lighting.GraphLight3D new_light = new Vivid3D.Lighting.GraphLight3D();
                Console.WriteLine("Is Light");
                gr.Lights.Add(new_light);
                new_light.Name     = node_name;
                new_light.LocalPos = FixP(omat.ExtractTranslation( ));

                break;

            case 2:
                LoadNode(vn);

                break;
            }

            int nc = ReadInt();

            //int nc=0;
            Console.WriteLine("childNodes:" + nc);

            for (int i = 0; i < nc; i++)
            {
                vn.Add(ReadNodes( ));
            }
            // _R.ReadInt32 ( );
            return(vn);
        }
Пример #3
0
        private void LoadNode(Vivid3D.Scene.GraphEntity3D vn)
        {
            int vc = ReadInt();

            //Console.WriteLine ( "verts:" + vc );
            List <OpenTK.Vector3> normL = new List <Vector3>();
            List <Vector3>        tanL  = new List <Vector3>();
            List <Vector3>        biL   = new List <Vector3>();
            List <OpenTK.Vector3> posL  = new List <OpenTK.Vector3>();
            List <Vector3>        uvL   = new List <Vector3>();

            //Vivid3D.Data.VMesh msh = new Vivid3D.Data.VMesh ( ic, vc );
            for (int v = 0; v < vc; v++)
            {
                OpenTK.Vector3 v_pos = ReadVec3( );

                Vector3 n = ReadVec3();
                //float ny = n.Y;
                //n.Y = n.Y;
                //n.Z = ny
                ;

                Vector3 t  = ReadVec3();
                Vector3 b  = ReadVec3();
                Vector3 uv = ReadVec3();
                uv.Y = 1 - uv.Y;
                uv.X = 1 - uv.X;
                //posL.Add ( v_pos );
                //float vy = v_pos.Y;
                //v_pos.Y = v_pos.Z;
                //v_pos.X = vy;
                //v_pos.Y = -v_pos.Y;
                // float vX = v_pos.X;
                //  v_pos.X = v_pos.Z;
                //   v_pos.Z = vX;
                //     float vX = v_pos.X;
                //   v_pos.X = v_pos.Z;
                //  v_pos.Z = -vX;
                //  vX = v_pos.X;
                // v_pos.X = v_pos.Y;
                // v_pos.Y = vX;

                posL.Add(v_pos);
                normL.Add(n);
                tanL.Add(t);
                biL.Add(b);
                uvL.Add(uv);

                //Console.WriteLine ( "V:" + v_pos );
            }

            int ic = ReadInt();

            int vi = 0;

            Vivid3D.Data.VMesh msh = new Vivid3D.Data.VMesh(ic * 3, vc);
            foreach (Vector3 vp in posL)
            {
                Vector3 vt  = tanL[vi];
                Vector3 vb  = biL[vi];
                Vector3 vn2 = normL[vi];
                Vector2 vuv = new Vector2(uvL[vi].X, uvL[vi].Y);
                Console.WriteLine("uv:" + uvL [vi].ToString( ));
                msh.SetVertex(vi, vp, vt, vb, vn2, vuv);

                vi++;
            }

            for (int f = 0; f < ic; f++)
            {
                int v0, v1, v2;
                v0 = ReadInt( ); v1 = ReadInt( ); v2 = ReadInt( );
                msh.SetTri(f, v0, v1, v2);
            }

            string mat_name = ReadString();

            Console.WriteLine("Mat:" + mat_name);
            int texc = ReadInt();

            Console.WriteLine("TexMaps:" + texc);
            string[] texs = new string[texc];
            for (int i = 0; i < texc; i++)
            {
                string tex_file = ReadString();
                texs [i] = tex_file;
                Console.WriteLine("TexFile:" + tex_file);
            }

            // Matrix4 tm = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-180)); msh.Transform
            // ( tm );

            //tm = tm * Matrix4.CreateRotationY ( MathHelper.DegreesToRadians ( 90 ) );
            // msh.Transform ( tm );

            //tm = tm * Matrix4.CreateRotationX ( MathHelper.DegreesToRadians ( 90 ) );
            // msh.Transform ( tm );

            Matrix4 tm = Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(90));

            tm = tm * Matrix4.CreateRotationX(MathHelper.DegreesToRadians(-90));

            vn.LocalTurn = vn.LocalTurn * tm;

            msh.Mat = new Vivid3D.Material.Material3D
            {
                TCol = new Vivid3D.Texture.VTex2D(texs [0], Vivid3D.Texture.LoadMethod.Single, true)
            };

            vn.AddMesh(msh);
            msh.GenerateTangents( );
            msh.Final( );
        }