當前位置: 首頁>>代碼示例>>Python>>正文


Python BulletTriangleMesh.addGeom方法代碼示例

本文整理匯總了Python中panda3d.bullet.BulletTriangleMesh.addGeom方法的典型用法代碼示例。如果您正苦於以下問題:Python BulletTriangleMesh.addGeom方法的具體用法?Python BulletTriangleMesh.addGeom怎麽用?Python BulletTriangleMesh.addGeom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在panda3d.bullet.BulletTriangleMesh的用法示例。


在下文中一共展示了BulletTriangleMesh.addGeom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: addMeshConvexRB

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def addMeshConvexRB(self,vertices, faces,ghost=False,**kw):
        #step 1) create GeomVertexData and add vertex information
        format=GeomVertexFormat.getV3()
        vdata=GeomVertexData("vertices", format, Geom.UHStatic)
        
        vertexWriter=GeomVertexWriter(vdata, "vertex")
        [vertexWriter.addData3f(v[0],v[1],v[2]) for v in vertices]
        
        #step 2) make primitives and assign vertices to them
        tris=GeomTriangles(Geom.UHStatic)
        [self.setGeomFaces(tris,face) for face in faces]
        
        #step 3) make a Geom object to hold the primitives
        geom=Geom(vdata)
        geom.addPrimitive(tris)
        
        #step 4) create the bullet mesh and node
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)

        shape = BulletConvexHullShape(mesh, dynamic=not ghost)#
        if ghost :
            inodenp = self.worldNP.attachNewNode(BulletGhostNode('Mesh'))
        else :
            inodenp = self.worldNP.attachNewNode(BulletRigidBodyNode('Mesh'))
        inodenp.node().addShape(shape)
#        inodenp.setPos(0, 0, 0.1)
        self.setRB(inodenp,**kw)
        inodenp.setCollideMask(BitMask32.allOn())
   
        self.world.attachRigidBody(inodenp.node())
        return inodenp
開發者ID:brettbarbaro,項目名稱:autoPACK,代碼行數:34,代碼來源:pandautil.py

示例2: genCollisionMeshMultiNp

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
def genCollisionMeshMultiNp(nodepath, basenodepath=None, name='autogen'):
    """
    generate the collision mesh of a nodepath using nodepath
    this function suppose the nodepath has multiple models with many geomnodes

    use genCollisionMeshMultiNp instead of genCollisionMeshNp for generality

    :param nodepath: the panda3d nodepath of the object
    :param basenodepath: the nodepath to compute relative transform, identity if none
    :param name: the name of the rigidbody
    :return: bulletrigidbody

    author: weiwei
    date: 20161212, tsukuba
    """

    gndcollection = nodepath.findAllMatches("**/+GeomNode")
    geombullnode = BulletRigidBodyNode(name)
    for gnd in gndcollection:
        geom = gnd.node().getGeom(0)
        geomtf = gnd.getTransform(base.render)
        if basenodepath is not None:
            geomtf = gnd.getTransform(basenodepath)
        geombullmesh = BulletTriangleMesh()
        geombullmesh.addGeom(geom)
        bullettmshape = BulletTriangleMeshShape(geombullmesh, dynamic=True)
        bullettmshape.setMargin(0)
        geombullnode.addShape(bullettmshape, geomtf)
    return geombullnode
開發者ID:wanweiwei07,項目名稱:pyhiro,代碼行數:31,代碼來源:collisiondetection.py

示例3: rayHit

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
def rayHit(pfrom, pto, geom):
    """
    NOTE: this function is quite slow
    find the nearest collision point between vec(pto-pfrom) and the mesh of nodepath

    :param pfrom: starting point of the ray, Point3
    :param pto: ending point of the ray, Point3
    :param geom: meshmodel, a panda3d datatype
    :return: None or Point3

    author: weiwei
    date: 20161201
    """

    bulletworld = BulletWorld()
    facetmesh = BulletTriangleMesh()
    facetmesh.addGeom(geom)
    facetmeshnode = BulletRigidBodyNode('facet')
    bullettmshape = BulletTriangleMeshShape(facetmesh, dynamic=True)
    bullettmshape.setMargin(0)
    facetmeshnode.addShape(bullettmshape)
    bulletworld.attachRigidBody(facetmeshnode)
    result = bulletworld.rayTestClosest(pfrom, pto)

    if result.hasHit():
        return result.getHitPos()
    else:
        return None
