Exemplo n.º 1
0
        public IModel Duplicate(string name, float height)
        {
            Actor dup = new Actor();

            dup._model = this._model.Duplicate(name);
            dup._model.SetPosition(0, 0, 0);
            dup._model.SetRotation(0, 0, 0);
            dup._key = name;


            DxVBLibA.D3DVECTOR boxmin = new DxVBLibA.D3DVECTOR();
            DxVBLibA.D3DVECTOR boxmax = new DxVBLibA.D3DVECTOR();
            dup._model.GetBoundingBox(ref boxmin, ref boxmax);

            // TODO: get bounding boxes dependent upon the animation sequence

            // EEERRR todo: there is a bug in tv3d mdl bounding boxes,
            // we need to transpose for it
            dup._boxmin = new Vector3D(boxmin.y, boxmin.z, boxmin.x);
            dup._boxmax = new Vector3D(boxmax.y, boxmax.z, boxmax.x);

            // todo: use a bounding cylinder instead, would be bett0r!

            dup._height = height;
            if (height != 0)
            {
                // scale the model to the correct height and get new bounding box info
                float scale_factor = height / (dup._boxmax.Y - dup._boxmin.Y);
                dup._model.SetScale(scale_factor, scale_factor, scale_factor);
                dup._boxmin.X *= scale_factor;
                dup._boxmin.Y *= scale_factor;
                dup._boxmin.Z *= scale_factor;
                dup._boxmax.X *= scale_factor;
                dup._boxmax.Y *= scale_factor;
                dup._boxmax.Z *= scale_factor;
            }
            float radius = 0;

            DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
            dup._model.GetBoundingSphere(ref center, ref radius);
            dup._RadiusSquared = radius * radius;
            dup._position      = new Math3D.Vector3D(0, 0, 0);
            // TODO: remove hardcoded initial rotation
            //dup._rotation = new Math3D.Vector3D( 0, 90, 0 );

            // todo: _offset is ghey I wish we could permenantly transpose
            // the object.
            // also, bounding box should be normalised around origin?
            dup._offset = new Math3D.Vector3D(
                (dup._boxmax.X + dup._boxmin.X) / 2,
                (dup._boxmax.Y + dup._boxmin.Y) / 2,
                (dup._boxmax.Z + dup._boxmin.Z) / 2
                );


            dup._id = dup._model.GetEntity();
            return(dup);
        }
