Esempio n. 1
0
		// Read a camera definition from a file.
		//
		// This function is called by lib3ds_file_read(), and you probably
		// don't want to call it directly.
		//
		// \param camera A Lib3dsCamera to be filled in.
		// \param io A Lib3dsIo object previously set up by the caller.
		//
		// \see lib3ds_file_read
		public static void lib3ds_camera_read(Lib3dsCamera camera, Lib3dsIo io)
		{
			Lib3dsChunk c=new Lib3dsChunk();
			Lib3dsChunks chunk;

			lib3ds_chunk_read_start(c, Lib3dsChunks.CHK_N_CAMERA, io);

			for(int i=0; i<3; i++) camera.position[i]=lib3ds_io_read_float(io);
			for(int i=0; i<3; i++) camera.target[i]=lib3ds_io_read_float(io);
			camera.roll=lib3ds_io_read_float(io);

			float s=lib3ds_io_read_float(io);
			if(Math.Abs(s)<EPSILON) camera.fov=45.0f;
			else camera.fov=2400.0f/s;

			lib3ds_chunk_read_tell(c, io);

			while((chunk=lib3ds_chunk_read_next(c, io))!=0)
			{
				switch(chunk)
				{
					case Lib3dsChunks.CHK_CAM_SEE_CONE: camera.see_cone=true; break;
					case Lib3dsChunks.CHK_CAM_RANGES:
						camera.near_range=lib3ds_io_read_float(io);
						camera.far_range=lib3ds_io_read_float(io);
						break;
					default: lib3ds_chunk_unknown(chunk, io); break;
				}
			}

			lib3ds_chunk_read_end(c, io);
		}
Esempio n. 2
0
 public static void lib3ds_file_insert_camera(Lib3dsFile file, Lib3dsCamera camera, int index)
 {
     Debug.Assert(file != null);
     if (index < 0)
     {
         file.cameras.Add(camera);
     }
     else
     {
         file.cameras.Insert(index, camera);
     }
 }
Esempio n. 3
0
        public static Lib3dsTargetNode lib3ds_node_new_camera_target(Lib3dsCamera camera)
        {
            Debug.Assert(camera != null);
            Lib3dsNode node = lib3ds_node_new(Lib3dsNodeType.LIB3DS_NODE_CAMERA_TARGET);

            node.name = camera.name;

            Lib3dsTargetNode n = (Lib3dsTargetNode)node;

            lib3ds_track_resize(n.pos_track, 1);
            lib3ds_vector_copy(n.pos_track.keys[0].value, camera.target);

            return(n);
        }