開發者ID:wanweiwei07,項目名稱:pyhiro,代碼行數:30,代碼來源:collisiondetection.py

示例4: __init__

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
	def __init__(self, name, modelPath, displayModelPath, game, pos):
		self.name = name
		self.modelPath = modelPath
		self.game = game
		
		self.model = self.game.loader.loadModel(self.modelPath)
		geomNodes = self.model.findAllMatches('**/+GeomNode')
		self.geomNode = geomNodes.getPath(0).node()
		self.geom = self.geomNode.getGeom(0)
		
		#self.shape = BulletConvexHullShape()
		#self.shape.addGeom(self.geom)
		
		mesh = BulletTriangleMesh()
		mesh.addGeom(self.geom)
		self.shape = BulletTriangleMeshShape(mesh, dynamic=False)
		
		self.node = BulletRigidBodyNode(self.name)
		self.node.addShape(self.shape)
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(pos)
		self.game.world.attachRigidBody(self.node)
		
		#self.model.reparentTo(self.np)
		
		self.displayModel = self.game.loader.loadModel(displayModelPath)
		self.displayModel.reparentTo(self.np)
		self.displayModel.setTwoSided(True)
		self.slice_able = False
開發者ID:arikel,項目名稱:PPARPG,代碼行數:32,代碼來源:bulletHandler.py

示例5: __init__

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def __init__(self, model, world, worldNP, pos, scale, hpr):
        self.worldNP = worldNP
        bulletWorld = world

        # Initialize the model.
        self.AIModel = loader.loadModel(model)
        self.AINode = BulletRigidBodyNode("AIChar")
        self.AIModel.setScale(scale)
        self.AIModel.flattenLight()  # Combines all geom nodes into one geom node.

        # Build the triangle mesh shape and attach it with the transform.
        geom = self.AIModel.findAllMatches("**/+GeomNode").getPath(0).node().getGeom(0)
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)
        self.AINode.addShape(shape, TransformState.makePosHprScale(Point3(0, 0, 0), hpr, scale))
        self.AINode.setMass(0)
        bulletWorld.attachRigidBody(self.AINode)

        # Apply the same transforms on the model being rendered.
        self.AIModel.reparentTo(render)
        self.AIModel.setH(hpr.getX())
        self.AIModel.setP(hpr.getY())
        self.AIModel.setR(hpr.getZ())
        self.AINode.setAngularFactor(Vec3(0, 0, 0))

        # Attach it to the world.
        self.AIChar = self.worldNP.attachNewNode(self.AINode)
        self.AIModel.reparentTo(self.AIChar)
        self.AIChar.setPos(pos)
開發者ID:tbackus127,項目名稱:AbominableSnowmanGame,代碼行數:32,代碼來源:SMCollide.py

示例6: ModelToBTS

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
def ModelToBTS(model):
    geomnodes = model.findAllMatches('**/+GeomNode')
    gn = geomnodes.getPath(0).node()
    geom = gn.getGeom(0)
    mesh = BulletTriangleMesh()
    mesh.addGeom(geom)
    shape = BulletTriangleMeshShape(mesh, dynamic=False)
    return shape
開發者ID:Sorrowkun,項目名稱:testPanda,代碼行數:10,代碼來源:Application.py

