コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: Model.cs プロジェクト: 628426/Strive.NET
		/// <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;
		}
コード例 #4
0
ファイル: Model.cs プロジェクト: 628426/Strive.NET
		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;
		}