Exemplo n.º 2
0
        public IModel Duplicate(string name, float height)
        {
            Model dup = new Model();

            dup._key  = name;
            dup._mesh = this._mesh.DuplicateMesh(name);
            dup._mesh.SetPosition(0, 0, 0);
            dup._mesh.SetRotation(0, 0, 0);

            //loadedModel._mesh.ShowBoundingBox( true );
            D3DVECTOR boxmin = new D3DVECTOR();
            D3DVECTOR boxmax = new D3DVECTOR();

            dup._mesh.GetBoundingBox(ref boxmin, ref boxmax, true);

            dup._height = height;
            if (height != 0)
            {
                // scale the model to the correct height and get new bounding box info
                float scale_factor = height / (boxmax.y - boxmin.y);
                dup._mesh.ScaleMesh(scale_factor, scale_factor, scale_factor);
                boxmin.x *= scale_factor;
                boxmin.y *= scale_factor;
                boxmin.z *= scale_factor;
                boxmax.x *= scale_factor;
                boxmax.y *= scale_factor;
                boxmax.z *= scale_factor;
            }
            dup._width  = Math.Max((boxmax.x - boxmin.x), (boxmax.z - boxmin.z));
            dup._depth  = Math.Min((boxmax.x - boxmin.x), (boxmax.z - boxmin.z));
            dup._boxmin = new Vector3D(boxmin.x, boxmin.y, boxmin.z);
            dup._boxmax = new Vector3D(boxmax.x, boxmax.y, boxmax.z);

            float radius = 0;

            DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
            dup._mesh.GetBoundingSphere(ref center, ref radius, true);
            dup._RadiusSquared = radius * radius;
            dup._position      = new Math3D.Vector3D(0, 0, 0);
            dup._rotation      = new Math3D.Vector3D(0, 0, 0);
            // TODO: could get rid of 'offset' if we prenormalize the models
            // outside
            dup._offset = new Math3D.Vector3D(
                (boxmax.x + boxmin.x) / 2,
                (boxmax.y + boxmin.y) / 2,
                (boxmax.z + boxmin.z) / 2
                );
            dup._id = dup._mesh.GetMeshIndex();
            return(dup);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load a model from file
        /// </summary>
        /// <param name="name"></param>
        /// <param name="path"></param>
        /// <param name="height">pass zero to retain original height</param>
        /// <returns></returns>
        public static IModel LoadStaticModel(string name, string path, float height)
        {
            if (!System.IO.File.Exists(path))
            {
                throw new System.IO.FileNotFoundException("Could not find model '" + path + "'", path);
            }

            Log.LogMessage("Loading static model " + path + name);

            Model loadedModel = new Model();

            loadedModel._key = name;
            try {
                loadedModel._mesh = Engine.TV3DScene.CreateMeshBuilder(name);
                loadedModel._mesh.Load3DSMesh(path, true, true, false, true, true);
            }
            catch (Exception e) {
                throw new ModelNotLoadedException(path, e);
            }

            //loadedModel._mesh.ShowBoundingBox( true );
            D3DVECTOR boxmin = new D3DVECTOR();
            D3DVECTOR boxmax = new D3DVECTOR();

            loadedModel._mesh.GetBoundingBox(ref boxmin, ref boxmax, true);
            loadedModel._height = height;
            if (height != 0)
            {
                // scale the model to the correct height and get new bounding box info
                float scale_factor = height / (boxmax.y - boxmin.y);
                loadedModel._mesh.ScaleMesh(scale_factor, scale_factor, scale_factor);
                boxmin.x *= scale_factor;
                boxmin.y *= scale_factor;
                boxmin.z *= scale_factor;
                boxmax.x *= scale_factor;
                boxmax.y *= scale_factor;
                boxmax.z *= scale_factor;
            }
            loadedModel._width  = Math.Max((boxmax.x - boxmin.x), (boxmax.z - boxmin.z));
            loadedModel._depth  = Math.Min((boxmax.x - boxmin.x), (boxmax.z - boxmin.z));
            loadedModel._boxmin = new Vector3D(boxmin.x, boxmin.y, boxmin.z);
            loadedModel._boxmax = new Vector3D(boxmax.x, boxmax.y, boxmax.z);

            loadedModel._mesh.Optimize();
            loadedModel._mesh.ComputeNormals();
            loadedModel._mesh.ComputeSphere();
            loadedModel._mesh.ComputeBoundingVolumes();
            //loadedModel._mesh.ShowBoundingBox( true );

            float radius = 0;

            DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
            loadedModel._mesh.GetBoundingSphere(ref center, ref radius, true);
            loadedModel._RadiusSquared = radius * radius;
            loadedModel._position      = new Math3D.Vector3D(0, 0, 0);
            loadedModel._rotation      = new Math3D.Vector3D(0, 0, 0);
            // TODO: could get rid of 'offset' if we prenormalize the models
            // outside
            loadedModel._offset = new Math3D.Vector3D(
                (boxmax.x + boxmin.x) / 2,
                (boxmax.y + boxmin.y) / 2,
                (boxmax.z + boxmin.z) / 2
                );
            loadedModel._id = loadedModel._mesh.GetMeshIndex();
            //loadedModel._mesh.InitLOD(0);
            return(loadedModel);
        }
Exemplo n.º 4
0
		/// <summary>
		/// Loads a model
		/// </summary>
		/// <param name="key">The key of the model</param>
		/// <param name="path">The path at which the model can be loaded</param>
		/// <param name="format">The format of the model</param>
		/// <returns>A reference to the loaded Model</returns>
		public static IActor LoadActor(string name, string path, float height ) {
			if(!System.IO.File.Exists(path)) {
				throw new System.IO.FileNotFoundException("Could not load model '" + path + "'", path);
			}
			
			Actor loadedModel = new Actor();

			loadedModel._key = name;

			try {
				//loadedModel._model = Engine.TV3DScene.CreateActorTVM( name );
				loadedModel._model = new TVActor2();
				loadedModel._model.Load( path, name, true, true );
			}
			catch(Exception e) {
				throw new ModelNotLoadedException(path, e);
			}
			DxVBLibA.D3DVECTOR boxmin = new DxVBLibA.D3DVECTOR();
			DxVBLibA.D3DVECTOR boxmax = new DxVBLibA.D3DVECTOR();
			loadedModel._model.GetBoundingBox( ref boxmin, ref boxmax );

			// TODO: get bounding boxes dependent upon the animation sequence

			// EEERRR todo: there is a bug in tv3d mdl bounding boxes,
			// we need to transpose for it
			loadedModel._boxmin = new Vector3D( boxmin.y, boxmin.z, boxmin.x );
			loadedModel._boxmax = new Vector3D( boxmax.y, boxmax.z, boxmax.x );

			// todo: use a bounding cylinder instead, would be bett0r!

			loadedModel._height = height;
			if ( height != 0 ) {
				// scale the model to the correct height and get new bounding box info
				float scale_factor = height / ( loadedModel._boxmax.Y - loadedModel._boxmin.Y );
				loadedModel._model.SetScale( scale_factor, scale_factor, scale_factor );
				loadedModel._boxmin.X *= scale_factor;
				loadedModel._boxmin.Y *= scale_factor;
				loadedModel._boxmin.Z *= scale_factor;
				loadedModel._boxmax.X *= scale_factor;
				loadedModel._boxmax.Y *= scale_factor;
				loadedModel._boxmax.Z *= scale_factor;
			}
			float radius = 0;
			DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
			loadedModel._model.GetBoundingSphere(ref center, ref radius );
			loadedModel._RadiusSquared = radius * radius;
			loadedModel._position = new Math3D.Vector3D( 0, 0, 0 );
			// TODO: remove hardcoded initial rotation
			//loadedModel._rotation = new Math3D.Vector3D( 0, 90, 0 );

			// todo: _offset is ghey I wish we could permenantly transpose
			// the object.
			// also, bounding box should be normalised around origin?
			loadedModel._offset = new Math3D.Vector3D(
				(loadedModel._boxmax.X + loadedModel._boxmin.X)/2,
				(loadedModel._boxmax.Y + loadedModel._boxmin.Y)/2,
				(loadedModel._boxmax.Z + loadedModel._boxmin.Z)/2
			);
			loadedModel._id = loadedModel._model.GetEntity();
			//loadedModel._model.ShowBoundingBox( true, false );
			loadedModel._model.PlayAnimation( 20 );
			return loadedModel;
		}
Exemplo n.º 5
0
		public IModel Duplicate( string name, float height ) 
		{
			Actor dup = new Actor();
			dup._model = this._model.Duplicate( name );
			dup._model.SetPosition( 0, 0, 0 );
			dup._model.SetRotation( 0, 0, 0 );
			dup._key = name;

			
			DxVBLibA.D3DVECTOR boxmin = new DxVBLibA.D3DVECTOR();
			DxVBLibA.D3DVECTOR boxmax = new DxVBLibA.D3DVECTOR();
			dup._model.GetBoundingBox( ref boxmin, ref boxmax );
			
			// TODO: get bounding boxes dependent upon the animation sequence

			// EEERRR todo: there is a bug in tv3d mdl bounding boxes,
			// we need to transpose for it
			dup._boxmin = new Vector3D( boxmin.y, boxmin.z, boxmin.x );
			dup._boxmax = new Vector3D( boxmax.y, boxmax.z, boxmax.x );

			// todo: use a bounding cylinder instead, would be bett0r!

			dup._height = height;
			if ( height != 0 ) {
				// scale the model to the correct height and get new bounding box info
				float scale_factor = height / ( dup._boxmax.Y - dup._boxmin.Y );
				dup._model.SetScale( scale_factor, scale_factor, scale_factor );
				dup._boxmin.X *= scale_factor;
				dup._boxmin.Y *= scale_factor;
				dup._boxmin.Z *= scale_factor;
				dup._boxmax.X *= scale_factor;
				dup._boxmax.Y *= scale_factor;
				dup._boxmax.Z *= scale_factor;
			}
			float radius = 0;
			DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
			dup._model.GetBoundingSphere(ref center, ref radius );
			dup._RadiusSquared = radius * radius;
			dup._position = new Math3D.Vector3D( 0, 0, 0 );
			// TODO: remove hardcoded initial rotation
			//dup._rotation = new Math3D.Vector3D( 0, 90, 0 );

			// todo: _offset is ghey I wish we could permenantly transpose
			// the object.
			// also, bounding box should be normalised around origin?
			dup._offset = new Math3D.Vector3D(
				(dup._boxmax.X + dup._boxmin.X)/2,
				(dup._boxmax.Y + dup._boxmin.Y)/2,
				(dup._boxmax.Z + dup._boxmin.Z)/2
				);


			dup._id = dup._model.GetEntity();
			return dup;
		}
Exemplo n.º 6
0
		/// <summary>
		/// Load a model from file
		/// </summary>
		/// <param name="name"></param>
		/// <param name="path"></param>
		/// <param name="height">pass zero to retain original height</param>
		/// <returns></returns>
		public static IModel LoadStaticModel( string name, string path, float height ) {
			if(!System.IO.File.Exists(path)) {
				throw new System.IO.FileNotFoundException("Could not find model '" + path + "'", path);
			}

			Log.LogMessage( "Loading static model " + path + name );

			Model loadedModel = new Model();
			loadedModel._key = name;
			try {
				loadedModel._mesh = Engine.TV3DScene.CreateMeshBuilder( name );
				loadedModel._mesh.Load3DSMesh( path, true, true, false, true, true );
			}
			catch(Exception e) {
				throw new ModelNotLoadedException(path, e);
			}

			//loadedModel._mesh.ShowBoundingBox( true );
			D3DVECTOR boxmin = new D3DVECTOR();
			D3DVECTOR boxmax = new D3DVECTOR();
			loadedModel._mesh.GetBoundingBox( ref boxmin, ref boxmax, true );
			loadedModel._height = height;
			if ( height != 0 ) {
				// scale the model to the correct height and get new bounding box info
				float scale_factor = height / ( boxmax.y - boxmin.y );
				loadedModel._mesh.ScaleMesh( scale_factor, scale_factor, scale_factor );
				boxmin.x *= scale_factor;
				boxmin.y *= scale_factor;
				boxmin.z *= scale_factor;
				boxmax.x *= scale_factor;
				boxmax.y *= scale_factor;
				boxmax.z *= scale_factor;
			}
			loadedModel._width = Math.Max( (boxmax.x - boxmin.x ), (boxmax.z - boxmin.z ) );
			loadedModel._depth = Math.Min( (boxmax.x - boxmin.x ), (boxmax.z - boxmin.z ) );
			loadedModel._boxmin = new Vector3D( boxmin.x, boxmin.y, boxmin.z );
			loadedModel._boxmax = new Vector3D( boxmax.x, boxmax.y, boxmax.z );

			loadedModel._mesh.Optimize();
			loadedModel._mesh.ComputeNormals();
			loadedModel._mesh.ComputeSphere();
			loadedModel._mesh.ComputeBoundingVolumes();
			//loadedModel._mesh.ShowBoundingBox( true );
			
			float radius = 0;
			DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
			loadedModel._mesh.GetBoundingSphere(ref center, ref radius, true );
			loadedModel._RadiusSquared = radius * radius;
			loadedModel._position = new Math3D.Vector3D( 0, 0, 0 );
			loadedModel._rotation = new Math3D.Vector3D( 0, 0, 0 );
			// TODO: could get rid of 'offset' if we prenormalize the models
			// outside
			loadedModel._offset = new Math3D.Vector3D(
				(boxmax.x + boxmin.x)/2,
				(boxmax.y + boxmin.y)/2,
				(boxmax.z + boxmin.z)/2
			);
			loadedModel._id = loadedModel._mesh.GetMeshIndex();
			//loadedModel._mesh.InitLOD(0);
			return loadedModel;
		}
Exemplo n.º 7
0
		public IModel Duplicate( string name, float height ) {
			Model dup = new Model();
			dup._key = name;
			dup._mesh = this._mesh.DuplicateMesh( name );
			dup._mesh.SetPosition( 0, 0, 0 );
			dup._mesh.SetRotation( 0, 0, 0 );

			//loadedModel._mesh.ShowBoundingBox( true );
			D3DVECTOR boxmin = new D3DVECTOR();
			D3DVECTOR boxmax = new D3DVECTOR();
			dup._mesh.GetBoundingBox( ref boxmin, ref boxmax, true );

			dup._height = height;
			if ( height != 0 ) {
				// scale the model to the correct height and get new bounding box info
				float scale_factor = height / ( boxmax.y - boxmin.y );
				dup._mesh.ScaleMesh( scale_factor, scale_factor, scale_factor );
				boxmin.x *= scale_factor;
				boxmin.y *= scale_factor;
				boxmin.z *= scale_factor;
				boxmax.x *= scale_factor;
				boxmax.y *= scale_factor;
				boxmax.z *= scale_factor;
			}
			dup._width = Math.Max( (boxmax.x - boxmin.x ), (boxmax.z - boxmin.z ) );
			dup._depth = Math.Min( (boxmax.x - boxmin.x ), (boxmax.z - boxmin.z ) );
			dup._boxmin = new Vector3D( boxmin.x, boxmin.y, boxmin.z );
			dup._boxmax = new Vector3D( boxmax.x, boxmax.y, boxmax.z );

			float radius = 0;
			DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
			dup._mesh.GetBoundingSphere(ref center, ref radius, true );
			dup._RadiusSquared = radius * radius;
			dup._position = new Math3D.Vector3D( 0, 0, 0 );
			dup._rotation = new Math3D.Vector3D( 0, 0, 0 );
			// TODO: could get rid of 'offset' if we prenormalize the models
			// outside
			dup._offset = new Math3D.Vector3D(
				(boxmax.x + boxmin.x)/2,
				(boxmax.y + boxmin.y)/2,
				(boxmax.z + boxmin.z)/2
				);
			dup._id = dup._mesh.GetMeshIndex();
			return dup;
		}
Exemplo n.º 8
0
        /// <summary>
        /// Loads a model
        /// </summary>
        /// <param name="key">The key of the model</param>
        /// <param name="path">The path at which the model can be loaded</param>
        /// <param name="format">The format of the model</param>
        /// <returns>A reference to the loaded Model</returns>
        public static IActor LoadActor(string name, string path, float height)
        {
            if (!System.IO.File.Exists(path))
            {
                throw new System.IO.FileNotFoundException("Could not load model '" + path + "'", path);
            }

            Actor loadedModel = new Actor();

            loadedModel._key = name;

            try {
                //loadedModel._model = Engine.TV3DScene.CreateActorTVM( name );
                loadedModel._model = new TVActor2();
                loadedModel._model.Load(path, name, true, true);
            }
            catch (Exception e) {
                throw new ModelNotLoadedException(path, e);
            }
            DxVBLibA.D3DVECTOR boxmin = new DxVBLibA.D3DVECTOR();
            DxVBLibA.D3DVECTOR boxmax = new DxVBLibA.D3DVECTOR();
            loadedModel._model.GetBoundingBox(ref boxmin, ref boxmax);

            // TODO: get bounding boxes dependent upon the animation sequence

            // EEERRR todo: there is a bug in tv3d mdl bounding boxes,
            // we need to transpose for it
            loadedModel._boxmin = new Vector3D(boxmin.y, boxmin.z, boxmin.x);
            loadedModel._boxmax = new Vector3D(boxmax.y, boxmax.z, boxmax.x);

            // todo: use a bounding cylinder instead, would be bett0r!

            loadedModel._height = height;
            if (height != 0)
            {
                // scale the model to the correct height and get new bounding box info
                float scale_factor = height / (loadedModel._boxmax.Y - loadedModel._boxmin.Y);
                loadedModel._model.SetScale(scale_factor, scale_factor, scale_factor);
                loadedModel._boxmin.X *= scale_factor;
                loadedModel._boxmin.Y *= scale_factor;
                loadedModel._boxmin.Z *= scale_factor;
                loadedModel._boxmax.X *= scale_factor;
                loadedModel._boxmax.Y *= scale_factor;
                loadedModel._boxmax.Z *= scale_factor;
            }
            float radius = 0;

            DxVBLibA.D3DVECTOR center = new DxVBLibA.D3DVECTOR();
            loadedModel._model.GetBoundingSphere(ref center, ref radius);
            loadedModel._RadiusSquared = radius * radius;
            loadedModel._position      = new Math3D.Vector3D(0, 0, 0);
            // TODO: remove hardcoded initial rotation
            //loadedModel._rotation = new Math3D.Vector3D( 0, 90, 0 );

            // todo: _offset is ghey I wish we could permenantly transpose
            // the object.
            // also, bounding box should be normalised around origin?
            loadedModel._offset = new Math3D.Vector3D(
                (loadedModel._boxmax.X + loadedModel._boxmin.X) / 2,
                (loadedModel._boxmax.Y + loadedModel._boxmin.Y) / 2,
                (loadedModel._boxmax.Z + loadedModel._boxmin.Z) / 2
                );
            loadedModel._id = loadedModel._model.GetEntity();
            //loadedModel._model.ShowBoundingBox( true, false );
            loadedModel._model.PlayAnimation(20);
            return(loadedModel);
        }