Inheritance: HighLevelMaterial
 //
 internal MapItem( ShaderBaseMaterial owner )
 {
     this.owner = owner;
     transform = new TransformItem( this );
 }
Exemplo n.º 2
0
        void CreateDecal()
        {
            Bounds bounds = Bounds.Cleared;
            foreach( Vertex vertex in vertices )
                bounds.Add( vertex.position );

            VertexData vertexData = new VertexData();
            IndexData indexData = new IndexData();

            //init vertexData
            VertexDeclaration declaration = vertexData.VertexDeclaration;
            declaration.AddElement( 0, 0, VertexElementType.Float3, VertexElementSemantic.Position );
            declaration.AddElement( 0, 12, VertexElementType.Float3, VertexElementSemantic.Normal );
            declaration.AddElement( 0, 24, VertexElementType.Float2,
                VertexElementSemantic.TextureCoordinates, 0 );
            declaration.AddElement( 0, 32, VertexElementType.Float3, VertexElementSemantic.Tangent );

            VertexBufferBinding bufferBinding = vertexData.VertexBufferBinding;
            HardwareVertexBuffer vertexBuffer = HardwareBufferManager.Instance.CreateVertexBuffer(
                44, vertices.Length, HardwareBuffer.Usage.StaticWriteOnly );
            bufferBinding.SetBinding( 0, vertexBuffer, true );
            vertexData.VertexCount = vertices.Length;

            //init indexData
            Trace.Assert( vertices.Length < 65536, "Decal: vertices.Length < 65536" );

            HardwareIndexBuffer indexBuffer = HardwareBufferManager.Instance.CreateIndexBuffer(
                HardwareIndexBuffer.IndexType._16Bit, indices.Length,
                HardwareBuffer.Usage.StaticWriteOnly );
            indexData.SetIndexBuffer( indexBuffer, true );
            indexData.IndexCount = indices.Length;

            //init material
            Material material = null;

            shaderBaseMaterial = HighLevelMaterialManager.Instance.
                GetMaterialByName( sourceMaterialName ) as ShaderBaseMaterial;
            //only default shader technique for ShaderBase material
            if( shaderBaseMaterial != null && !shaderBaseMaterial.IsDefaultTechniqueCreated() )
                shaderBaseMaterial = null;

            if( shaderBaseMaterial != null )
            {
                //ShaderBase material
                material = shaderBaseMaterial.BaseMaterial;
            }
            else
            {
                //standard material or fallback ShaderBase technique
                Material sourceMaterial = MaterialManager.Instance.GetByName( sourceMaterialName );
                if( sourceMaterial != null )
                {
                    //clone standard material
                    clonedStandardMaterial = MaterialManager.Instance.Clone( sourceMaterial,
                        MaterialManager.Instance.GetUniqueName( sourceMaterialName + "_Cloned" ) );
                    material = clonedStandardMaterial;
                }
            }

            staticMeshObject = SceneManager.Instance.CreateStaticMeshObject( bounds + Position,
                Position, Quat.Identity, new Vec3( 1, 1, 1 ), material, vertexData, indexData, true );
            staticMeshObject.AddToRenderQueue += StaticMeshObject_AddToRenderQueue;

            UpdateBuffers();
        }
 internal DiffuseMapItem( ShaderBaseMaterial owner )
     : base(owner)
 {
 }