Beispiel #1
0
            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);
            }
Beispiel #2
0
            public void Assign(QueuedGeometry qgeom)
            {
                // Look up any current geometry
                var formatString = GetGeometryFormatString(qgeom.geometry);
                var newBucket    = true;

                if (this.currentGeometryMap.ContainsKey(formatString))
                {
                    var gbucket = this.currentGeometryMap[formatString];
                    // Found existing geometry, try to assign
                    newBucket = !gbucket.Assign(qgeom);
                    // Note that this bucket will be replaced as the 'current'
                    // for this format string below since it's out of space
                }
                // Do we need to create a new one?
                if (newBucket)
                {
                    var gbucket = new GeometryBucket(this, formatString, qgeom.geometry.vertexData, qgeom.geometry.indexData);
                    // Add to main list
                    this.geometryBucketList.Add(gbucket);
                    // Also index in 'current' list
                    this.currentGeometryMap[formatString] = gbucket;
                    if (!gbucket.Assign(qgeom))
                    {
                        throw new AxiomException("Somehow we couldn't fit the requested geometry even in a " +
                                                 "brand new GeometryBucket!! Must be a bug, please report.");
                    }
                }
            }
Beispiel #3
0
        public bool Assign(QueuedGeometry qgeom)
        {
            // do we have enough space
            if (vertexData.vertexCount + qgeom.geometry.vertexData.vertexCount > maxVertexIndex)
            {
                return(false);
            }

            queuedGeometry.Add(qgeom);
            vertexData.vertexCount += qgeom.geometry.vertexData.vertexCount;
            indexData.indexCount   += qgeom.geometry.indexData.indexCount;

            return(true);
        }
Beispiel #4
0
        protected unsafe byte *CopyVertices(HardwareVertexBuffer srcBuf, byte *pDst, List <VertexElement> elems, QueuedGeometry geom, Vector3 regionCenter)
        {
            // lock source
            IntPtr src    = srcBuf.Lock(BufferLocking.ReadOnly);
            int    bufInc = srcBuf.VertexSize;

            byte *  pSrc = (byte *)src.ToPointer();
            float * pSrcReal;
            float * pDstReal;
            Vector3 temp = Vector3.Zero;

            // Calculate elem sizes outside the loop
            int [] elemSizes = new int[elems.Count];
            for (int i = 0; i < elems.Count; i++)
            {
                elemSizes[i] = VertexElement.GetTypeSize(elems[i].Type);
            }

            // Move the position offset calculation outside the loop
            Vector3 positionDelta = geom.position - regionCenter;

            for (int v = 0; v < geom.geometry.vertexData.vertexCount; ++v)
            {
                // iterate over vertex elements
                for (int i = 0; i < elems.Count; i++)
                {
                    VertexElement elem = elems[i];
                    pSrcReal = (float *)(pSrc + elem.Offset);
                    pDstReal = (float *)(pDst + elem.Offset);

                    switch (elem.Semantic)
                    {
                    case VertexElementSemantic.Position:
                        temp.x = *pSrcReal++;
                        temp.y = *pSrcReal++;
                        temp.z = *pSrcReal++;
                        // transform
                        temp = (geom.orientation * (temp * geom.scale));
                        *pDstReal++ = temp.x + positionDelta.x;
                        *pDstReal++ = temp.y + positionDelta.y;
                        *pDstReal++ = temp.z + positionDelta.z;
                        break;

                    case VertexElementSemantic.Normal:
                    case VertexElementSemantic.Tangent:
                    case VertexElementSemantic.Binormal:
                        temp.x = *pSrcReal++;
                        temp.y = *pSrcReal++;
                        temp.z = *pSrcReal++;
                        // rotation only
                        temp = geom.orientation * temp;
                        *pDstReal++ = temp.x;
                        *pDstReal++ = temp.y;
                        *pDstReal++ = temp.z;
                        break;

                    default:
                        // just raw copy
                        int size = elemSizes[i];
                        // Optimize the loop for the case that
                        // these things are in units of 4
                        if ((size & 0x3) == 0x0)
                        {
                            int cnt = size / 4;
                            while (cnt-- > 0)
                            {
                                *pDstReal++ = *pSrcReal++;
                            }
                        }
                        else
                        {
                            // Fall back to the byte-by-byte copy
                            byte *pbSrc = (byte *)pSrcReal;
                            byte *pbDst = (byte *)pDstReal;
                            while (size-- > 0)
                            {
                                *pbDst++ = *pbSrc++;
                            }
                        }
                        break;
                    }
                }

                // Increment both pointers
                pDst += bufInc;
                pSrc += bufInc;
            }

            srcBuf.Unlock();
            return(pDst);
        }