示例7: __init__

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def __init__(self, bulletWorld):

        self.env = loader.loadModel("models/env")
        self.env.reparentTo(render)
        self.env.setPos(0,0,-6)
        self.env.setScale(400)
        self.environ_tex = loader.loadTexture("models/tex/env_sky.jpg")
        self.env.setTexture(self.environ_tex, 1)
        self.period_cloud = self.env.hprInterval(400, (360, 0, 0))
        self.period_cloud.loop()

        self.ground = loader.loadModel("models/Ground2")
        self.ground.reparentTo(render)
        self.ground.setPos(0,0,-5)
        self.ground.setScale(0.5,0.5,0)
        self.ground_tex = loader.loadTexture("models/tex/ground.tif")
        self.ground.setTexture(self.ground_tex, 1)

        # model used as collision mesh
        collisionModel = loader.loadModel('models/Track2')
        # model used as display model
        model = loader.loadModel('models/Track2')

        tex = loader.loadTexture("models/tex/Main.png")
        model.setTexture(tex)
        # renders track from two camera views
        model.setTwoSided(True)

        collisionModel.setScale(1, 1, 100)

        mesh = BulletTriangleMesh()
        for geomNP in collisionModel.findAllMatches('**/+GeomNode'):
            geomNode = geomNP.node()
            ts = geomNP.getTransform(collisionModel)
            for geom in geomNode.getGeoms():
                mesh.addGeom(geom, ts)

        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        self.rigidNode = BulletRigidBodyNode('Heightfield')
        self.rigidNode.notifyCollisions(False)
        np = render.attachNewNode(self.rigidNode)
        np.node().addShape(shape)

        model.setScale(1, 1, .1)
        model.reparentTo(np)
        np.setScale(.7)
        np.setPos(0, 0, -5)
        np.setCollideMask(BitMask32(0xf0))
        np.node().notifyCollisions(False)
        bulletWorld.attachRigidBody(np.node())

        self.hf = np.node()  # To enable/disable debug visualisation
        
        
開發者ID:2015-CS454,項目名稱:rr-team,代碼行數:55,代碼來源:Track2.py

示例8: renderObject

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
	def renderObject(self,scale,hpr,collisionOn=False):
		(x_scale,y_scale,z_scale) = scale
		(h,p,r) = hpr
		if collisionOn is True:
			if self.name is 'wide_ramp':
				(x_c,y_c,z_c) = (x_scale + .2,y_scale+2.5,z_scale+1.75)
			if self.name is 'tree1':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)
			if self.name is 'tree2':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)
			if self.name is 'rock1':
				(x_c,y_c,z_c) = (x_scale * 2,y_scale * 2,z_scale*2)
			if self.name is 'rock2':
				(x_c,y_c,z_c) = (x_scale*100,y_scale*100,z_scale*100)
			if self.name is 'gate':
				(x_c,y_c,z_c) = (x_scale * 10,y_scale,z_scale*3.5)
			if self.name is 'statue':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)

       			mesh = BulletTriangleMesh()
        		for geomNP in self.model.findAllMatches('**/+GeomNode'):
            			geomNode = geomNP.node()
            			ts = geomNP.getTransform(self.model)
          		for geom in geomNode.getGeoms():
                		mesh.addGeom(geom, ts)

        		shape = BulletTriangleMeshShape(mesh, dynamic=False)

            		node = BulletRigidBodyNode(self.name)
            		node.setMass(0)
            		node.addShape(shape)

			np = self.__game.render.attachNewNode(node)
			np.setPos(self.x,self.y,self.z)
			np.setHpr(h,p,r)
			np.setScale(x_c,y_c,z_c)

			self.__game.world.attachRigidBody(node)
		self.model.setPos(self.x,self.y,self.z)
		self.model.setHpr(h,p,r)
		self.model.setScale(x_scale,y_scale,z_scale)
		self.model.reparentTo(self.__game.render)
		
		if self.name is 'statue':
			plat_texture = loader.loadTexture('models/textures/rocky.jpg')
		        self.model.setTexture(plat_texture,1)
			ts = TextureStage.getDefault()
	       	 	texture = self.model.getTexture()
			self.model.setTexScale(ts, 1, 1)
