コード例 #1
0
ファイル: Car.py プロジェクト: BackupGGCode/autosim
 def initChassisByXml(self, physxScene, carNode):
     """ Loads chassis configuraiton from an xml file and applies to the car """
     # Start initializing the chassis ...
     chassisNode = carNode.getElementsByTagName( 'chassis' )[0]
     bodyNode = chassisNode.getElementsByTagName( 'body' )[0]
     
     bodyDesc = PhysxBodyDesc()
     bodyDesc.setMass( float( bodyNode.getAttribute( 'mass' ) ) )
     
     actorDesc = PhysxActorDesc()
     actorDesc.setName( 'Chassis' )
     actorDesc.setBody( bodyDesc )
     actorDesc.setGlobalPos( readPoint3( chassisNode.getElementsByTagName( 'global-pos' )[0] ) )
     
     boxShapeNodes = bodyNode.getElementsByTagName( 'boxshape' )
     for boxNode in boxShapeNodes:
         shapeDesc = PhysxBoxShapeDesc()
         shapeDesc.setDimensions( readVec3( boxNode.getElementsByTagName('dimensions')[0] ) )
         shapeDesc.setLocalPos( readPoint3( boxNode.getElementsByTagName('local-pos')[0] ) )
         actorDesc.addShape( shapeDesc )
         
     self.chassis = physxScene.createActor( actorDesc )
     vMassCenter = readPoint3( chassisNode.getElementsByTagName( 'center-of-mass' )[0] )
     self.chassis.setCMassOffsetLocalPos( vMassCenter )
     self.massCenter = vMassCenter 
     self.chassisModel = loader.loadModel( chassisNode.getAttribute( 'model' ))
     self.chassisModel.reparentTo( render )
     for hideNode in chassisNode.getElementsByTagName( 'hide' ):
         part = self.chassisModel.find( hideNode.getAttribute( 'part' ))
         if part is not None:
             part.hide()
     for mirrorNode in chassisNode.getElementsByTagName( 'mirror' ):
         mirror = self.chassisModel.find( mirrorNode.getAttribute( 'part' ) )
         if mirror is not None:
             self.setAsMirror( mirror )
コード例 #2
0
ファイル: default.py プロジェクト: BackupGGCode/autosim
    def initTrack(self):
        """ Loads the track model and the collision model for it. """
        kitchen = PhysxKitchen()
        
        trackCollision = loader.loadModel( "Resources/Models/TrackCollision.egg" )
        fenceCollision = loader.loadModel( "Resources/Models/FenceCollision.egg")
        self.track = loader.loadModel( "Resources/Models/Track.egg" )

        triMeshDesc = PhysxTriangleMeshDesc()
        triMeshDesc.setFromNodePath( trackCollision )
        triMesh = kitchen.cookTriangleMesh( triMeshDesc )
        triMeshShapeDesc = PhysxTriangleMeshShapeDesc()
        triMeshShapeDesc.setMesh( triMesh )
        
        triMeshDesc2 = PhysxTriangleMeshDesc()
        triMeshDesc2.setFromNodePath( fenceCollision )
        triMesh2 = kitchen.cookTriangleMesh( triMeshDesc2 )
        triMeshShapeDesc2 = PhysxTriangleMeshShapeDesc()
        triMeshShapeDesc2.setMesh( triMesh2 )
        
        actor = PhysxActorDesc()
        actor.setName( 'trackcollision' )
        actor.addShape( triMeshShapeDesc )
        actor.addShape( triMeshShapeDesc2 )
        self.physxtrack = self.physxScene.createActor( actor )
        
        self.track.reparentTo( render )
        loader.loadModel( "Resources/Models/Fence.egg" ).reparentTo( self.track )
        loader.loadModel( "Resources/Models/Rocks.egg" ).reparentTo( self.track )
        
        linfog = Fog( "Fog" )
        linfog.setColor( Vec4( 0.8, 0.85, 0.8, 1 ) )
        linfog.setExpDensity( 0.003 )
        self.track.attachNewNode(linfog)
        render.setFog(linfog)
