示例#1
0
    def __init__(self, sceneManager):
        bullet.btIDebugDraw.__init__(self)

        self.mDebugMode = bullet.btIDebugDraw.DBG_DrawWireframe
        self.beginLineUpdates = False
        self.beginTriUpdates = False
        self.mContactPoints = []

        mLines = ogre.ManualObject("Bullet Physics lines")
        mTriangles = ogre.ManualObject("Bullet Physics triangles")
        mLines.setDynamic(True)
        mTriangles.setDynamic(True)
        self.mSceneManager = sceneManager
        self.mSceneManager.getRootSceneNode().attachObject(mLines)
        self.mSceneManager.getRootSceneNode().attachObject(mTriangles)

        matName = "OgreBulletCollisionsDebugDefault"
        mtl = ogre.MaterialManager.getSingleton().getDefaultSettings().clone(
            matName)
        mtl.setReceiveShadows(False)
        mtl.setSceneBlending(ogre.SBT_TRANSPARENT_ALPHA)
        mtl.setDepthBias(0.1, 0)
        tu = mtl.getTechnique(0).getPass(0).createTextureUnitState()
        tu.setColourOperationEx(ogre.LBX_SOURCE1, ogre.LBS_DIFFUSE)
        mtl.getTechnique(0).setLightingEnabled(False)
        ##mtl.getTechnique(0).setSelfIllumination( ogre.ColourValue().White )

        mLines.begin(matName, ogre.RenderOperation.OT_LINE_LIST)
        mLines.position(ogre.Vector3().ZERO)
        mLines.colour(ogre.ColourValue().Blue)
        mLines.position(ogre.Vector3().ZERO)
        mLines.colour(ogre.ColourValue().Blue)

        mTriangles.begin(matName, ogre.RenderOperation.OT_TRIANGLE_LIST)
        mTriangles.position(ogre.Vector3().ZERO)
        mTriangles.colour(ogre.ColourValue().Blue)
        mTriangles.position(ogre.Vector3().ZERO)
        mTriangles.colour(ogre.ColourValue().Blue)
        mTriangles.position(ogre.Vector3().ZERO)
        mTriangles.colour(ogre.ColourValue().Blue)

        self.mLines = mLines
        self.mTriangles = mTriangles
示例#2
0
def create():
    """Create a procedural Terrain entity."""
    terrain_id = entitysystem.create_entity()
    logging.debug('Terrain id: ' + str(terrain_id))

    # Map the terrain onto an Ogre mesh
    width = height = 100
    offsetX = width / 2.0
    offsetY = height / 2.0
    terrain_object = ogre.ManualObject('Manual-' + str(terrain_id))
    terrain_object.estimateVertexCount(width * height)
    terrain_object.estimateIndexCount(width * height)

    # Generate heights and input the indices into OGRE.
    terrain_object.begin("Terrain_Azul", ogre.RenderOperation.OT_TRIANGLE_LIST)
    for row in range(height):
        for column in range(width):
            terrain_height = simplexnoise.scaled_octave_noise_2d(
                3,
                0.3,
                0.05,  # Noise settings
                -20,
                0,  # Height range
                column - offsetX,
                row - offsetY)
            terrain_object.position(
                column - offsetX,  # x
                terrain_height,  # y
                row - offsetY  # z
            )
            #XXX: these normals are fake and will break lighting
            terrain_object.normal(0, 1, 0)
            terrain_object.colour(abs(terrain_height / 20),
                                  abs(terrain_height / 20),
                                  abs(terrain_height / 20), 1)

    # Build a mesh of vertices.
    vertexID = 0
    for strip in range(height - 1):
        for quad in range(width - 1):
            terrain_object.quad(
                vertexID,  # top-left
                vertexID + width,  # bottom-left
                vertexID + width + 1,  # bottom-right
                vertexID + 1  # top-right
            )
            vertexID += 1
        vertexID += 1
    terrain_object.end()

    # Attach mesh to OGRE scene.
    terrain_object.convertToMesh('Mesh-' + str(terrain_id))
    ogre_entity = application.ogre_scene_manager.createEntity(
        'ogreEntity-' + str(terrain_id), 'Mesh-' + str(terrain_id))
    ogre_node = application.ogre_root_node.createChildSceneNode(
        'ogreNode-' + str(terrain_id))
    ogre_node.attachObject(ogre_entity)
    ogre_entity.setCastShadows(False)
    entitysystem.add_component(terrain_id,
                               entitysystem.ComponentTypes.Graphics, ogre_node)

    # Setup terrain collisions.
    collision_object = OgreBulletUtils.CollisionObject(
        application.bullet_world)
    triangle_mesh, collision_shape = OgreBulletUtils.MeshInfo.createTriMeshShape(
        ogre_entity)
    collision_object.setShape(collision_shape)
    collision_object.setMotion(None)
    entitysystem.add_component(terrain_id, entitysystem.ComponentTypes.Physics,
                               (collision_object, triangle_mesh))