public void Assign(QueuedSubMesh qsm, ushort atlod) { var q = new QueuedGeometry(); this.queuedGeometryList.Add(q); q.position = qsm.position; q.orientation = qsm.orientation; q.scale = qsm.scale; if (qsm.geometryLodList.Count > atlod) { // This submesh has enough lods, use the right one q.geometry = (SubMeshLodGeometryLink)qsm.geometryLodList[atlod]; } else { // Not enough lods, use the lowest one we have q.geometry = (SubMeshLodGeometryLink)qsm.geometryLodList[qsm.geometryLodList.Count - 1]; } // Locate a material bucket MaterialBucket mbucket; if (this.materialBucketMap.ContainsKey(qsm.materialName)) { mbucket = this.materialBucketMap[qsm.materialName]; } else { mbucket = new MaterialBucket(this, qsm.materialName); this.materialBucketMap.Add(qsm.materialName, mbucket); } mbucket.Assign(q); }
/// <summary> /// Adds an Entity to the static geometry. /// </summary> /// <remarks> /// This method takes an existing Entity and adds its details to the /// list of elements to include when building. Note that the Entity /// itself is not copied or referenced in this method; an Entity is /// passed simply so that you can change the materials of attached /// SubEntity objects if you want. You can add the same Entity /// instance multiple times with different material settings /// completely safely, and destroy the Entity before destroying /// this StaticGeometry if you like. The Entity passed in is simply /// used as a definition. /// /// Note: Must be called before 'build'. /// </remarks> /// <param name="ent">The Entity to use as a definition (the Mesh and Materials</param> /// <param name="position">The world position at which to add this Entity</param> /// <param name="orientation">The world orientation at which to add this Entity</param> /// <param name="scale">The scale at which to add this entity</param> public void AddEntity(Entity ent, Vector3 position, Quaternion orientation, Vector3 scale) { var msh = ent.Mesh; // Validate if (msh.IsLodManual) { LogManager.Instance.Write("WARNING (StaticGeometry): Manual LOD is not supported. " + "Using only highest LOD level for mesh " + msh.Name); } // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods foreach (SubEntity se in ent.SubEntities) { var q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry(q.submesh); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; // Determine the bounds based on the highest LOD q.worldBounds = CalculateBounds(q.geometryLodList[0].vertexData, position, orientation, scale); this.queuedSubMeshes.Add(q); } }
/// <summary> /// Adds an Entity to the static geometry. /// </summary> /// <remarks> /// This method takes an existing Entity and adds its details to the /// list of elements to include when building. Note that the Entity /// itself is not copied or referenced in this method; an Entity is /// passed simply so that you can change the materials of attached /// SubEntity objects if you want. You can add the same Entity /// instance multiple times with different material settings /// completely safely, and destroy the Entity before destroying /// this StaticGeometry if you like. The Entity passed in is simply /// used as a definition. /// /// Note: Must be called before 'build'. /// </remarks> /// <param name=ent>The Entity to use as a definition (the Mesh and Materials</param> /// <param name=position>The world position at which to add this Entity</param> /// <param name=orientation>The world orientation at which to add this Entity</param> /// <param name=scale>The scale at which to add this entity</param> /// <param name=position>The world position at which to add this Entity</position> public void AddEntity(Entity ent, Vector3 position, Quaternion orientation, Vector3 scale) { Mesh msh = ent.Mesh; // Validate if (msh.IsLodManual) { log.WarnFormat("StaticGeometry.AddEntity: Manual LOD is not supported. Using only highest LOD level for mesh {0}", msh.Name); } // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods for (int i = 0; i < ent.SubEntityCount; ++i) { SubEntity se = ent.GetSubEntity(i); QueuedSubMesh q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry(q.submesh); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; // Determine the bounds based on the highest LOD q.worldBounds = CalculateBounds(q.geometryLodList[0].vertexData, position, orientation, scale); queuedSubMeshes.Add(q); } }
public void Assign(QueuedSubMesh qsm) { queuedSubMeshes.Add(qsm); // update lod distances Mesh mesh = qsm.submesh.Parent; ushort lodLevels = (ushort)(mesh.IsLodManual ? 1 : mesh.LodLevelCount); if (qsm.geometryLodList.Count != lodLevels) { string msg = string.Format("QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}", qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels); throw new AxiomException(msg); } while (lodSquaredDistances.Count < lodLevels) { lodSquaredDistances.Add(0.0f); } // Make sure LOD levels are max of all at the requested level for (ushort lod = 1; lod < lodLevels; ++lod) { MeshLodUsage meshLod = qsm.submesh.Parent.GetLodLevel(lod); lodSquaredDistances[lod] = Math.Max((float)lodSquaredDistances[lod], meshLod.fromSquaredDepth); } // update bounds // Transform world bounds relative to our center AxisAlignedBox localBounds = new AxisAlignedBox(qsm.worldBounds.Minimum - center, qsm.worldBounds.Maximum - center); aabb.Merge(localBounds); foreach (Vector3 corner in localBounds.Corners) { boundingRadius = Math.Max(boundingRadius, corner.Length); } }
public void Assign(QueuedSubMesh qsm, ushort atlod) { QueuedGeometry q = new QueuedGeometry(); queuedGeometryList.Add(q); q.position = qsm.position; q.orientation = qsm.orientation; q.scale = qsm.scale; if(qsm.geometryLodList.Count > atlod) { // This submesh has enough lods, use the right one q.geometry = qsm.geometryLodList[atlod]; } else { // Not enough lods, use the lowest one we have q.geometry = qsm.geometryLodList[qsm.geometryLodList.Count - 1]; } // Locate a material bucket MaterialBucket mbucket; if(materialBucketMap.ContainsKey(qsm.materialName)) { mbucket = materialBucketMap[qsm.materialName]; } else { mbucket = new MaterialBucket(this, qsm.materialName); materialBucketMap[qsm.materialName] = mbucket; } mbucket.Assign(q); }
public void Assign(QueuedSubMesh qsm) { this.queuedSubMeshes.Add(qsm); // update lod distances var mesh = qsm.submesh.Parent; var lodStrategy = mesh.LodStrategy; if (this.lodStrategy == null) { this.lodStrategy = lodStrategy; // First LOD mandatory, and always from base lod value this.lodValues.Add(this.lodStrategy.BaseValue); } else { if (this.lodStrategy != lodStrategy) { throw new AxiomException("Lod strategies do not match."); } } var lodLevels = mesh.LodLevelCount; if (qsm.geometryLodList.Count != lodLevels) { var msg = string.Format("QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}", qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels); throw new AxiomException(msg); } while (this.lodValues.Count < lodLevels) { this.lodValues.Add(0.0f); } // Make sure LOD levels are max of all at the requested level for (ushort lod = 1; lod < lodLevels; ++lod) { var meshLod = qsm.submesh.Parent.GetLodLevel(lod); this.lodValues[lod] = Utility.Max((float)this.lodValues[lod], meshLod.Value); } // update bounds // Transform world bounds relative to our center var localBounds = new AxisAlignedBox(qsm.worldBounds.Minimum - this.center, qsm.worldBounds.Maximum - this.center); this.aabb.Merge(localBounds); foreach (var corner in localBounds.Corners) { this.boundingRadius = Utility.Max(this.boundingRadius, corner.Length); } }
///<summary> /// Adds an Entity to the static geometry. /// <remarks> /// This method takes an existing Entity and adds its details to the list of elements to include when building. Note that the Entity itself is not copied or referenced in this method; an Entity is passed simply so that you can change the materials of attached SubEntity objects if you want. You can add the same Entity instance multiple times with different material settings completely safely, and destroy the Entity before destroying this InstancedGeometry if you like. The Entity passed in is simply Must be called before 'Build'. /// </remarks> ///</summary> ///<param name="ent"> The Entity to use as a definition (the Mesh and Materials referenced will be recorded for the build call). </param> ///<param name="position"> The world position at which to add this Entity </param> ///<param name="orientation"> The world orientation at which to add this Entity </param> ///<param name="scale"> </param> public virtual void AddEntity(Entity ent, Vector3 position, Quaternion orientation, Vector3 scale) { Mesh msh = ent.Mesh; // Validate if (msh.IsLodManual) { LogManager.Instance.Write( "(InstancedGeometry): Manual LOD is not supported. Using only highest LOD level for mesh " + msh.Name); } //get the skeleton of the entity, if that's not already done if (ent.Mesh.Skeleton != null && mBaseSkeleton == null) { mBaseSkeleton = ent.Mesh.Skeleton; mSkeletonInstance = new SkeletonInstance(mBaseSkeleton); mSkeletonInstance.Load(); mAnimationState = ent.GetAllAnimationStates(); } BoundingBox sharedWorldBounds; // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods for (int i = 0; i < ent.SubEntityCount; ++i) { SubEntity se = ent.GetSubEntity(i); var q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry(q.submesh); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; q.ID = mObjectCount; } mObjectCount++; }
///<summary> /// Adds an Entity to the static geometry. /// <remarks> /// This method takes an existing Entity and adds its details to the list of elements to include when building. Note that the Entity itself is not copied or referenced in this method; an Entity is passed simply so that you can change the materials of attached SubEntity objects if you want. You can add the same Entity instance multiple times with different material settings completely safely, and destroy the Entity before destroying this InstancedGeometry if you like. The Entity passed in is simply Must be called before 'Build'. /// </remarks> ///</summary> ///<param name="ent"> The Entity to use as a definition (the Mesh and Materials referenced will be recorded for the build call). </param> ///<param name="position"> The world position at which to add this Entity </param> ///<param name="orientation"> The world orientation at which to add this Entity </param> ///<param name="scale"> </param> public virtual void AddEntity( Entity ent, Vector3 position, Quaternion orientation, Vector3 scale ) { Mesh msh = ent.Mesh; // Validate if ( msh.IsLodManual ) { LogManager.Instance.Write( "(InstancedGeometry): Manual LOD is not supported. Using only highest LOD level for mesh " + msh.Name ); } //get the skeleton of the entity, if that's not already done if ( ent.Mesh.Skeleton != null && mBaseSkeleton == null ) { mBaseSkeleton = ent.Mesh.Skeleton; mSkeletonInstance = new SkeletonInstance( mBaseSkeleton ); mSkeletonInstance.Load(); mAnimationState = ent.GetAllAnimationStates(); } BoundingBox sharedWorldBounds; // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods for ( int i = 0; i < ent.SubEntityCount; ++i ) { SubEntity se = ent.GetSubEntity( i ); var q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry( q.submesh ); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; q.ID = mObjectCount; } mObjectCount++; }
public void Assign( QueuedSubMesh qsm ) { this.queuedSubMeshes.Add( qsm ); // update lod distances var mesh = qsm.submesh.Parent; var lodStrategy = mesh.LodStrategy; if ( this.lodStrategy == null ) { this.lodStrategy = lodStrategy; // First LOD mandatory, and always from base lod value this.lodValues.Add( this.lodStrategy.BaseValue ); } else { if ( this.lodStrategy != lodStrategy ) { throw new AxiomException( "Lod strategies do not match." ); } } var lodLevels = mesh.LodLevelCount; if ( qsm.geometryLodList.Count != lodLevels ) { var msg = string.Format( "QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}", qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels ); throw new AxiomException( msg ); } while ( this.lodValues.Count < lodLevels ) { this.lodValues.Add( 0.0f ); } // Make sure LOD levels are max of all at the requested level for ( ushort lod = 1; lod < lodLevels; ++lod ) { var meshLod = qsm.submesh.Parent.GetLodLevel( lod ); this.lodValues[ lod ] = Utility.Max( (float)this.lodValues[ lod ], meshLod.Value ); } // update bounds // Transform world bounds relative to our center var localBounds = new AxisAlignedBox( qsm.worldBounds.Minimum - this.center, qsm.worldBounds.Maximum - this.center ); this.aabb.Merge( localBounds ); foreach ( var corner in localBounds.Corners ) { this.boundingRadius = Utility.Max( this.boundingRadius, corner.Length ); } }
/// <summary> /// Adds an Entity to the static geometry. /// </summary> /// <remarks> /// This method takes an existing Entity and adds its details to the /// list of elements to include when building. Note that the Entity /// itself is not copied or referenced in this method; an Entity is /// passed simply so that you can change the materials of attached /// SubEntity objects if you want. You can add the same Entity /// instance multiple times with different material settings /// completely safely, and destroy the Entity before destroying /// this StaticGeometry if you like. The Entity passed in is simply /// used as a definition. /// /// Note: Must be called before 'build'. /// </remarks> /// <param name="ent">The Entity to use as a definition (the Mesh and Materials</param> /// <param name="position">The world position at which to add this Entity</param> /// <param name="orientation">The world orientation at which to add this Entity</param> /// <param name="scale">The scale at which to add this entity</param> public void AddEntity( Entity ent, Vector3 position, Quaternion orientation, Vector3 scale ) { var msh = ent.Mesh; // Validate if ( msh.IsLodManual ) { LogManager.Instance.Write( "WARNING (StaticGeometry): Manual LOD is not supported. " + "Using only highest LOD level for mesh " + msh.Name ); } // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods foreach ( SubEntity se in ent.SubEntities ) { var q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry( q.submesh ); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; // Determine the bounds based on the highest LOD q.worldBounds = CalculateBounds( q.geometryLodList[ 0 ].vertexData, position, orientation, scale ); this.queuedSubMeshes.Add( q ); } }
/// <summary> /// Adds an Entity to the static geometry. /// </summary> /// <remarks> /// This method takes an existing Entity and adds its details to the /// list of elements to include when building. Note that the Entity /// itself is not copied or referenced in this method; an Entity is /// passed simply so that you can change the materials of attached /// SubEntity objects if you want. You can add the same Entity /// instance multiple times with different material settings /// completely safely, and destroy the Entity before destroying /// this StaticGeometry if you like. The Entity passed in is simply /// used as a definition. /// /// Note: Must be called before 'build'. /// </remarks> /// <param name=ent>The Entity to use as a definition (the Mesh and Materials</param> /// <param name=position>The world position at which to add this Entity</param> /// <param name=orientation>The world orientation at which to add this Entity</param> /// <param name=scale>The scale at which to add this entity</param> /// <param name=position>The world position at which to add this Entity</position> public void AddEntity(Entity ent, Vector3 position, Quaternion orientation, Vector3 scale) { Mesh msh = ent.Mesh; // Validate if (msh.IsLodManual) log.WarnFormat("StaticGeometry.AddEntity: Manual LOD is not supported. Using only highest LOD level for mesh {0}", msh.Name); // queue this entities submeshes and choice of material // also build the lists of geometry to be used for the source of lods for (int i = 0; i < ent.SubEntityCount; ++i) { SubEntity se = ent.GetSubEntity(i); QueuedSubMesh q = new QueuedSubMesh(); // Get the geometry for this SubMesh q.submesh = se.SubMesh; q.geometryLodList = DetermineGeometry(q.submesh); q.materialName = se.MaterialName; q.orientation = orientation; q.position = position; q.scale = scale; // Determine the bounds based on the highest LOD q.worldBounds = CalculateBounds(q.geometryLodList[0].vertexData, position, orientation, scale); queuedSubMeshes.Add(q); } }
public void Assign(QueuedSubMesh qsm) { queuedSubMeshes.Add(qsm); // update lod distances Mesh mesh = qsm.submesh.Parent; ushort lodLevels = (ushort)(mesh.IsLodManual ? 1 : mesh.LodLevelCount); if (qsm.geometryLodList.Count != lodLevels) { string msg = string.Format("QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}", qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels); throw new AxiomException(msg); } while(lodSquaredDistances.Count < lodLevels) { lodSquaredDistances.Add(0.0f); } // Make sure LOD levels are max of all at the requested level for(ushort lod = 1; lod < lodLevels; ++lod) { MeshLodUsage meshLod = qsm.submesh.Parent.GetLodLevel(lod); lodSquaredDistances[lod] = Math.Max((float)lodSquaredDistances[lod], meshLod.fromSquaredDepth); } // update bounds // Transform world bounds relative to our center AxisAlignedBox localBounds = new AxisAlignedBox(qsm.worldBounds.Minimum - center, qsm.worldBounds.Maximum - center); aabb.Merge(localBounds); foreach (Vector3 corner in localBounds.Corners) boundingRadius = Math.Max(boundingRadius, corner.Length); }