def handleWheelCameraSpeed( self, mz ): # look at the rotator for changing the camera speed c = WorldEditor.camera() currentValue = WorldEditor.getOptionString( "camera/speed" ) speeds = ["Slow", "Medium", "Fast", "SuperFast"] iSpeed = 0 if currentValue == speeds[1]: iSpeed = 1 elif currentValue == speeds[2]: iSpeed = 2 elif currentValue == speeds[3]: iSpeed = 3 if mz > 0: iSpeed = iSpeed + 1 if iSpeed > 3: iSpeed = 3 elif mz < 0: iSpeed = iSpeed - 1 if iSpeed < 0: iSpeed = 0 value = speeds[iSpeed] handled = 0 if value != currentValue: c = WorldEditor.camera() WorldEditor.setOptionString( "camera/speed", value ) c.speed = WorldEditor.getOptionFloat( "camera/speed/" + value ) c.turboSpeed = WorldEditor.getOptionFloat( "camera/speed/" + value + "/turbo" ) handled = 1 WorldEditor.addCommentaryMsg( "New camera speed %s" % value, 1 ) return handled
def updateState( self, dTime ): GUI.update( dTime ) self.cc.update( dTime ) WorldEditor.camera().update( dTime ) if not WorldEditor.tool().applying: self.objInfo.overGizmo = WorldEditor.gizmoUpdate( WorldEditor.worldRay() ) WorldEditor.update( dTime ) return 1
def render( self, dTime ): """This function forces World Editor to render everything on the scene. Usually called everyframe, however it still recieves a dTime value which informs the renderer how much time has passed since the last render call.""" WorldEditor.camera().render( dTime ) WorldEditor.render( dTime ) GUI.draw() return 1
def onMouseEvent( self, mx, my, mz ): handled = 0 if not handled: handled = WorldEditor.tool().handleMouseEvent( mx, my, mz ) if not handled: handled = WorldEditor.camera().handleMouseEvent( mx, my, mz ) return handled
def onKeyEvent( self, isDown, key, modifiers ): if not WorldEditor.cursorOverGraphicsWnd(): return 0 if key == KEY_RIGHTMOUSE: if ( not self.rightMouseButtonDown ) and isDown: self.rightMouseButtonDown = 1 self.mouseMoved = 0 elif self.rightMouseButtonDown and not isDown: self.rightMouseButtonDown = 0 if not self.mouseMoved: self.onRightMouse() handled = 0 if self.avatarMode and key == KEY_Q: self.qDown = isDown self.eDown = 0 handled = 1 if self.avatarMode and key == KEY_E: self.eDown = isDown self.qDown = 0 handled = 1 if not handled: handled = WorldEditor.camera().handleKeyEvent( isDown, key, modifiers ) if not handled and isDown: handled = self.ownKeyEvent( key, modifiers ) if not handled and WorldEditor.tool() != None: handled = WorldEditor.tool().handleKeyEvent( isDown, key, modifiers ) if not handled and isDown and key == KEY_LEFTMOUSE and self.objInfo.overGizmo: WorldEditor.gizmoClick() handled = 1 return handled
def _onInput(self, position, yaw, pitch, roll): self._parent.setRotateYPR(Math.Vector3(yaw, pitch, roll)) self._parent.translation = position if IS_CLIENT: if g_hangarSpace is not None: clientHangarSpace = g_hangarSpace.space if clientHangarSpace: strategy = clientHangarSpace.hangarCamera.getStateStrategy( ) if strategy and isinstance( strategy, BigWorld.CameraStrategySuperFree): direction = Math.Vector3(self._parent.get(2, 0), self._parent.get(2, 1), self._parent.get(2, 2)) fakeTarget = Math.Vector3(position.x + direction.x, position.y + direction.y, position.z + direction.z) self._source.setTranslate(position) self._target.setTranslate(fakeTarget) strategy.sourceProvider = self._source strategy.targetProvider = self._target BigWorld.camera().parentMatrix = self._parent else: import WorldEditor self._parent.invert() WorldEditor.camera(0).view = self._parent return 'out'
def onStart( self ): c = WorldEditor.camera() c.speed = WorldEditor.getOptionFloat( "app/cameraSpeed" ) c.turboSpeed = WorldEditor.getOptionFloat( "app/cameraSpeed2" ) self.alphafunc = Functor.TerrainTextureFunctor() self.guiview = View.AlphaGUITextureToolView( self.alphafunc ) viewmap = "" try: viewmap = WorldEditor.getOptionString( "tools/alphaTool" ) except: pass if viewmap == "": viewmap = "resources/maps/gizmo/disc.bmp" self.alphatool = WorldEditor.Tool( Locator.TerrainToolLocator(), View.TerrainTextureToolView( viewmap ), self.alphafunc ) vismap = "" try: vismap = WorldEditor.getOptionString( "tools/chunkVisualisation" ) except: pass if vismap == "": vismap = "resources/maps/gizmo/square.bmp" self.chunkvis = View.TerrainChunkTextureToolView( vismap ) scv = WorldEditor.getOptionString( "tools/showChunkVisualisation" ) if scv == "true": self.alphatool.addView( self.chunkvis, "chunkVisualisation" ) self.alphatool.addView( self.guiview, "alphaGUI" ) self.guiview.visible = 1 self.alphatool.size = WorldEditor.getOptionFloat( "tools/alphaToolSize" ) self.alphatool.strength = WorldEditor.getOptionFloat( "tools/alphaToolStrength" ) self.heightfunc = Functor.TerrainHeightFilterFunctor() # Create the ecotype tool self.ecotool = WorldEditor.Tool( Locator.TerrainChunkLocator(), View.TerrainChunkTextureToolView( vismap ), Functor.HeightPoleEcotypeFunctor() ); self.ecotool.size = 10000 # Create the object manipulation tool self.objtool = WorldEditor.Tool() self.objtool.functor = Functor.ScriptedFunctor( ChunkItemFunctor( self.objtool, self.objInfo ) ) # Make the closed captions commentary viewer self.cc = GUI.ClosedCaptions( WorldEditor.getOptionInt( "consoles/numMessageLines" ) ) self.onResume( 0 )
def onKeyEvent( self, isDown, key, modifiers ): handled = WorldEditor.camera().handleKeyEvent( isDown, key, modifiers ) if not handled and isDown: handled = self.ownKeyEvent( key, modifiers ) if not handled: handled = WorldEditor.tool().handleKeyEvent( isDown, key, modifiers ) return handled
def _onInput(self, position, targetPos): localPos = targetPos - position localPos.normalise() yawOnTarget = math.atan2(localPos.x, localPos.z) pitchOnTarget = -math.asin(clamp(-1.0, localPos.y, 1.0)) if self.prevYaw: alternativeYaw = yawOnTarget - math.pi if yawOnTarget > 0 else yawOnTarget + math.pi if math.fabs(alternativeYaw - self.prevYaw) < math.fabs(yawOnTarget - self.prevYaw): yawOnTarget = alternativeYaw pitchOnTarget = math.pi - pitchOnTarget if pitchOnTarget > 0 else -math.pi - pitchOnTarget self.prevYaw = yawOnTarget self._matrix.setRotateYPR((yawOnTarget, pitchOnTarget, 0)) self._matrix.translation = position if self.prevMatrixYaw: if math.fabs(self.prevMatrixYaw - self._matrix.yaw) > 0.1: self.skipFrames = SetCameraPosAndTarget.FRAMES_TO_SKIP elif math.fabs(self.prevMatrixPitch - self._matrix.pitch) > 0.1: self.skipFrames = SetCameraPosAndTarget.FRAMES_TO_SKIP elif math.fabs(self.prevMatrixRoll - self._matrix.roll) > 0.1: self.skipFrames = SetCameraPosAndTarget.FRAMES_TO_SKIP else: self.prevMatrixYaw = self._matrix.yaw self.prevMatrixPitch = self._matrix.pitch self.prevMatrixRoll = self._matrix.roll if self.skipFrames > 0: self.skipFrames = self.skipFrames - 1 self._parent.translation = self._matrix.translation else: self._parent.set(self._matrix) if math.fabs( math.fabs(self.prevMatrixYaw) - math.fabs(self._matrix.yaw)) < 0.05 and math.fabs( math.fabs(self.prevMatrixPitch) - math.fabs(self._matrix.pitch)) < 0.05: self.prevMatrixYaw = self._matrix.yaw self.prevMatrixPitch = self._matrix.pitch self.prevMatrixRoll = self._matrix.roll if IS_CLIENT: if g_hangarSpace is not None: clientHangarSpace = g_hangarSpace.space if clientHangarSpace: strategy = clientHangarSpace.hangarCamera.getStateStrategy( ) if strategy and isinstance( strategy, BigWorld.CameraStrategySuperFree): strategy.parentProvider = self._parent BigWorld.camera().parentMatrix = self._parent clientHangarSpace.hangarCamera.setDirectAngle( yawOnTarget, pitchOnTarget) else: import WorldEditor self._inverted.set(self._parent) self._inverted.invert() WorldEditor.camera(0).view = self._inverted return 'out'
def doSaveCameraPosition(item): dir = WorldEditor.getOptionString("space/mru0") dirDS = ResMgr.openSection(dir) if not dirDS: WorldEditor.addCommentaryMsg("Unable to open local directory " + dir) return ds = dirDS["space.localsettings"] if ds == None: ds = dirDS.createSection("space.localsettings") if ds == None: WorldEditor.addCommentaryMsg("Unable to create space.localsettings") return m = WorldEditor.camera(0).view m.invert() ds.writeVector3("startPosition", m.translation) ds.writeVector3("startDirection", (m.roll, m.pitch, m.yaw)) ds.save() WorldEditor.addCommentaryMsg("Camera position saved")
def actSaveCameraPositionExecute(): dir = WorldEditor.getOptionString( "space/mru0" ) dirDS = ResMgr.openSection( dir ) if not dirDS: WorldEditor.addCommentaryMsg( "Unable to open local directory " + dir ) return ds = dirDS["space.localsettings"] if ds == None: ds = dirDS.createSection( "space.localsettings" ) if ds == None: WorldEditor.addCommentaryMsg( "Unable to create space.localsettings" ) return m = WorldEditor.camera(0).view m.invert() ds.writeVector3( "startPosition", m.translation ) ds.writeVector3( "startDirection", (m.roll, m.pitch, m.yaw) ) ds.save() WorldEditor.addCommentaryMsg( "Camera position saved" )
def updateCamera( value ): c = WorldEditor.camera() c.speed = WorldEditor.getOptionFloat( "camera/speed/" + value ) c.turboSpeed = WorldEditor.getOptionFloat( "camera/speed/" + value + "/turbo" )
def updateCamera(): value = WorldEditor.getOptionString("camera/speed") c = WorldEditor.camera() c.speed = WorldEditor.getOptionFloat("camera/speed/" + value, 60) c.turboSpeed = WorldEditor.getOptionFloat( "camera/speed/" + value + "/turbo", 120)
def updateState( self, dTime ): """This function forces an update to be called in World Editor. Usually called everyframe, however it still recieves a dTime value which informs the update function how much time has passed since the last update call.""" # detect a change of space, and act accordingly if self.currentSpace != WorldEditor.getOptionString( "space/mru0" ): self.currentSpace = WorldEditor.getOptionString( "space/mru0" ) # make sure the chunk viz resolution is set correctly self.enterChunkVizMode() GUI.update( dTime ) self.cc.update( dTime ) WorldEditor.camera().update( dTime ) if ( WorldEditor.tool() != None and not WorldEditor.tool().applying ): self.objInfo.overGizmo = WorldEditor.gizmoUpdate( WorldEditor.worldRay() ) # update the WorldEditor WorldEditor.update( dTime ) # update tool views base = dTime / 5 self.alphaToolTextureView.rotation += base * (1 + (self.alphaTool.strength / 650)) self.heightView.rotation += base * (1 + (self.heightTool.strength / 650)) self.filterToolTextureView.rotation += base if self.nextTimeDoSelUpdate == 2: self.itemTool.functor.script.restoreOldSelection() self.nextTimeDoSelUpdate = 0 elif self.nextTimeDoSelUpdate == 1: self.itemTool.functor.script.clearAndSaveSelection() self.nextTimeDoSelUpdate = 2 if WorldEditor.isInPlayerPreviewMode() and not self.avatarMode: WorldEditor.addCommentaryMsg( "entered avatar walkthrough mode." ) self.avatarMode = 1 if self.avatarMode and not WorldEditor.isInPlayerPreviewMode(): self.qDown = 0 self.eDown = 0 self.avatarMode = 0 if self.avatarMode: value = WorldEditor.getOptionString( "camera/speed" ) speed = 1 if value == "Medium": speed = 2 if value == "Fast": speed = 3 if value == "SuperFast": speed = 4 if self.qDown and WorldEditor.getOptionInt( "graphics/cameraHeight" ) - speed <= 2: WorldEditor.setOptionInt( "graphics/cameraHeight", 2 ) if self.qDown and WorldEditor.getOptionInt( "graphics/cameraHeight" ) > 2: WorldEditor.setOptionInt( "graphics/cameraHeight", WorldEditor.getOptionInt( "graphics/cameraHeight" ) - speed ) if self.eDown: WorldEditor.setOptionInt( "graphics/cameraHeight", WorldEditor.getOptionInt( "graphics/cameraHeight" ) + speed ) WorldEditor.snapCameraToTerrain() if WorldEditor.tool() == bd.alphaTool: bd.alphaTool.size = WorldEditor.getOptionFloat ( "terrain/texture/size" ) bd.alphaTool.strength = WorldEditor.getOptionFloat ( "terrain/texture/strength" ) bd.alphaTool.functor.displayOverlay = WorldEditor.getOptionInt ( "terrain/texture/maskoverlay" ) WorldEditor.setPaintLayer(bd.alphaTool.functor.lastPaintedLayer) WorldEditor.setPaintPos(bd.alphaTool.functor.lastPaintedPos) if bd.alphaTool.functor.hadEscapeKey != 0: WorldEditor.setTerrainPaintEscKey(bd.alphaTool.functor.hadEscapeKey) bd.alphaTool.functor.hadEscapeKey = 0 bd.heightTool.size = WorldEditor.getOptionFloat ( "terrain/height/size" ) bd.heightTool.strength = WorldEditor.getOptionFloat ( "terrain/height/strength" ) bd.setHeightFunctor.height = WorldEditor.getOptionFloat ( "terrain/height/height" ) bd.setHeightFunctor.relative = WorldEditor.getOptionInt ( "terrain/height/relative" ) bd.heightFunctor.falloff = WorldEditor.getOptionInt ( "terrain/height/brushFalloff" ) bd.filterTool.size = WorldEditor.getOptionFloat ( "terrain/filter/size" ) bd.filterTool.functor.index = WorldEditor.getOptionInt ( "terrain/filter/index" ) bd.holeTool.size = WorldEditor.getOptionFloat ( "terrain/cutRepair/size" ) bd.holeTool.functor.fillNotCut = WorldEditor.getOptionInt ( "terrain/cutRepair/brushMode" ) if self.needsChunkVizUpdate: self.enterChunkVizMode() return 1
def onStart( self ): # create chunk viz self.chunkViz = View.TerrainChunkTextureToolView( "resources/maps/gizmo/square.dds" ) self.chunkViz.numPerChunk = 1 # create vertex viz self.vertexViz = View.TerrainChunkTextureToolView( "resources/maps/gizmo/vertices.dds" ) self.vertexViz.numPerChunk = 25 # create terrain mesh viz self.meshViz = View.TerrainChunkTextureToolView( "resources/maps/gizmo/quads.dds" ) self.meshViz.numPerChunk = 25 # create alpha tool self.alphaTool = WorldEditor.Tool() self.alphaTool.functor = Functor.TerrainTextureFunctor() self.alphaTool.locator = Locator.TerrainToolLocator() self.alphaToolTextureView = View.TerrainTextureToolView( "resources/maps/gizmo/alphatool.tga" ) self.alphaTool.addView( self.alphaToolTextureView, "stdView" ) self.alphaTool.size = 30 self.alphaTool.strength = 1000 # create height filter tool self.heightFunctor = Functor.TerrainHeightFilterFunctor() self.heightFunctor.index = 0 # this index must match the filters.xml file self.heightFunctor.strengthMod = 1 self.heightFunctor.framerateMod = 1 self.heightFunctor.constant = 1.0 self.heightFunctor.falloff = 2 self.setHeightFunctor = Functor.TerrainSetHeightFunctor() self.setHeightFunctor.height = 0 self.setHeightFunctor.relative = 0 self.heightView = View.TerrainTextureToolView( "resources/maps/gizmo/heighttool.tga" ) self.setHeightView = View.TerrainTextureToolView( "resources/maps/gizmo/squaretool.dds" ) self.heightTool = WorldEditor.Tool() self.heightTool.locator = Locator.TerrainToolLocator() self.heightTool.functor = Functor.TeeFunctor( self.heightFunctor, self.setHeightFunctor, KEY_LCONTROL ) self.heightToolTextureView = View.TeeView( self.heightView, self.setHeightView, KEY_LCONTROL ) self.heightTool.addView( self.heightToolTextureView, "stdView" ) self.heightTool.size = 30 # create general filter tool self.filterTool = WorldEditor.Tool() self.filterTool.locator = Locator.TerrainToolLocator() self.filterTool.functor = Functor.TerrainHeightFilterFunctor() self.filterTool.functor.strengthMod = 1 self.filterTool.functor.constant = 0.0 self.filterToolTextureView = View.TerrainTextureToolView( "resources/maps/gizmo/filtertool.tga" ) self.filterTool.addView( self.filterToolTextureView, "stdView" ) self.filterTool.size = 30 # create a hole cutter self.holeTool = WorldEditor.Tool() self.holeTool.locator = Locator.TerrainHoleToolLocator() view = View.TerrainTextureToolView( "resources/maps/gizmo/squaretool.dds" ) view.showHoles = True self.holeTool.addView( view, "stdView" ) self.holeTool.functor = Functor.TerrainHoleFunctor() self.holeTool.size = 30 # create the item tool self.itemTool = WorldEditor.Tool() self.itemToolXZLocator = Locator.ItemToolLocator() self.itemTool.locator = Locator.TerrainToolLocator() self.itemToolTextureView = View.TerrainTextureToolView( "resources/maps/gizmo/cross2.dds" ) self.itemToolModelView = View.ModelToolView( "resources/models/pointer.model" ) self.itemToolPlaneView = View.ModelToolView( "resources/models/freepointer.model" ) self.itemTool.addView( self.itemToolTextureView, "stdView" ) # This changes our locator to a ChunkItemLocator self.itemTool.functor = Functor.ScriptedFunctor( ChunkItemFunctor( self.itemTool, self.objInfo ) ) # Setup the correct subLocator for the ChunkItemLocator self.itemTool.locator.subLocator = self.itemToolXZLocator self.itemTool.size = 1 # Make the closed captions commentary viewer self.cc = GUI.ClosedCaptions( WorldEditor.getOptionInt( "consoles/numMessageLines", 5 ) ) self.cc.addAsView() self.cc.visible = 1 if ( WorldEditor.getOptionInt( "tools/showChunkVisualisation" ) == 1 ): WorldEditor.setOptionInt( "render/chunk/vizMode", 1) self.enterChunkVizMode() self.enterMode( self.modeName, 1 ) # initialise the mouse move camera # load up the start position from space.localsettings startPos = (0,1.85,0) startDir = (0,0,0) dir = WorldEditor.getOptionString( "space/mru0" ) dirDS = ResMgr.openSection( dir ) ds = dirDS["space.localsettings"] if ds != None: startPos = ds.readVector3( "startPosition", startPos ) startDir = ds.readVector3( "startDirection", startDir ) m = WorldEditor.camera(0).view m.setIdentity() m.setRotateYPR( (startDir[2], startDir[1], startDir[0]) ) m.translation = startPos m.invert() WorldEditor.camera(0).view = m # select the camera as specified in the options WorldEditor.changeToCamera( WorldEditor.getOptionInt( "camera/ortho" ) ) # read the initial item snap mode self.updateItemSnaps();
def onMouseEvent( self, mx, my, mz ): handled = 0 if mx or my: self.mouseMoved = 1 legacyMouse = WorldEditor.getOptionInt( "input/legacyMouseWheel" ) itemsRotated = 0 cameraSpeedChanged = False if legacyMouse != 0: # if using legacy mouse if WorldEditor.isKeyDown( KEY_MOUSE1 ): # Change camera speed with right click self.handleWheelCameraSpeed( mz ) cameraSpeedChanged = True elif WorldEditor.tool(): # handle the tool handled = WorldEditor.tool().handleMouseEvent( mx, my, mz ) itemsRotated = self.itemTool.functor.script.selection.size else: # if using new mouse if WorldEditor.tool() and mz == 0: # handle the tool handled = WorldEditor.tool().handleMouseEvent( mx, my, mz ) elif WorldEditor.isKeyDown( KEY_SPACE ): # Change camera speed with space self.handleWheelCameraSpeed( mz ) cameraSpeedChanged = True elif ( WorldEditor.isKeyDown( KEY_LSHIFT ) or WorldEditor.isKeyDown( KEY_RSHIFT ) ) and WorldEditor.tool(): # handle the tool with shift handled = WorldEditor.tool().handleMouseEvent( mx, my, mz ) itemsRotated = self.itemTool.functor.script.selection.size elif mz != 0 and \ ( WorldEditor.isKeyDown( KEY_LCONTROL ) or WorldEditor.isKeyDown( KEY_RCONTROL ) ) and \ self.itemTool.functor.script.selection.size > 0: WorldEditor.rotateSnap( self.itemTool.functor.script.selection, mz, self.itemTool.functor.script.mouseRevealer ) itemsRotated = self.itemTool.functor.script.selection.size if not handled: handled = WorldEditor.camera().handleMouseEvent( mx, my, mz ) if not handled and ( mz != 0 ) and not itemsRotated and not cameraSpeedChanged: # zoom using scroll wheel handled = 1 view = WorldEditor.camera().view view.invert() mult = mz / 1200.0 if WorldEditor.isCapsLockOn(): mult = mult * WorldEditor.camera().turboSpeed else: mult = mult * WorldEditor.camera().speed forward = view.applyToAxis( 2 ) view.translation = ( view.translation[0] + forward[0] * mult, view.translation[1] + forward[1] * mult, view.translation[2] + forward[2] * mult ) view.invert() WorldEditor.camera().view = view return handled
def updateCamera(): value = WorldEditor.getOptionString( "camera/speed" ) c = WorldEditor.camera() c.speed = WorldEditor.getOptionFloat( "camera/speed/" + value, 60 ) c.turboSpeed = WorldEditor.getOptionFloat( "camera/speed/" + value + "/turbo", 120 )
def render( self, dTime ): WorldEditor.camera().render( dTime ) WorldEditor.render( dTime ) GUI.draw() return 1