Beispiel #5
0
			public void Assign( QueuedGeometry qgeom )
			{
				// Look up any current geometry
				var formatString = GetGeometryFormatString( qgeom.geometry );
				var newBucket = true;
				if ( this.currentGeometryMap.ContainsKey( formatString ) )
				{
					var gbucket = this.currentGeometryMap[ formatString ];
					// Found existing geometry, try to assign
					newBucket = !gbucket.Assign( qgeom );
					// Note that this bucket will be replaced as the 'current'
					// for this format string below since it's out of space
				}
				// Do we need to create a new one?
				if ( newBucket )
				{
					var gbucket = new GeometryBucket( this, formatString, qgeom.geometry.vertexData, qgeom.geometry.indexData );
					// Add to main list
					this.geometryBucketList.Add( gbucket );
					// Also index in 'current' list
					this.currentGeometryMap[ formatString ] = gbucket;
					if ( !gbucket.Assign( qgeom ) )
					{
						throw new AxiomException( "Somehow we couldn't fit the requested geometry even in a " +
						                          "brand new GeometryBucket!! Must be a bug, please report." );
					}
				}
			}
Beispiel #6
0
			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 );
			}
        protected unsafe byte *CopyVertices(HardwareVertexBuffer srcBuf, byte *pDst, List<VertexElement> elems, QueuedGeometry geom, Vector3 regionCenter)
        {
            // lock source
            IntPtr src = srcBuf.Lock(BufferLocking.ReadOnly);
            int bufInc = srcBuf.VertexSize;

            byte * pSrc = (byte *)src.ToPointer();
            float * pSrcReal;
            float * pDstReal;
            Vector3 temp = Vector3.Zero;

            // Calculate elem sizes outside the loop
            int [] elemSizes = new int[elems.Count];
            for (int i=0; i<elems.Count; i++)
                elemSizes[i] = VertexElement.GetTypeSize(elems[i].Type);

            // Move the position offset calculation outside the loop
            Vector3 positionDelta = geom.position - regionCenter;

            for(int v = 0; v < geom.geometry.vertexData.vertexCount; ++v)
            {
                // iterate over vertex elements
                for (int i=0; i<elems.Count; i++) {
                    VertexElement elem = elems[i];
                    pSrcReal = (float *)(pSrc + elem.Offset);
                    pDstReal = (float *)(pDst + elem.Offset);

                    switch(elem.Semantic)
                    {
                        case VertexElementSemantic.Position:
                            temp.x = *pSrcReal++;
                            temp.y = *pSrcReal++;
                            temp.z = *pSrcReal++;
                            // transform
                            temp = (geom.orientation * (temp * geom.scale));
                            *pDstReal++ = temp.x + positionDelta.x;
                            *pDstReal++ = temp.y + positionDelta.y;
                            *pDstReal++ = temp.z + positionDelta.z;
                            break;
                        case VertexElementSemantic.Normal:
                        case VertexElementSemantic.Tangent:
                        case VertexElementSemantic.Binormal:
                            temp.x = *pSrcReal++;
                            temp.y = *pSrcReal++;
                            temp.z = *pSrcReal++;
                            // rotation only
                            temp = geom.orientation * temp;
                            *pDstReal++ = temp.x;
                            *pDstReal++ = temp.y;
                            *pDstReal++ = temp.z;
                            break;
                        default:
                            // just raw copy
                            int size = elemSizes[i];
                            // Optimize the loop for the case that
                            // these things are in units of 4
                            if ((size & 0x3) == 0x0) {
                                int cnt = size / 4;
                                while (cnt-- > 0)
                                    *pDstReal++ = *pSrcReal++;
                            }
                            else {
                                // Fall back to the byte-by-byte copy
                                byte * pbSrc = (byte*)pSrcReal;
                                byte * pbDst = (byte*)pDstReal;
                                while(size-- > 0)
                                    *pbDst++ = *pbSrc++;
                            }
                            break;
                    }
                }

                // Increment both pointers
                pDst += bufInc;
                pSrc += bufInc;
            }

            srcBuf.Unlock();
            return pDst;
        }
        public bool Assign(QueuedGeometry qgeom)
        {
            // do we have enough space
            if(vertexData.vertexCount + qgeom.geometry.vertexData.vertexCount > maxVertexIndex)
                return false;

            queuedGeometry.Add(qgeom);
            vertexData.vertexCount += qgeom.geometry.vertexData.vertexCount;
            indexData.indexCount += qgeom.geometry.indexData.indexCount;

            return true;
        }