Esempio n. 4
0
 // Return a new Lib3dsCamera object.
 //
 // Object is initialized with the given name and fov=45.  All other
 // values are 0.
 //
 // \param name Name of this camera.  Must not be NULL.  Must be < 64 characters.
 //
 // \return Lib3dsCamera object or NULL on failure.
 public static Lib3dsCamera lib3ds_camera_new(string name)
 {
     Debug.Assert(name != null);
     Debug.Assert(name.Length < 64);
     try
     {
         Lib3dsCamera camera = new Lib3dsCamera();
         camera.name = name;
         camera.fov  = 45.0f;
         return(camera);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 5
0
		// Return a new Lib3dsCamera object.
		//
		// Object is initialized with the given name and fov=45.  All other
		// values are 0.
		//
		// \param name Name of this camera.  Must not be NULL.  Must be < 64 characters.
		//
		// \return Lib3dsCamera object or NULL on failure.
		public static Lib3dsCamera lib3ds_camera_new(string name)
		{
			Debug.Assert(name!=null);
			Debug.Assert(name.Length<64);
			try
			{
				Lib3dsCamera camera=new Lib3dsCamera();
				camera.name=name;
				camera.fov=45.0f;
				return camera;
			}
			catch
			{
				return null;
			}
		}
Esempio n. 6
0
        // Read a camera definition from a file.
        //
        // This function is called by lib3ds_file_read(), and you probably
        // don't want to call it directly.
        //
        // \param camera A Lib3dsCamera to be filled in.
        // \param io A Lib3dsIo object previously set up by the caller.
        //
        // \see lib3ds_file_read
        public static void lib3ds_camera_read(Lib3dsCamera camera, Lib3dsIo io)
        {
            Lib3dsChunk  c = new Lib3dsChunk();
            Lib3dsChunks chunk;

            lib3ds_chunk_read_start(c, Lib3dsChunks.CHK_N_CAMERA, io);

            for (int i = 0; i < 3; i++)
            {
                camera.position[i] = lib3ds_io_read_float(io);
            }
            for (int i = 0; i < 3; i++)
            {
                camera.target[i] = lib3ds_io_read_float(io);
            }
            camera.roll = lib3ds_io_read_float(io);

            float s = lib3ds_io_read_float(io);

            if (Math.Abs(s) < EPSILON)
            {
                camera.fov = 45.0f;
            }
            else
            {
                camera.fov = 2400.0f / s;
            }

            lib3ds_chunk_read_tell(c, io);

            while ((chunk = lib3ds_chunk_read_next(c, io)) != 0)
            {
                switch (chunk)
                {
                case Lib3dsChunks.CHK_CAM_SEE_CONE: camera.see_cone = true; break;

                case Lib3dsChunks.CHK_CAM_RANGES:
                    camera.near_range = lib3ds_io_read_float(io);
                    camera.far_range  = lib3ds_io_read_float(io);
                    break;

                default: lib3ds_chunk_unknown(chunk, io); break;
                }
            }

            lib3ds_chunk_read_end(c, io);
        }
Esempio n. 7
0
        public static Lib3dsCameraNode lib3ds_node_new_camera(Lib3dsCamera camera)
        {
            Debug.Assert(camera != null);
            Lib3dsNode node = lib3ds_node_new(Lib3dsNodeType.LIB3DS_NODE_CAMERA);

            node.name = camera.name;

            Lib3dsCameraNode n = (Lib3dsCameraNode)node;

            lib3ds_track_resize(n.pos_track, 1);
            lib3ds_vector_copy(n.pos_track.keys[0].value, camera.position);

            lib3ds_track_resize(n.fov_track, 1);
            n.fov_track.keys[0].value[0] = camera.fov;

            lib3ds_track_resize(n.roll_track, 1);
            n.roll_track.keys[0].value[0] = camera.roll;

            return(n);
        }
Esempio n. 8
0
        // Write a camera definition to a file.
        //
        // This function is called by lib3ds_file_write(), and you probably
        // don't want to call it directly.
        //
        // \param camera A Lib3dsCamera to be written.
        // \param io A Lib3dsIo object previously set up by the caller.
        //
        // \see lib3ds_file_write
        public static void lib3ds_camera_write(Lib3dsCamera camera, Lib3dsIo io)
        {
            Lib3dsChunk c_n_camera = new Lib3dsChunk();

            c_n_camera.chunk = Lib3dsChunks.CHK_N_CAMERA;
            lib3ds_chunk_write_start(c_n_camera, io);

            lib3ds_io_write_vector(io, camera.position);
            lib3ds_io_write_vector(io, camera.target);
            lib3ds_io_write_float(io, camera.roll);
            if (Math.Abs(camera.fov) < EPSILON)
            {
                lib3ds_io_write_float(io, 2400.0f / 45.0f);
            }
            else
            {
                lib3ds_io_write_float(io, 2400.0f / camera.fov);
            }

            if (camera.see_cone)
            {
                Lib3dsChunk c = new Lib3dsChunk();
                c.chunk = Lib3dsChunks.CHK_CAM_SEE_CONE;
                c.size  = 6;
                lib3ds_chunk_write(c, io);
            }

            Lib3dsChunk c_cam_ranges = new Lib3dsChunk();

            c_cam_ranges.chunk = Lib3dsChunks.CHK_CAM_RANGES;
            c_cam_ranges.size  = 14;
            lib3ds_chunk_write(c_cam_ranges, io);
            lib3ds_io_write_float(io, camera.near_range);
            lib3ds_io_write_float(io, camera.far_range);

            lib3ds_chunk_write_end(c_n_camera, io);
        }
Esempio n. 9
0
		static void camera_dump(Lib3dsCamera camera)
		{
			Debug.Assert(camera!=null);

			Console.WriteLine("  name:       {0}", camera.name);
			Console.WriteLine("  position:   ({0},{1},{2})", camera.position[0], camera.position[1], camera.position[2]);
			Console.WriteLine("  target      ({0},{1},{2})", camera.target[0], camera.target[1], camera.target[2]);
			Console.WriteLine("  roll:       {0}", camera.roll);
			Console.WriteLine("  fov:        {0}", camera.fov);
			Console.WriteLine("  see_cone:   {0}", camera.see_cone?"yes":"no");
			Console.WriteLine("  near_range: {0}", camera.near_range);
			Console.WriteLine("  far_range:  {0}", camera.far_range);
			Console.WriteLine();
		}
Esempio n. 10
0
		public static Lib3dsTargetNode lib3ds_node_new_camera_target(Lib3dsCamera camera)
		{
			Debug.Assert(camera!=null);
			Lib3dsNode node=lib3ds_node_new(Lib3dsNodeType.LIB3DS_NODE_CAMERA_TARGET);
			node.name=camera.name;

			Lib3dsTargetNode n=(Lib3dsTargetNode)node;
			lib3ds_track_resize(n.pos_track, 1);
			lib3ds_vector_copy(n.pos_track.keys[0].value, camera.target);

			return n;
		}
Esempio n. 11
0
		public static Lib3dsCameraNode lib3ds_node_new_camera(Lib3dsCamera camera)
		{
			Debug.Assert(camera!=null);
			Lib3dsNode node=lib3ds_node_new(Lib3dsNodeType.LIB3DS_NODE_CAMERA);
			node.name=camera.name;

			Lib3dsCameraNode n=(Lib3dsCameraNode)node;
			lib3ds_track_resize(n.pos_track, 1);
			lib3ds_vector_copy(n.pos_track.keys[0].value, camera.position);

			lib3ds_track_resize(n.fov_track, 1);
			n.fov_track.keys[0].value[0]=camera.fov;

			lib3ds_track_resize(n.roll_track, 1);
			n.roll_track.keys[0].value[0]=camera.roll;

			return n;
		}
Esempio n. 12
0
		public static void lib3ds_file_insert_camera(Lib3dsFile file, Lib3dsCamera camera, int index)
		{
			Debug.Assert(file!=null);
			if(index<0) file.cameras.Add(camera);
			else file.cameras.Insert(index, camera);
		}
Esempio n. 13
0
 // Free a Lib3dsCamera object and all of its resources.
 //
 // \param camera Lib3dsCamera object to be freed.
 public static void lib3ds_camera_free(Lib3dsCamera camera)
 {
 }
Esempio n. 14
0
		// Write a camera definition to a file.
		//
		// This function is called by lib3ds_file_write(), and you probably
		// don't want to call it directly.
		//
		// \param camera A Lib3dsCamera to be written.
		// \param io A Lib3dsIo object previously set up by the caller.
		//
		// \see lib3ds_file_write
		public static void lib3ds_camera_write(Lib3dsCamera camera, Lib3dsIo io)
		{
			Lib3dsChunk c_n_camera=new Lib3dsChunk();

			c_n_camera.chunk=Lib3dsChunks.CHK_N_CAMERA;
			lib3ds_chunk_write_start(c_n_camera, io);

			lib3ds_io_write_vector(io, camera.position);
			lib3ds_io_write_vector(io, camera.target);
			lib3ds_io_write_float(io, camera.roll);
			if(Math.Abs(camera.fov)<EPSILON) lib3ds_io_write_float(io, 2400.0f/45.0f);
			else lib3ds_io_write_float(io, 2400.0f/camera.fov);

			if(camera.see_cone)
			{
				Lib3dsChunk c=new Lib3dsChunk();
				c.chunk=Lib3dsChunks.CHK_CAM_SEE_CONE;
				c.size=6;
				lib3ds_chunk_write(c, io);
			}

			Lib3dsChunk c_cam_ranges=new Lib3dsChunk();
			c_cam_ranges.chunk=Lib3dsChunks.CHK_CAM_RANGES;
			c_cam_ranges.size=14;
			lib3ds_chunk_write(c_cam_ranges, io);
			lib3ds_io_write_float(io, camera.near_range);
			lib3ds_io_write_float(io, camera.far_range);

			lib3ds_chunk_write_end(c_n_camera, io);
		}
Esempio n. 15
0
		// Free a Lib3dsCamera object and all of its resources.
		//
		// \param camera Lib3dsCamera object to be freed.
		public static void lib3ds_camera_free(Lib3dsCamera camera)
		{
		}
Esempio n. 16
0
        static void named_object_read(Lib3dsFile file, Lib3dsIo io)
        {
            Lib3dsChunk  c = new Lib3dsChunk();
            string       name;
            Lib3dsChunks chunk;

            Lib3dsMesh        mesh         = null;
            Lib3dsCamera      camera       = null;
            Lib3dsLight       light        = null;
            Lib3dsObjectFlags object_flags = 0;

            lib3ds_chunk_read_start(c, Lib3dsChunks.CHK_NAMED_OBJECT, io);

            name = lib3ds_io_read_string(io, 64);
            lib3ds_io_log(io, Lib3dsLogLevel.LIB3DS_LOG_INFO, "NAME={0}", name);
            lib3ds_chunk_read_tell(c, io);

            while ((chunk = lib3ds_chunk_read_next(c, io)) != 0)
            {
                switch (chunk)
                {
                case Lib3dsChunks.CHK_N_TRI_OBJECT:
                    mesh = lib3ds_mesh_new(name);
                    lib3ds_file_insert_mesh(file, mesh, -1);
                    lib3ds_chunk_read_reset(c, io);
                    lib3ds_mesh_read(file, mesh, io);
                    break;

                case Lib3dsChunks.CHK_N_CAMERA:
                    camera = lib3ds_camera_new(name);
                    lib3ds_file_insert_camera(file, camera, -1);
                    lib3ds_chunk_read_reset(c, io);
                    lib3ds_camera_read(camera, io);
                    break;

                case Lib3dsChunks.CHK_N_DIRECT_LIGHT:
                    light = lib3ds_light_new(name);
                    lib3ds_file_insert_light(file, light, -1);
                    lib3ds_chunk_read_reset(c, io);
                    lib3ds_light_read(light, io);
                    break;

                case Lib3dsChunks.CHK_OBJ_HIDDEN: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_HIDDEN; break;

                case Lib3dsChunks.CHK_OBJ_DOESNT_CAST: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_DOESNT_CAST; break;

                case Lib3dsChunks.CHK_OBJ_VIS_LOFTER: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_VIS_LOFTER; break;

                case Lib3dsChunks.CHK_OBJ_MATTE: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_MATTE; break;

                case Lib3dsChunks.CHK_OBJ_DONT_RCVSHADOW: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_DONT_RCVSHADOW; break;

                case Lib3dsChunks.CHK_OBJ_FAST: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_FAST; break;

                case Lib3dsChunks.CHK_OBJ_FROZEN: object_flags |= Lib3dsObjectFlags.LIB3DS_OBJECT_FROZEN; break;

                default: lib3ds_chunk_unknown(chunk, io); break;
                }
            }

            if (mesh != null)
            {
                mesh.object_flags = object_flags;
            }
            if (camera != null)
            {
                camera.object_flags = object_flags;
            }
            if (light != null)
            {
                light.object_flags = object_flags;
            }

            lib3ds_chunk_read_end(c, io);
        }