def __init__(self, pos, scale, base_rotate, modelPath, cam, col_scale, col_local_pos = [0,0,0], camfollow = False): # Create model to display on pyxie self.model = pyxie.figure(modelPath) self.model.position = pos self.model.scale = scale self.base_rotate = base_rotate self.model.rotation = vmath.quat(self.base_rotate) self.currentState = STATUS_STAY self.model.connectAnimator(pyxie.ANIMETION_SLOT_A0, STATE_MOTION[self.currentState]) # Create collider box to simulate physics on bullet physics self.colId = 0 self.col_scale = col_scale self.col_local_pos = col_local_pos self.lastContactId = -1 # Create box collider self.camFollow = camfollow self.__createColBox(10) self.tapped = False # Should this player have camera follow behind? if self.camFollow: self.cam = cam self.camDis = [0.0, -3.0, 1]
def __init__(self, pos, scale, modelPath, col_radius, col_height, col_local_pos=[0, 0, 0], base_quaternion=[0, 0, 0, 1], isStatic=False, isIteractable=False): # Create model to display on pyxie self.model = pyxie.figure(modelPath) self.model.position = pos self.model.scale = scale self.base_rotate = base_quaternion self.model.rotation = vmath.quat(self.base_rotate) # Create collider to simulate physics on bullet physics self.colId = 0 self.col_radius = col_radius self.col_height = col_height self.col_local_pos = col_local_pos # Create box collider self.isIteractable = isIteractable self.isStatic = isStatic if self.isStatic: self.__createCollider(0) else: self.__createCollider(1) # Depend on cube type should be iteractable or not if self.isIteractable: self.tapped = False
def replaceMesh(self, meshData): self.meshName = meshData self.mesh = pyxie.figure(meshData) self.mesh.position = vmath.vec3(self.gameObject.transform.position) self.mesh.rotation = vmath.quat( helperFunction.fromEulerToQuaternion( self.gameObject.transform.rotation)) self.mesh.scale = vmath.vec3(self.gameObject.transform.scale)
def __autoRePosition(self): pos, orn = p.getBasePositionAndOrientation(self.colId) quat = self.__autoReRotation(orn) self.model.rotation = quat local_v = vmath.rotate(vmath.vec3(self.col_local_pos), vmath.quat(orn)) pos_x = pos[0] - local_v.x pos_y = pos[1] - local_v.y pos_z = pos[2] - local_v.z model_pos = (pos_x, pos_y, pos_z) self.model.position = vmath.vec3(model_pos)
def __init__(self, gameObject, meshData): super().__init__(gameObject) self.meshName = meshData self.showOnInspector("meshName") self.mesh = pyxie.figure(meshData) self.mesh.position = vmath.vec3(self.gameObject.transform.position) self.mesh.rotation = vmath.quat( helperFunction.fromEulerToQuaternion( self.gameObject.transform.rotation)) self.mesh.scale = vmath.vec3(self.gameObject.transform.scale)
def __initialize(self): for i in range(0, self.matrix_scale): for j in range(0, self.matrix_scale): position = self.__getPositionAndScaleOfCube(i, j) scale = [ self.unit_scale.x / 2, self.unit_scale.y / 2, self.unit_scale.z / 2 ] pos_v3 = vmath.vec3(position) cube = Cube(pos_v3, self.unit_scale, self.texture_path, scale, [0, 0, 0], [0, 0, 0, 1], True) cube.model.rotation = vmath.quat([0, 0, 0, 1]) self.showcase.add(cube.model) self.cube_list.append(cube)
def __autoRePosition(self): pos, orn = p.getBasePositionAndOrientation(self.colId) quat = self.__autoReRotation(orn) self.model.rotation = quat local_v = vmath.rotate(vmath.vec3(self.col_local_pos), vmath.quat(orn)) pos_x = pos[0] - local_v.x pos_y = pos[1] - local_v.y pos_z = pos[2] - local_v.z model_pos = (pos_x, pos_y, pos_z) self.model.position = vmath.vec3(model_pos) # If this character have camfollow, make camera follow it if self.camFollow: self.cam.position = vmath.vec3(pos) + vmath.vec3(self.camDis) self.cam.target = vmath.vec3(pos)
def __init__(self, gameObject, colliderPath, showcase): super().__init__(gameObject) self.colType = "BOX COLLIDER" self.showOnInspector("colType") self.scale = self.gameObject.transform.scale self.showOnInspector("scale") self.isDisplay = True self.showOnInspector("isDisplay") self.showcase = showcase self.mesh = pyxie.figure(colliderPath) self.mesh.position = vmath.vec3(self.gameObject.transform.position) self.mesh.rotation = vmath.quat( helperFunction.fromEulerToQuaternion( self.gameObject.transform.rotation)) self.mesh.scale = vmath.vec3(self.gameObject.transform.scale) self.showcase.add(self.mesh)
def __init__(self, pos, scale, base_rotate, modelPath, cam, col_scale, col_local_pos=[0, 0, 0], camfollow=False): # Create model to display on pyxie self.model = pyxie.figure(modelPath) self.model.position = pos self.model.scale = scale self.base_rotate = base_rotate self.model.rotation = vmath.quat(self.base_rotate) self.currentState = STATUS_STAY self.nextState = STATUS_STAY # self.model.connectAnimator(pyxie.ANIMETION_SLOT_A0, STATE_MOTION[self.currentState]) # Create collider box to simulate physics on bullet physics self.colId = 0 self.col_scale = col_scale self.col_local_pos = col_local_pos self.lastContactId = -1 self.firstClick = False self.transitTime = 0.0 # Create box collider self.camFollow = camfollow self.__createColBox(10) self.tapped = False self.dragged = False self.abortCheckContact = False self.kEpsilon = 1.0 self.isDeath = False # Should this player have camera follow behind? if self.camFollow: self.cam = cam self.camDis = [0.0, -3.0, 2.0] # Previous touch self.previousTouchX = 0
def SimulateProcess(self): index = 1 for bd in self.bodies: if not bd: index += 1 continue if not self.firstTimeActive and bd not in self.activatedBodies: index += 1 continue pos, rot = p.getBasePositionAndOrientation(bd) self.model.setJoint(index, position=vmath.vec3(pos), rotation=vmath.quat(rot), scale=vmath.vec3(self.sizeMulti, self.sizeMulti, self.sizeMulti)) index += 1 if self.firstTimeActive: self.firstTimeActive = False
def ConstructPybulletProcess(self): boxinfo = [] with open("TestVoxel/boxinfo.pickle", "rb") as f: boxinfo = pickle.load(f) self.bodies = [] box1 = boxinfo[0] SCALE = 0.98 shape = p.createCollisionShape(p.GEOM_BOX, halfExtents=[ self.size / 2 * SCALE, self.size / 2 * SCALE, self.size / 2 * SCALE ]) for data in self.newBoxData: quat = [0.7071068, 0, 0, 0.7071068] vec = [ data[0] - self.center[0], data[1] - self.center[1], data[2] - self.center[2] ] newVec = vmath.rotate(vmath.vec3(vec), vmath.quat(quat)) newPos = [ newVec.x + self.center[0], newVec.y + self.center[1], newVec.z + self.center[2] ] body = p.createMultiBody(baseMass=0, baseCollisionShapeIndex=shape, basePosition=newPos) p.changeDynamics( bodyUniqueId=body, linkIndex=-1, mass=0, linearDamping=0.4, angularDamping=1, restitution=0.8, ) self.bodies.append(body)
def __init__(self, pos, scale, modelPath, col_scale, col_local_pos=[0, 0, 0], base_quaternion=[0, 0, 0, 1], isPlane=False, camfollow=False, isIteractable=False): # Create model to display on pyxie self.model = pyxie.figure(modelPath) # self.model.setMaterialRenderState() self.model.position = pos self.model.scale = scale self.base_rotate = base_quaternion self.model.rotation = vmath.quat(self.base_rotate) # Create collider to simulate physics on bullet physics self.colId = 0 self.col_scale = col_scale self.col_local_pos = col_local_pos # Create box collider self.isPlane = isPlane self.isIteractable = isIteractable if not self.isPlane: self.__createColBox(1) else: self.__createColBox(0) # Depend on cube type should be iteractable or not if self.isIteractable: self.tapped = False self.isDestroy = False
def __autoReTransform(self): self.mesh.position = vmath.vec3(self.gameObject.transform.position) self.mesh.rotation = vmath.quat( helperFunction.fromEulerToQuaternion( self.gameObject.transform.rotation)) self.mesh.scale = vmath.vec3(self.gameObject.transform.scale)
def __autoReRotation(self, rot_quat): fin_quat = vmath.mul(vmath.quat(rot_quat), vmath.quat(self.base_rotate)) return fin_quat