Beispiel #9
0
			protected int CopyVertices( HardwareVertexBuffer srcBuf, BufferBase pDst, List<VertexElement> elems,
			                            QueuedGeometry geom, Vector3 regionCenter )
			{
#if !AXIOM_SAFE_ONLY
				unsafe
#endif
				{
					// lock source
					var src = srcBuf.Lock( BufferLocking.ReadOnly );
					var bufInc = srcBuf.VertexSize;

					var temp = Vector3.Zero;

					// Calculate elem sizes outside the loop
					var elemSizes = new int[elems.Count];
					for ( var i = 0; i < elems.Count; i++ )
					{
						elemSizes[ i ] = VertexElement.GetTypeSize( elems[ i ].Type );
					}

					// Move the position offset calculation outside the loop
					var positionDelta = geom.position - regionCenter;

					for ( var v = 0; v < geom.geometry.vertexData.vertexCount; ++v )
					{
						// iterate over vertex elements
						for ( var i = 0; i < elems.Count; i++ )
						{
							var elem = elems[ i ];
							var pSrcReal = ( src + elem.Offset ).ToFloatPointer();
							var pDstReal = ( pDst + elem.Offset ).ToFloatPointer();

							switch ( elem.Semantic )
							{
								case VertexElementSemantic.Position:
									temp.x = pSrcReal[ 0 ];
									temp.y = pSrcReal[ 1 ];
									temp.z = pSrcReal[ 2 ];
									// transform
									temp = ( geom.orientation*( temp*geom.scale ) );
									pDstReal[ 0 ] = temp.x + positionDelta.x;
									pDstReal[ 1 ] = temp.y + positionDelta.y;
									pDstReal[ 2 ] = temp.z + positionDelta.z;
									break;
								case VertexElementSemantic.Normal:
								case VertexElementSemantic.Tangent:
								case VertexElementSemantic.Binormal:
									temp.x = pSrcReal[ 0 ];
									temp.y = pSrcReal[ 1 ];
									temp.z = pSrcReal[ 2 ];
									// rotation only
									temp = geom.orientation*temp;
									pDstReal[ 0 ] = temp.x;
									pDstReal[ 1 ] = temp.y;
									pDstReal[ 2 ] = temp.z;
									break;
								default:
									// just raw copy
									var size = elemSizes[ i ];
									// Optimize the loop for the case that
									// these things are in units of 4
									if ( ( size & 0x3 ) == 0x3 )
									{
										var cnt = size/4;
										while ( cnt-- > 0 )
										{
											pDstReal[ cnt ] = pSrcReal[ cnt ];
										}
									}
									else
									{
										// Fall back to the byte-by-byte copy
										var pbSrc = ( src + elem.Offset ).ToBytePointer();
										var pbDst = ( pDst + elem.Offset ).ToBytePointer();
										while ( size-- > 0 )
										{
											pbDst[ size ] = pbSrc[ size ];
										}
									}
									break;
							}
						}

						// Increment both pointers
						pDst.Ptr += bufInc;
						src.Ptr += bufInc;
					}

					srcBuf.Unlock();
					return pDst.Ptr;
				}
			}
