def GetSolidAroundLine(line, radius): rad = math.pi * 2.0 / 3.0 triangle1 = [] triangle1.append((math.cos(0) * radius, math.sin(0) * radius, 0.0)) triangle1.append((math.cos(rad) * radius, math.sin(rad) * radius, 0.0)) triangle1.append( (math.cos(2 * rad) * radius, math.sin(2 * rad) * radius, 0.0)) dirOfLine = geo2.Vec3Normalize(geo2.Vec3Subtract(line[1], line[0])) if abs(geo2.Vec3Dot((0.0, 0.0, 1.0), dirOfLine)) != 1.0: rot = geo2.QuaternionRotationArc((0.0, 0.0, 1.0), dirOfLine) else: rot = geo2.QuaternionIdentity() rot = geo2.MatrixRotationQuaternion(rot) t1 = geo2.MatrixTranslation(*line[0]) t2 = geo2.MatrixTranslation(*line[1]) compA = geo2.MatrixMultiply(rot, t1) compB = geo2.MatrixMultiply(rot, t2) startTri = geo2.Vec3TransformCoordArray(triangle1, compA) endTri = geo2.Vec3TransformCoordArray(triangle1, compB) triangles = [ startTri[1], endTri[0], startTri[0], endTri[1], endTri[0], startTri[1], startTri[2], endTri[1], startTri[1], endTri[2], endTri[1], startTri[2], startTri[0], endTri[2], startTri[2], endTri[0], endTri[2], startTri[0] ] return triangles
def GetSafeSpotTransformMatrix(self): rotQuat = geo2.QuaternionRotationSetYawPitchRoll( self.GetSafeSpotYaw(), 0, 0) rotMatrix = geo2.MatrixRotationQuaternion(rotQuat) rotMatrix = geo2.MatrixInverse(rotMatrix) transMatrix = geo2.MatrixTranslation(*self.GetSafeSpotPosition()) return geo2.MatrixMultiply(rotMatrix, transMatrix)
def GetTargetPlaneProjectionMatrix(self): trans = self.GetTranslation() adjusted_translation = ProjectPointTowardsFrontPlane(trans) rmat = geo2.MatrixRotationQuaternion(self.GetRotation()) rmat = geo2.MatrixTranspose(rmat) mat = geo2.MatrixTranslation(adjusted_translation.x, adjusted_translation.y, adjusted_translation.z) self.frontPlaneTranslation = geo2.MatrixMultiply(rmat, mat) return self.frontPlaneTranslation
def fset(self, rotationQuaternion): rotationMatrix = geo2.MatrixRotationQuaternion(rotationQuaternion) transformedVec = geo2.Vec3Transform((1.0, 0.0, 0.0), rotationMatrix) cameraDistance = geo2.Vec3Length(self._eyePositionCurrent) self._eyePositionCurrent = geo2.Vec3Scale(transformedVec, cameraDistance) self._eyePosition = self._eyePositionCurrent
def AddToScene(self, entity, component): if component.trinityObject is None: component.trinityObject = trinity.Load(component.redFile) scene = self.graphicClient.GetScene(entity.scene.sceneID) if scene: scene.AddDynamic(component.trinityObject) positionComponent = entity.GetComponent('position') if positionComponent is not None and component.trinityObject is not None: component.trinityObject.transform = geo2.MatrixMultiply( geo2.MatrixRotationQuaternion(positionComponent.rotation), geo2.MatrixTranslation(positionComponent.position[0], positionComponent.position[1], positionComponent.position[2]))
def FollowCamera(self, target, aimTarget=None): viewStep, proj = self.GetViewAndProjection() if viewStep: viewStep.view = trinity.TriView() camera = sm.GetService('sceneManager').GetRegisteredCamera( None, defaultOnActiveCamera=True) globalSceneScale = 1.0 ballpark = sm.GetService('michelle').GetBallpark() ball = ballpark.GetBall(eve.session.shipid) self.resetCamera = False while not self.resetCamera and target: time = blue.os.GetSimTime() rot = target.rotationCurve if True: rotation = rot.GetQuaternionAt(time) translation = target.translationCurve.GetVectorAt(time) if ball: targetPos = ball.model.worldPosition targetVector = (targetPos[0] - translation.x, targetPos[0] - translation.x, targetPos[0] - translation.x) targetVector = geo2.Vec3Normalize(targetVector) dist = 100.0 elevation = 0.0 translation.x = translation.x - targetVector[0] * dist translation.y = translation.y - targetVector[ 1] * dist + elevation translation.z = translation.z - targetVector[2] * dist lookat = geo2.MatrixLookAtRH( (translation.x, translation.y, translation.z), targetPos, (0.0, 1.0, 0.0)) trans = geo2.MatrixTranslation( translation.x * globalSceneScale, translation.y * globalSceneScale, translation.z * globalSceneScale) rot = geo2.MatrixRotationQuaternion( (rotation.x, rotation.y, rotation.z, rotation.w)) if viewStep and viewStep.view: viewStep.view.transform = lookat blue.synchro.Yield() if viewStep: viewStep.view = None proj.projection = camera.projectionMatrix self.resetCamera = False
def _UpdateCameraAnimation(self, alignToParent=False, alignTargets=None, loop=False, clipName=None, parent=None): def FindParametersInPostFx(): blurScaleH = None blurScaleV = None blurFade = None exposure = None rj = self.GetRenderJob() if rj: for step in rj.steps: if step.name == 'RJ_POSTPROCESSING': if step.job: for jobStep in step.job.steps: if jobStep.name == 'PostProcess Blur': for fx in jobStep.PostProcess.stages: for param in fx.parameters: if param.name == 'ScalingFactor': if fx.name == 'Gaussian Horizontal Blur': blurScaleH = param if fx.name == 'Gaussianl Vertical Blur': blurScaleV = param if fx.name == '4x Up Filter and Add': blurFade = param if jobStep.name == 'PostProcess Exposure': for fx in jobStep.PostProcess.stages: for param in fx.parameters: if param.name == 'ScalingFactor': if fx.name == '4x Up Filter and Add': exposure = param return (blurScaleH, blurScaleV, blurFade, exposure) transformTrack = None shakeSequencer = None duration = 0.0 curveSetName = 'AnimatedCamera' scene = sm.GetService('sceneManager').GetRegisteredScene('default') viewStep, proj = self.GetViewAndProjection() camera = viewStep.camera for cset in scene.curveSets: if cset.name == curveSetName: transformTrack = cset.curves[0] if len(cset.curves) > 1: shakeSequencer = cset.curves[1] duration = transformTrack.duration - 1 / 10.0 oldFov = camera.fieldOfView ppJob.AddPostProcess('Blur', 'res:/fisfx/postprocess/blur.red') ppJob.AddPostProcess('Exposure', 'res:/fisfx/postprocess/exposure.red') blurScaleH, blurScaleV, blurFade, exposure = FindParametersInPostFx() ballpark = sm.GetService('michelle').GetBallpark() ball = ballpark.GetBall(session.shipid) if parent: ball = parent.translationCurve if alignTargets: ball = alignTargets[0] if viewStep: viewStep.view = trinity.TriView() startTime = blue.os.GetSimTime() if loop: endTime = startTime + 36000000000L else: endTime = startTime + duration * 10000000 time = startTime globalSceneScale = 4.0 / 30.0 * ball.model.boundingSphereRadius lastWorldPos = None lastWorldRot = None while time < endTime and not self.resetCamera and not self.interrupt: time = blue.os.GetSimTime() weight1 = 0.0 weight2 = 0.0 if self.vectorTracks: currentTime = trinity.device.animationTime for cvt in self.vectorTracks: if cvt == 'targetWeight1' or cvt == 'targetWeight2': vecTrack = self.vectorTracks[cvt] if cvt == 'targetWeight1': weight1 = vecTrack.value else: weight2 = vecTrack.value if viewStep: trans = geo2.MatrixTranslation( transformTrack.translation[0] * globalSceneScale, transformTrack.translation[1] * globalSceneScale, transformTrack.translation[2] * globalSceneScale) rot = geo2.MatrixRotationQuaternion(transformTrack.rotation) comp = geo2.MatrixMultiply(rot, trans) if alignToParent: if not ball.model and lastWorldPos: translation = lastWorldPos rotation = lastWorldRot else: rotation = ball.GetQuaternionAt(time) translation = ball.model.worldPosition lastWorldPos = translation lastWorldRot = rotation transOffset = geo2.MatrixTranslation( translation[0], translation[1], translation[2]) rotOffset = geo2.MatrixRotationQuaternion( (rotation.x, rotation.y, rotation.z, rotation.w)) comp = geo2.MatrixMultiply(comp, rotOffset) comp = geo2.MatrixMultiply(comp, transOffset) if alignTargets: t1 = alignTargets[0].model.worldPosition t2 = alignTargets[1].model.worldPosition if True: sphereOffset = alignTargets[ 1].model.boundingSphereCenter qr = alignTargets[ 1].model.rotationCurve.GetQuaternionAt(time) quatRotation = (qr.x, qr.y, qr.z, qr.w) correctedOffset = geo2.QuaternionTransformVector( quatRotation, sphereOffset) t2 = geo2.Vec3Add(t2, correctedOffset) rot = geo2.MatrixLookAtRH(t2, t1, (0.0, 1.0, 0.0)) rot = geo2.MatrixInverse(rot) rot = (rot[0], rot[1], rot[2], (t1[0], t1[1], t1[2], 1.0)) comp = geo2.MatrixMultiply(comp, rot) if weight1 > 0.0001: shake = shakeSequencer.value pos = (comp[3][0], comp[3][1], comp[3][2]) targetPos = (t2[0] + shake.x, t2[1] + shake.y, t2[2] + shake.z) lookat = geo2.MatrixLookAtRH(pos, targetPos, (0.0, 1.0, 0.0)) lookat = geo2.MatrixInverse(lookat) qlookat = geo2.QuaternionRotationMatrix(lookat) qorig = geo2.QuaternionRotationMatrix(comp) qresult = geo2.Lerp(qorig, qlookat, weight1) mresult = geo2.MatrixRotationQuaternion(qresult) comp = (mresult[0], mresult[1], mresult[2], comp[3]) if viewStep.view: viewStep.view.transform = geo2.MatrixInverse(comp) if self.vectorTracks: currentTime = trinity.device.animationTime for cvt in self.vectorTracks: if cvt == 'fov': vecTrack = self.vectorTracks['fov'] fovValue = vecTrack.value camera.fieldOfView = fovValue proj.projection.PerspectiveFov( fovValue, trinity.device.width / float(trinity.device.height), camera.frontClip, camera.backClip) if cvt == 'blur': vecTrack = self.vectorTracks['blur'] blurValue = vecTrack.value if blurScaleH and blurScaleV and blurFade: blurScaleH.value = blurValue blurScaleV.value = blurValue if blurValue > 0.01: blurFade.value = 1.0 else: blurFade.value = 0.0 if cvt == 'exposure': vecTrack = self.vectorTracks['exposure'] exposureValue = vecTrack.value if exposure: exposure.value = exposureValue if 'fov' not in self.vectorTracks: camera.fieldOfView = oldFov proj.projection.PerspectiveFov( oldFov, trinity.device.width / float(trinity.device.height), camera.frontClip, camera.backClip) blue.synchro.Yield() if exposure and blurFade: exposure.value = 0.0 blurFade.value = 0.0 if viewStep: viewStep.view = None camera.fieldOfView = oldFov if not self.interrupt: if not camera.fieldOfView == 1.0: self.LogWarn('Warning: Camera fov not 1, correcting...') camera.fieldOfView = 1.0 proj.projection = camera.projectionMatrix self.playingClip = False if self.continuousType and not self.interrupt and not self.resetCamera: self.interrupt = False self.UpdateContinuous() self.resetCamera = False self.interrupt = False if clipName: self.LogInfo('Camera clip done:', clipName)
def Rotate(self, rot): self.worldTranslation = geo2.MatrixRotationQuaternion(rot)