Exemplo n.º 1
0
        /// <summary>
        ///     Buffers array data and creates draw commands as needed for a given object
        /// </summary>
        /// <param name="eye">Viewer camera used to select detail level</param>
        /// <param name="objectBlock">Object to draw</param>
        private void Dispatch(Camera eye, ScenarioStructureBspBlock scenarioStructure, CacheKey cacheKey)
        {
            if (scenarioStructure == null)
            {
                return;
            }

            foreach (var cluster in scenarioStructure.Clusters)
            {
                if (!cluster.IsClusterDataLoaded)
                {
                    cluster.LoadClusterData(  );
                }
                var section = cluster.ClusterData[0].Section;
                _bucketManager.BufferPartData(section);

                foreach (var part in section.Parts)
                {
                    var materialBlock = scenarioStructure.Materials[part.Material];

                    //  Create an instance for this part and assign a shader for it
                    _drawManager.CreateInstance(part, new ScenarioInstanceBlock( ), false);
                    _drawManager.AssignShader(part, cacheKey, materialBlock.Shader.Ident);
                }
            }
        }
Exemplo n.º 2
0
        internal void LoadScenarioCollision(ScenarioStructureBspBlock structureBSP)
        {
            foreach (var cluster in structureBSP.clusters)
            {
                var triangleMesh = new TriangleMesh();

                var vertices = new Vector3[cluster.clusterData[0].section.vertexBuffers[0].vertexBuffer.Data.Length / 12];
                for (int i = 0; i < vertices.Length; ++i)
                {
                    var data = cluster.clusterData[0].section.vertexBuffers[0].vertexBuffer.Data;
                    vertices[i] = new Vector3(
                        BitConverter.ToSingle(data, i * 12 + 0),
                        BitConverter.ToSingle(data, i * 12 + 4),
                        BitConverter.ToSingle(data, i * 12 + 8));
                }
                TriangleIndexVertexArray inte = new TriangleIndexVertexArray(
                    cluster.clusterData[0].section.stripIndices.Select(x => (int)x.index).ToArray(), vertices);

                CollisionObject o = new CollisionObject();
                o.CollisionShape = new BvhTriangleMeshShape(inte, true);
                o.CollisionFlags = CollisionFlags.StaticObject;


                World.AddCollisionObject(o, CollisionFilterGroups.StaticFilter, CollisionFilterGroups.AllFilter);
            }
        }
Exemplo n.º 3
0
 public void LoadScenarioStructure(ScenarioStructureBspBlock levelBlock)
 {
     this.Level               = levelBlock;
     ClusterObjects           = new List <RenderObject>();
     InstancedGeometryObjects = new List <RenderObject>();
     foreach (var cluster in this.Level.clusters)
     {
         ClusterObjects.Add(new RenderObject(cluster)
         {
             DiffuseColour = Colours.LinearRandomDiffuseColor
         });
     }
     foreach (var item in this.Level.instancedGeometriesDefinitions)
     {
         InstancedGeometryObjects.Add(new RenderObject(item)
         {
             DiffuseColour = Color.DarkRed
         });
     }
 }
Exemplo n.º 4
0
        internal void LoadScenarioCollision(ScenarioStructureBspBlock structureBSP)
        {
            {
                var meshArray = new InfoTriangleIndexVertexArray( );
                foreach (var cluster in structureBSP.Clusters)
                {
                    var globalGeometrySectionStructBlock = cluster.ClusterData[0].Section;
                    if (!IsCollisionMesh(globalGeometrySectionStructBlock))
                    {
                        continue;
                    }

                    var indexedMesh = GenerateBvhCollisionObjectFromMesh(globalGeometrySectionStructBlock, Matrix4.Identity);
                    meshArray.AddIndexedMesh(indexedMesh);
                    meshArray.AddIndexedMeshSurfaceData(globalGeometrySectionStructBlock);
                }

                Vector3 aabbMax;
                Vector3 aabbMin;
                meshArray.CalculateAabbBruteForce(out aabbMin, out aabbMax);
                var bvhTriangleMeshShape = new BvhTriangleMeshShape(meshArray, true, aabbMin, aabbMax, true);
                bvhTriangleMeshShape.BuildOptimizedBvh( );

                var collisionObject = new CollisionObject
                {
                    CollisionShape = bvhTriangleMeshShape
                };
                World.AddCollisionObject(collisionObject, CollisionFilterGroups.StaticFilter,
                                         CollisionFilterGroups.DefaultFilter);
            }

            foreach (var structureBspInstancedGeometryInstancesBlock in structureBSP.InstancedGeometryInstances)
            {
                var instanceMeshArray = new InfoTriangleIndexVertexArray();
                var structureBspInstancedGeometryDefinitionBlock = structureBSP.InstancedGeometriesDefinitions[structureBspInstancedGeometryInstancesBlock.InstanceDefinition];
                if (structureBspInstancedGeometryDefinitionBlock.RenderInfo.RenderData.Length < 1)
                {
                    continue;
                }

                var globalGeometrySectionStructBlock = structureBspInstancedGeometryDefinitionBlock.RenderInfo.RenderData[0].Section;
                if (!IsCollisionMesh(globalGeometrySectionStructBlock))
                {
                    continue;
                }

                var indexedMesh = GenerateBvhCollisionObjectFromMesh(globalGeometrySectionStructBlock, structureBspInstancedGeometryInstancesBlock.WorldMatrix);
                instanceMeshArray.AddIndexedMesh(indexedMesh);
                instanceMeshArray.AddIndexedMeshSurfaceData(globalGeometrySectionStructBlock);

                Vector3 aabbMin;
                Vector3 aabbMax;
                instanceMeshArray.CalculateAabbBruteForce(out aabbMin, out aabbMax);
                var bvhTriangleMeshShape = new BvhTriangleMeshShape(instanceMeshArray, true, aabbMin, aabbMax, true);
                bvhTriangleMeshShape.BuildOptimizedBvh();

                var collisionObject = new CollisionObject
                {
                    CollisionShape = bvhTriangleMeshShape,
                    UserObject     = "Instance"
                };
                World.AddCollisionObject(collisionObject, CollisionFilterGroups.StaticFilter, CollisionFilterGroups.DefaultFilter);
            }
            World.UpdateAabbs();
        }