コード例 #3
0
ファイル: Car.py プロジェクト: aricwang88/autosim
    def initChassisByXml(self, physxScene, carNode):
        """ Loads chassis configuraiton from an xml file and applies to the car """
        # Start initializing the chassis ...
        chassisNode = carNode.getElementsByTagName('chassis')[0]
        bodyNode = chassisNode.getElementsByTagName('body')[0]

        bodyDesc = PhysxBodyDesc()
        bodyDesc.setMass(float(bodyNode.getAttribute('mass')))

        actorDesc = PhysxActorDesc()
        actorDesc.setName('Chassis')
        actorDesc.setBody(bodyDesc)
        actorDesc.setGlobalPos(
            readPoint3(chassisNode.getElementsByTagName('global-pos')[0]))

        boxShapeNodes = bodyNode.getElementsByTagName('boxshape')
        for boxNode in boxShapeNodes:
            shapeDesc = PhysxBoxShapeDesc()
            shapeDesc.setDimensions(
                readVec3(boxNode.getElementsByTagName('dimensions')[0]))
            shapeDesc.setLocalPos(
                readPoint3(boxNode.getElementsByTagName('local-pos')[0]))
            actorDesc.addShape(shapeDesc)

        self.chassis = physxScene.createActor(actorDesc)
        vMassCenter = readPoint3(
            chassisNode.getElementsByTagName('center-of-mass')[0])
        self.chassis.setCMassOffsetLocalPos(vMassCenter)
        self.massCenter = vMassCenter
        self.chassisModel = loader.loadModel(chassisNode.getAttribute('model'))
        self.chassisModel.reparentTo(render)
        for hideNode in chassisNode.getElementsByTagName('hide'):
            part = self.chassisModel.find(hideNode.getAttribute('part'))
            if part is not None:
                part.hide()
        for mirrorNode in chassisNode.getElementsByTagName('mirror'):
            mirror = self.chassisModel.find(mirrorNode.getAttribute('part'))
            if mirror is not None:
                self.setAsMirror(mirror)
コード例 #4
0
ファイル: default.py プロジェクト: aricwang88/autosim
    def initTrack(self):
        """ Loads the track model and the collision model for it. """
        kitchen = PhysxKitchen()

        trackCollision = loader.loadModel(
            "Resources/Models/TrackCollision.egg")
        fenceCollision = loader.loadModel(
            "Resources/Models/FenceCollision.egg")
        self.track = loader.loadModel("Resources/Models/Track.egg")

        triMeshDesc = PhysxTriangleMeshDesc()
        triMeshDesc.setFromNodePath(trackCollision)
        triMesh = kitchen.cookTriangleMesh(triMeshDesc)
        triMeshShapeDesc = PhysxTriangleMeshShapeDesc()
        triMeshShapeDesc.setMesh(triMesh)

        triMeshDesc2 = PhysxTriangleMeshDesc()
        triMeshDesc2.setFromNodePath(fenceCollision)
        triMesh2 = kitchen.cookTriangleMesh(triMeshDesc2)
        triMeshShapeDesc2 = PhysxTriangleMeshShapeDesc()
        triMeshShapeDesc2.setMesh(triMesh2)

        actor = PhysxActorDesc()
        actor.setName('trackcollision')
        actor.addShape(triMeshShapeDesc)
        actor.addShape(triMeshShapeDesc2)
        self.physxtrack = self.physxScene.createActor(actor)

        self.track.reparentTo(render)
        loader.loadModel("Resources/Models/Fence.egg").reparentTo(self.track)
        loader.loadModel("Resources/Models/Rocks.egg").reparentTo(self.track)

        linfog = Fog("Fog")
        linfog.setColor(Vec4(0.8, 0.85, 0.8, 1))
        linfog.setExpDensity(0.003)
        self.track.attachNewNode(linfog)
        render.setFog(linfog)