예제 #1
0
			public void Build( bool stencilShadows, int logLevel )
			{
				// Create a node
				this.node = this.sceneMgr.RootSceneNode.CreateChildSceneNode( name, this.center );
				this.node.AttachObject( this );
				// We need to create enough LOD buckets to deal with the highest LOD
				// we encountered in all the meshes queued
				for ( ushort lod = 0; lod < this.lodValues.Count; ++lod )
				{
					var lodBucket = new LODBucket( this, lod, (float)this.lodValues[ lod ] );
					this.lodBucketList.Add( lodBucket );
					// Now iterate over the meshes and assign to LODs
					// LOD bucket will pick the right LOD to use
					IEnumerator iter = this.queuedSubMeshes.GetEnumerator();
					while ( iter.MoveNext() )
					{
						var qsm = (QueuedSubMesh)iter.Current;
						lodBucket.Assign( qsm, lod );
					}
					// now build
					lodBucket.Build( stencilShadows, logLevel );
				}

				// Do we need to build an edge list?
				if ( stencilShadows )
				{
					var eb = new EdgeListBuilder();
					//int vertexSet = 0;
					foreach ( var lod in this.lodBucketList )
					{
						foreach ( var mat in lod.MaterialBucketMap.Values )
						{
							// Check if we have vertex programs here
							var t = mat.Material.GetBestTechnique();
							if ( null != t )
							{
								var p = t.GetPass( 0 );
								if ( null != p )
								{
									if ( p.HasVertexProgram )
									{
										this.vertexProgramInUse = true;
									}
								}
							}

							foreach ( var geom in mat.GeometryBucketList )
							{
								// Check we're dealing with 16-bit indexes here
								// Since stencil shadows can only deal with 16-bit
								// More than that and stencil is probably too CPU-heavy
								// in any case
								if ( geom.IndexData.indexBuffer.Type != IndexType.Size16 )
								{
									throw new AxiomException( "Only 16-bit indexes allowed when using stencil shadows" );
								}
								eb.AddVertexData( geom.VertexData );
								eb.AddIndexData( geom.IndexData );
							}
						}
					}
					this.edgeList = eb.Build();
				}
			}
예제 #2
0
파일: Mesh.cs 프로젝트: ryan-bunker/axiom3d
		/// <summary>
		///		Builds an edge list for this mesh, which can be used for generating a shadow volume
		///		among other things.
		/// </summary>
		public void BuildEdgeList()
		{
			if ( this._edgeListsBuilt )
			{
				return;
			}

			// loop over LODs
			for ( var lodIndex = 0; lodIndex < this.meshLodUsageList.Count; lodIndex++ )
			{
				// use getLodLevel to enforce loading of manual mesh lods
				var usage = GetLodLevel( lodIndex );

				if ( this._isLodManual && lodIndex != 0 )
				{
					// Delegate edge building to manual mesh
					// It should have already built its own edge list while loading
					usage.EdgeData = usage.ManualMesh.GetEdgeList( 0 );
				}
				else
				{
					var builder = new EdgeListBuilder();

					// Add this mesh's vertex and index data structures
					AddVertexAndIndexSets( builder, lodIndex );

					// build the edge data from all accumulate vertex/index buffers
					usage.EdgeData = builder.Build();
				}
			}

			this._edgeListsBuilt = true;
		}
예제 #3
0
        // Returns the number of geometry buckets
        public int Build(bool stencilShadows, bool logDetails)
        {
            int bucketCount = 0;
            // Create a node
            node = sceneMgr.RootSceneNode.CreateChildSceneNode(name, center);
            node.AttachObject(this);
            // We need to create enough LOD buckets to deal with the highest LOD
            // we encountered in all the meshes queued
            for(ushort lod = 0; lod < lodSquaredDistances.Count; ++lod)
            {
                LODBucket lodBucket = new LODBucket(this, lod, (float)lodSquaredDistances[lod]);
                lodBucketList.Add(lodBucket);
                // Now iterate over the meshes and assign to LODs
                // LOD bucket will pick the right LOD to use
                foreach (QueuedSubMesh qsm in queuedSubMeshes)
                    lodBucket.Assign(qsm, lod);
                // now build
                bucketCount += lodBucket.Build(stencilShadows, logDetails);
            }

            // Do we need to build an edge list?
            if(stencilShadows)
            {
                EdgeListBuilder eb = new EdgeListBuilder();
                foreach (LODBucket lod in lodBucketList) {
                    foreach(MaterialBucket mat in lod.MaterialBucketMap.Values) {
                        // Check if we have vertex programs here
                        Technique t = mat.Material.GetBestTechnique();
                        if(null != t)
                        {
                            Pass p = t.GetPass(0);
                            if(null != p)
                            {
                                if(p.HasVertexProgram)
                                {
                                    vertexProgramInUse = true;
                                }
                            }
                        }

                        foreach (GeometryBucket geom in mat.GeometryBucketList) {
                            bucketCount++;
                            // Check we're dealing with 16-bit indexes here
                            // Since stencil shadows can only deal with 16-bit
                            // More than that and stencil is probably too CPU-heavy
                            // in any case
                            if(geom.IndexData.indexBuffer.Type != IndexType.Size16) throw new AxiomException("Only 16-bit indexes allowed when using stencil shadows");
                            eb.AddVertexData(geom.VertexData);
                            eb.AddIndexData(geom.IndexData);
                        }
                    }
                }
                edgeList = eb.Build();
            }
            return bucketCount;
        }