開發者ID:cgaldamez14,項目名稱:rolling-eve,代碼行數:51,代碼來源:envobject.py

示例9: setupCollisionMeshAndRigidNodeFromModel

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def setupCollisionMeshAndRigidNodeFromModel(self):
        mesh = BulletTriangleMesh()
        for geomNP in self.floorModel.findAllMatches('**/+GeomNode'):
            geomNode = geomNP.node()
            ts = geomNP.getTransform(self.floorModel)
            for geom in geomNode.getGeoms():
                mesh.addGeom(geom, ts)

        shape = BulletTriangleMeshShape(mesh, dynamic=False)
        self.rigidNode = BulletRigidBodyNode('Floor')
        self.rigidNode.notifyCollisions(False)

        self.rigidNodePath = self.parentNodePath.attachNewNode(self.rigidNode)
        self.rigidNodePath.node().addShape(shape)
        self.rigidNodePath.setScale(12, 12, 1.5)
        self.rigidNodePath.setCollideMask(BitMask32.allOn())
        self.rigidNodePath.node().notifyCollisions(False)
開發者ID:genusgant,項目名稱:CS594-ThrottleThunder-GameClient,代碼行數:19,代碼來源:Terrain.py

示例10: createPlatform

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def createPlatform(self, x, y, z):
        self.platform = loader.loadModel('../models/disk/disk.egg')
        geomnodes = self.platform.findAllMatches('**/+GeomNode')
        gn = geomnodes.getPath(0).node()
        geom = gn.getGeom(0)
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        node = BulletRigidBodyNode('Platform')
        node.setMass(0)
        node.addShape(shape)
        platformnn = render.attachNewNode(node)
        platformnn.setPos(x, y, z)
        platformnn.setScale(3)

        self.world.attachRigidBody(node)
        self.platform.reparentTo(platformnn)
開發者ID:laylaxh,項目名稱:infinite-loop,代碼行數:20,代碼來源:level_1.py

示例11: __addTriangleMesh

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def __addTriangleMesh(self, body, model, pos=(0,0,0), hpr=(0,0,0), scale=(1,1,1), dynamic=True):        
        
        mesh = BulletTriangleMesh()
      
        def one():
            geom = model.node().getGeom(0)            
            mesh.addGeom(geom)
            return []

        children =  model.findAllMatches('**/+GeomNode') or one()

        model.flattenLight()

        for piece in children:
            geom = piece.node().getGeom(0)
            mesh.addGeom(geom)

        shape = BulletTriangleMeshShape(mesh, dynamic=dynamic )
        body.addShape( shape, TransformState.makePosHprScale(pos,hpr,scale) )
開發者ID:fredukita,項目名稱:Pandark-Project,代碼行數:21,代碼來源:physicsmanager.py

示例12: createWall

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def createWall(self, x, y, z, h):
        self.wall = loader.loadModel('../models/wall/wall.egg')
        geomnodes = self.wall.findAllMatches('**/+GeomNode')
        gn = geomnodes.getPath(0).node()
        geom = gn.getGeom(0)
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom)
        shape = BulletTriangleMeshShape(mesh, dynamic=False)

        wallNode = BulletRigidBodyNode('Wall')
        wallNode.setMass(0)
        wallNode.addShape(shape)
        wallnn = render.attachNewNode(wallNode)
        wallnn.setPos(x, y, z)
        wallnn.setH(h)
        wallnn.setScale(0.5, 50.5, 4.5)

        self.world.attachRigidBody(wallNode)
        self.wall.reparentTo(wallnn)
開發者ID:laylaxh,項目名稱:infinite-loop,代碼行數:21,代碼來源:level_1.py