Beispiel #10
0
			public bool Assign( QueuedGeometry qgeom )
			{
				// do we have enough space
				if ( this.vertexData.vertexCount + qgeom.geometry.vertexData.vertexCount > this.maxVertexIndex )
				{
					return false;
				}

				this.queuedGeometry.Add( qgeom );
				this.vertexData.vertexCount += qgeom.geometry.vertexData.vertexCount;
				this.indexData.indexCount += qgeom.geometry.indexData.indexCount;

				return true;
			}
Beispiel #11
0
            protected int CopyVertices(HardwareVertexBuffer srcBuf, BufferBase pDst, List <VertexElement> elems,
                                       QueuedGeometry geom, Vector3 regionCenter)
            {
#if !AXIOM_SAFE_ONLY
                unsafe
#endif
                {
                    // lock source
                    var src    = srcBuf.Lock(BufferLocking.ReadOnly);
                    var bufInc = srcBuf.VertexSize;

                    var temp = Vector3.Zero;

                    // Calculate elem sizes outside the loop
                    var elemSizes = new int[elems.Count];
                    for (var i = 0; i < elems.Count; i++)
                    {
                        elemSizes[i] = VertexElement.GetTypeSize(elems[i].Type);
                    }

                    // Move the position offset calculation outside the loop
                    var positionDelta = geom.position - regionCenter;

                    for (var v = 0; v < geom.geometry.vertexData.vertexCount; ++v)
                    {
                        // iterate over vertex elements
                        for (var i = 0; i < elems.Count; i++)
                        {
                            var elem     = elems[i];
                            var pSrcReal = (src + elem.Offset).ToFloatPointer();
                            var pDstReal = (pDst + elem.Offset).ToFloatPointer();

                            switch (elem.Semantic)
                            {
                            case VertexElementSemantic.Position:
                                temp.x = pSrcReal[0];
                                temp.y = pSrcReal[1];
                                temp.z = pSrcReal[2];
                                // transform
                                temp        = (geom.orientation * (temp * geom.scale));
                                pDstReal[0] = temp.x + positionDelta.x;
                                pDstReal[1] = temp.y + positionDelta.y;
                                pDstReal[2] = temp.z + positionDelta.z;
                                break;

                            case VertexElementSemantic.Normal:
                            case VertexElementSemantic.Tangent:
                            case VertexElementSemantic.Binormal:
                                temp.x = pSrcReal[0];
                                temp.y = pSrcReal[1];
                                temp.z = pSrcReal[2];
                                // rotation only
                                temp        = geom.orientation * temp;
                                pDstReal[0] = temp.x;
                                pDstReal[1] = temp.y;
                                pDstReal[2] = temp.z;
                                break;

                            default:
                                // just raw copy
                                var size = elemSizes[i];
                                // Optimize the loop for the case that
                                // these things are in units of 4
                                if ((size & 0x3) == 0x3)
                                {
                                    var cnt = size / 4;
                                    while (cnt-- > 0)
                                    {
                                        pDstReal[cnt] = pSrcReal[cnt];
                                    }
                                }
                                else
                                {
                                    // Fall back to the byte-by-byte copy
                                    var pbSrc = (src + elem.Offset).ToBytePointer();
                                    var pbDst = (pDst + elem.Offset).ToBytePointer();
                                    while (size-- > 0)
                                    {
                                        pbDst[size] = pbSrc[size];
                                    }
                                }
                                break;
                            }
                        }

                        // Increment both pointers
                        pDst.Ptr += bufInc;
                        src.Ptr  += bufInc;
                    }

                    srcBuf.Unlock();
                    return(pDst.Ptr);
                }
            }