示例13: _createBulletShape_

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
  def _createBulletShape_(self,np, apply_scale = True, apply_transform = True):
    """
    @brief Creates a BulletTriangleMeshShape from the geometries in the model node.  The passed
    node path must point to a GeomNode type.  The Geom objects are then added to a 
    BulletTriangleMesh object which is then used to initialize the Shape.  Optionally, 
    the node's transform and scaled can be baked into the Geometries (recommended 
    according to the Panda3D guide https://www.panda3d.org/manual/index.php/Bullet_FAQ).
    If you apply the scale and transform make sure not to apply them again to the shape or
    the bullet node that contains the shape as it'll compound the effect.
    @warning: If the underlying GeomNode contains multiple geometries each with a different
    transform and scale then it's best to set apply_scale and apply_transform to True.
    @param np: The nodepath containing the GeomNode
    @param apply_scale: Boolean that allows choosing whether or not to apply the nodepath's scale to the geometries
    @param apply_transform: Boolean that indicates whether or not to apply the nodepath's trasform to the geometries.
    @return:  A BulletTriangleMeshShape object containing the node's geometries
    """
    
    geom_node = np.node()
    if type(geom_node) is not GeomNode:
      logging.error("Node %s is not a GeomNode node type"%(np.getName()))
      return None
    
    bullet_mesh = BulletTriangleMesh()
        
    # Assembling transform
    tr = TransformState.makeIdentity()
    geom_scale = np.getScale()
    if apply_transform:
      tr = tr.setPos(np.getPos())
      tr = tr.setQuat(np.getQuat())
      sc = LPoint3(1)
      tr = tr.setScale(sc)
    if apply_scale: # baking scale into geometry data
      tr = tr.setScale(geom_scale)    

    for geom in geom_node.getGeoms():      
      bullet_mesh.addGeom(geom,True,tr)
    
    bullet_shape = BulletTriangleMeshShape(bullet_mesh,False,True,True)    
    bullet_shape.setMargin(GameObject.DEFAULT_COLLISION_MARGIN)
    
    return bullet_shape
開發者ID:jrgnicho,項目名稱:platformer_games_project,代碼行數:44,代碼來源:level_loader.py

示例14: _create_bullet_nodepath

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
    def _create_bullet_nodepath(geom, geom_node, entity):
        bullet_node = BulletRigidBodyNode("NavmeshCollision")

        transform = geom_node.getTransform()
        mesh = BulletTriangleMesh()
        mesh.addGeom(geom, True, transform)

        shape = BulletTriangleMeshShape(mesh, dynamic=False)
        bullet_node.addShape(shape)

        mask = BitMask32()
        mask.set_word(CollisionGroups.navmesh)

        bullet_node.set_into_collide_mask(mask)

        # Associate with entity
        bullet_nodepath = base.render.attachNewNode(bullet_node)
        bullet_nodepath.set_python_tag("entity", entity)

        return bullet_nodepath
開發者ID:TurBoss,項目名稱:PyAuthServer,代碼行數:22,代碼來源:definitions.py

示例15: genCollisionMeshGeom

# 需要導入模塊: from panda3d.bullet import BulletTriangleMesh [as 別名]
# 或者: from panda3d.bullet.BulletTriangleMesh import addGeom [as 別名]
def genCollisionMeshGeom(geom, name='autogen'):
    """
    generate the collision mesh of a nodepath using geom

    :param geom: the panda3d geom of the object
    :param basenodepath: the nodepath to compute relative transform
    :return: bulletrigidbody

    author: weiwei
    date: 20161212, tsukuba
    """

    geomtf = TransformState.makeIdentity()
    geombullmesh = BulletTriangleMesh()
    geombullmesh.addGeom(geom)
    geombullnode = BulletRigidBodyNode(name)
    bullettmshape = BulletTriangleMeshShape(geombullmesh, dynamic=True)
    bullettmshape.setMargin(0)
    geombullnode.addShape(bullettmshape, geomtf)
    return geombullnode
開發者ID:wanweiwei07,項目名稱:pyhiro,代碼行數:22,代碼來源:collisiondetection.py


注:本文中的panda3d.bullet.BulletTriangleMesh.addGeom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。