def addStar(self, object, position): node = self.createObjectNode(position, object.id, 'sphere_lod.mesh', 100, False) self.nodes[object.id] = node self.stars.append(node) entity_node = self.sceneManager.getSceneNode("Object%i_EntityNode" % object.id) # Lens flare billboard = self.flareBillboard.createBillboard( position, ogre.ColourValue().White) light = self.sceneManager.createLight("Object%i_Light" % object.id) light.type = ogre.Light.LT_POINT light.position = position light.setAttenuation(500, 1, 0, 0) # Text overlays label = overlay.ObjectOverlay(entity_node, object) label.show(label.name) label.setColour(ogre.ColourValue(0.7, 0.9, 0.7)) self.overlays[object.id] = label icon = overlay.IconOverlay(entity_node, object, "Starmap/Icons/Stars") self.icons[object.id] = icon random.seed(object.id) star_type = random.choice(["Orange", "White", "Green"]) entity = self.sceneManager.getEntity("Object%i" % object.id) entity.setMaterialName("Starmap/Sun/%s" % star_type) return node
def __init__(self, pSceneMgr, pViewport): super(ViewportGrid, self).__init__() self.sceneManager = pSceneMgr self.viewport = pViewport self.enabled = False self.layer = None self.prevCamera = None self.prevOrtho = False self.prevCamPos = None self.prevNear = None self.prevOrtho = None self.prevAspectRatio = None self.bForceUpdate = True self.pGrid = None self.created = False self.pNode = None self.colour1 = og.ColourValue(0.7, 0.7, 0.7) self.colour2 = og.ColourValue(0.7, 0.7, 0.7) self.division = 10 self.perspSize = 100 self.renderScale = True self.renderMiniAxes = True self.sMatName = "ViewportGrid" self.__createGrid() self.setRenderLayer(RL_BEHIND) # Add this as a render target listener self.viewport.getTarget().addListener(self)
def setupScene(): """Create the initial OGRE scene (first items to appear).""" global ogre_scene_manager global ogre_render_window global ogre_root_node global ogre_camera ogre_render_window = ogre_root.getAutoCreatedWindow() ogre_scene_manager = ogre_root.createSceneManager(ogre.ST_GENERIC, "Default SceneManager") ogre_camera = ogre_scene_manager.createCamera("Camera") ogre_root.getAutoCreatedWindow().addViewport(ogre_camera) ogre_camera.setPosition(ogre.Vector3(0, 40, 5)) ogre_camera.lookAt(ogre.Vector3(0, 0, 0)) ogre_camera.nearClipDistance = 5 ogre_scene_manager.setAmbientLight(ogre.ColourValue(0.05, 0.05, 0.05)) ogre_scene_manager.setShadowTechnique(ogre.SHADOWTYPE_STENCIL_ADDITIVE) ogre_scene_manager.setFog(ogre.FOG_EXP, ogre.ColourValue(1, 1, 1), 0.002) directional_light = ogre_scene_manager.createLight('Light-Directional') directional_light.setType(ogre.Light.LT_DIRECTIONAL) directional_light.setDirection(0.1, -1, 0.5) directional_light.setDiffuseColour(0.5, 0.5, 0.5) directional_light.setSpecularColour(0.02, 0, 0) ogre_root_node = ogre_scene_manager.getRootSceneNode()
def fire(self, source, target): """ Takes in two SceneNodes and puts a laser up between them """ self.laser.addChainElement( 0, ogre.BillboardChain.Element(source._getDerivedPosition(), 10, 0.0, ogre.ColourValue(1.0, 1.0, 1.0))) self.laser.addChainElement( 0, ogre.BillboardChain.Element(target._getDerivedPosition(), .1, 1.0, ogre.ColourValue(1.0, 1.0, 1.0))) self.laser.setVisible(True) target.attachObject(self.particles)
def onItemClicked(self, item, column): if column == 1: self.valueBeforeEdit = str(item.text(column)) if item.text(0) == "State": ed = GameObjectStateEditor(item.text(column), self) ed.exec_() item.setText(column, ed.getValue()) self.node.getAttachedObject(0).getUserObject().state = ed.getValue() elif item.text(0) == "Receives Shadows": bedit = BoolEditor(item.text(column), self) bedit.exec_() item.setText(column, bedit.getValue()) self.node.getAttachedObject(0).getUserObject().receivesShadow = str(bedit.getValue()) elif item.text(0) == "Physics Proxy Type": bedit = EntityPhysicsProxyEditor(item.text(column), self) bedit.exec_() item.setText(column, bedit.getValue()) self.node.getAttachedObject(0).getUserObject().physicsproxytype = bedit.getValue() elif item.text(0) == "Visibility": bedit = BoolEditor(item.text(column), self) bedit.exec_() item.setText(column, str(bedit.getValue())) ModuleManager.extractLight(self.node).setVisible(bedit.getValue()) elif item.text(0) == "CastShadows": bedit = BoolEditor(item.text(column), self) bedit.exec_() item.setText(column, str(bedit.getValue())) ModuleManager.extractLight(self.node).setCastShadows(bedit.getValue()) elif item.text(0) == "Diffuse Color": min = 1.0 / 255.0 col = ModuleManager.extractLight(self.node).getDiffuseColour() newColor = QColorDialog.getColor(QColor(col.r * 255, col.g * 255, col.g * 255), self) ModuleManager.extractLight(self.node).setDiffuseColour(og.ColourValue(min * newColor.red(), min * newColor.green(), min * newColor.blue())) self.showProperties(self.so) elif item.text(0) == "Specular Color": min = 1.0 / 255.0 col = ModuleManager.extractLight(self.node).getSpecularColour() newColor = QColorDialog.getColor(QColor(col.r * 255, col.g * 255, col.g * 255), self) ModuleManager.extractLight(self.node).setSpecularColour(og.ColourValue(min * newColor.red(), min * newColor.green(), min * newColor.blue())) self.showProperties(self.so) elif item.text(0) == "Subtract": bedit = BoolEditor(item.text(column), self) bedit.exec_() item.setText(column, str(bedit.getValue())) self.so.entity.getUserObject().subtract = bedit.getValue() else: self.treeWidget.editItem(item, column)
def addPlanet(self, object, position, parent): pos = self.calculateRadialPosition(position, 300, 720, parent.planets, object.index) node = self.createObjectNode(pos, object.id, 'sphere_lod.mesh', 50) self.nodes[object.id] = node self.planets.append(node) entity_node = self.sceneManager.getSceneNode("Object%i_EntityNode" % object.id) colour = None owner = object.Ownership[0][1] if owner != -1: random.seed(owner) r = random.random colour = ogre.ColourValue(r(), r(), r(), 1) icon = overlay.IconOverlay(entity_node, object, "Starmap/Icons/Planets", 15, 15, colour) self.icons[object.id] = icon random.seed(parent.id) for i in range(object.index): random.random() planet_type = random.choice(["Terran", "Ocean", "Arid"]) entity = self.sceneManager.getEntity("Object%i" % object.id) entity.setMaterialName("Starmap/Planet/%s" % planet_type) return node
def on_health_changed(self, player, value): p = player.health / player.max_health width = p * 120 r, g, b = 1 - p, p, 0 color = ogre.ColourValue(r, g, b, .5) self.bar_health.setDimensions(width, 20) self.bar_health.setColour(color)
def _onRootChanged(self, isRoot): """Root changed event """ global prev_background global prev_back_visible BaseModeLogic._onRootChanged(self, isRoot) if isRoot: render_engine.setMode(render_engine.Mode_Perspective) self.prev_cam_pos = render_engine._ogreCameraNode.getPosition() self.prev_cam_dir = render_engine._ogreCameraNode.getOrientation() prev_background = render_engine._ogreViewport.getBackgroundColour() render_engine._ogreViewport.setBackgroundColour( ogre.ColourValue(0, 0, 0)) # space_panel.activate(self._getSheet().getChilds()) prev_back_visible = render_engine.SceneManager.isBackVisible() if prev_back_visible: render_engine.SceneManager.hideBack() else: render_engine.setMode(render_engine.Mode_Isometric) render_engine._ogreCameraNode.setPosition(self.prev_cam_pos) render_engine._ogreCameraNode.setOrientation(self.prev_cam_dir) render_engine._ogreViewport.setBackgroundColour(prev_background) # space_panel.deactivate() space_window.deactivate() if prev_back_visible: render_engine.SceneManager.showBack() self.is_root = isRoot
def _createViewports(self): """Creates the Viewport.""" try: self.viewport = self.renderWindow.addViewport(self.camera.getRealCamera()) except AttributeError: self.viewport = self.renderWindow.addViewport(self.camera) self.viewport.BackgroundColour = ogre.ColourValue(0,0,0)
def setupOgre(self, pluginCfgPath="./Plugins.cfg", ogreCfgPath="./ogre.cfg", logPath="./ogre.log"): if platform.system() == "Windows": pluginCfgPath="./Plugins-windows.cfg" else: pluginCfgPath="./Plugins-linux.cfg" root = og.Root(pluginCfgPath, ogreCfgPath, logPath) self.ogreRoot = root if not self.ogreRoot.restoreConfig() and not self.ogreRoot.showConfigDialog(): sys.exit('Quit from Config Dialog') root.initialise(False) self.pivotRenderQueueListener = PivotRenderQueueListener() self.OgreMainWinSceneMgr = self.ogreRoot.createSceneManager(og.ST_GENERIC, "OgreMainWinSceneMgr") self.OgreMainWinSceneMgr.ambientLight = og.ColourValue(4, 4, 4) self.OgreMainWinSceneMgr.addRenderQueueListener(self.pivotRenderQueueListener) self.moduleName = "" self.myTerrainManager = MyTerrainManager(self.OgreMainWinSceneMgr) self.moduleManager = ModuleManager(self.ogreRoot, self.OgreMainWinSceneMgr) self.moduleManager.myTerrainManager = self.myTerrainManager self.gocManager = self.moduleManager.gocManager self.ogreMainWindow = OgreMainWindow.OgreMainWindow(self.moduleManager, root, self.OgreMainWinSceneMgr, self) self.gridlayout.addWidget(self.ogreMainWindow,0,0,1,1) self.hboxlayout.addLayout(self.gridlayout) self.setCentralWidget(self.centralwidget) self.myTerrainManager.ogreMainWindow = self.ogreMainWindow oglog = og.LogManager.getSingleton().getDefaultLog() oglog.addListener(self.consoleWindow.lockenLog)
def randomizeColor(self): r = random.randrange(1, 255) g = random.randrange(1, 255) b = random.randrange(1, 255) self.currentColorAsVector3 = og.Vector3(r, g, b) var = 1.0 / 255.0 self.currentColor = og.ColourValue(r * var, g * var, b * var)
def drawLine(self, btVectorFrom, btVectorTo, colour): mLines = self.mLines c = ogre.ColourValue(colour.getX(), colour.getY(), colour.getZ()) c.saturate() mLines.position(btVectorFrom.x(), btVectorFrom.y(), btVectorFrom.z()) mLines.colour(c) mLines.position(btVectorTo.x(), btVectorTo.y(), btVectorTo.z()) mLines.colour(c)
def __init__(self, sceneManager): bullet.btIDebugDraw.__init__(self) self.mDebugMode = bullet.btIDebugDraw.DBG_DrawWireframe self.beginLineUpdates = False self.beginTriUpdates = False self.mContactPoints = [] mLines = ogre.ManualObject("Bullet Physics lines") mTriangles = ogre.ManualObject("Bullet Physics triangles") mLines.setDynamic(True) mTriangles.setDynamic(True) self.mSceneManager = sceneManager self.mSceneManager.getRootSceneNode().attachObject(mLines) self.mSceneManager.getRootSceneNode().attachObject(mTriangles) matName = "OgreBulletCollisionsDebugDefault" mtl = ogre.MaterialManager.getSingleton().getDefaultSettings().clone( matName) mtl.setReceiveShadows(False) mtl.setSceneBlending(ogre.SBT_TRANSPARENT_ALPHA) mtl.setDepthBias(0.1, 0) tu = mtl.getTechnique(0).getPass(0).createTextureUnitState() tu.setColourOperationEx(ogre.LBX_SOURCE1, ogre.LBS_DIFFUSE) mtl.getTechnique(0).setLightingEnabled(False) ##mtl.getTechnique(0).setSelfIllumination( ogre.ColourValue().White ) mLines.begin(matName, ogre.RenderOperation.OT_LINE_LIST) mLines.position(ogre.Vector3().ZERO) mLines.colour(ogre.ColourValue().Blue) mLines.position(ogre.Vector3().ZERO) mLines.colour(ogre.ColourValue().Blue) mTriangles.begin(matName, ogre.RenderOperation.OT_TRIANGLE_LIST) mTriangles.position(ogre.Vector3().ZERO) mTriangles.colour(ogre.ColourValue().Blue) mTriangles.position(ogre.Vector3().ZERO) mTriangles.colour(ogre.ColourValue().Blue) mTriangles.position(ogre.Vector3().ZERO) mTriangles.colour(ogre.ColourValue().Blue) self.mLines = mLines self.mTriangles = mTriangles
def updateLightMap(self): return decalCursorWasVisible = False if self.decalCursor.m_bVisible: self.decalCursor.hide() decalCursorWasVisible = True lightmap = og.Image() ET.createTerrainLightmap( self.terrainManager.getTerrainInfo() , lightmap, 128, 128 , og.Vector3(1, -1, 1) , og.ColourValue(1 ,1, 1) , og.ColourValue(0.3, 0.3, 0.3) ) ## get our dynamic texture and update its contents tex = og.TextureManager.getSingleton().getByName("ETLightmap") l = lightmap.getPixelBox(0, 0) tex.getBuffer(0, 0).blitFromMemory(lightmap.getPixelBox(0, 0)) if decalCursorWasVisible: self.decalCursor.show()
def setupScene(self): self.renderWindow = self.root.getAutoCreatedWindow() self.sceneManager = self.root.createSceneManager( ogre.ST_GENERIC, "Default SceneManager") self.camera = self.sceneManager.createCamera("Camera") viewPort = self.root.getAutoCreatedWindow().addViewport(self.camera) self.camera.setPosition(ogre.Vector3(0, 100, -400)) self.camera.lookAt(ogre.Vector3(0, 0, 1)) self.sceneManager.setAmbientLight(ogre.ColourValue(0.7, 0.7, 0.7)) self.sceneManager.setSkyDome(True, 'Examples/CloudySky', 4, 8) self.sceneManager.setFog(ogre.FOG_EXP, ogre.ColourValue(1, 1, 1), 0.0002) self.light = self.sceneManager.createLight('lightMain') self.light.setPosition(ogre.Vector3(20, 80, 50)) self.rn = self.sceneManager.getRootSceneNode() self.entityOgre = self.sceneManager.createEntity( 'Ogre', 'ogrehead.mesh') self.nodeOgre = self.rn.createChildSceneNode('nodeOgre') self.nodeOgre.setPosition(ogre.Vector3(0, 0, 0)) self.nodeOgre.attachObject(self.entityOgre)
def setupUi(self, Form): Form.setObjectName("Form") Form.resize(QSize(QRect(0,0,935,843).size()).expandedTo(Form.minimumSizeHint())) self.gridlayout = QGridLayout(Form) self.gridlayout.setContentsMargins(0, 2, 0, 0) self.gridlayout.setObjectName("gridlayout") # create the vertical splitter ( contains the preferences buttons and the horizontal splitter with the two render windows ) self.splitterV = QSplitter(Form) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding,QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.splitterV.sizePolicy().hasHeightForWidth()) self.splitterV.setSizePolicy(sizePolicy) self.splitterV.setOrientation(Qt.Vertical) self.splitterV.setObjectName("splitter") # create the horizontal splitter wich contains the two ogre render windows and add it to the vertical splitter ################################## self.ogreWidget = OgreWidget.OgreWidget("OgreMainWin", self.ogreRoot, self.OgreMainWinSceneMgr, "MainCam", self.splitterV, 0) self.ogreWidget.setMinimumSize(QSize(250,250)) sizePolicy = QSizePolicy(QSizePolicy.Maximum,QSizePolicy.Maximum) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.ogreWidget.sizePolicy().hasHeightForWidth()) self.ogreWidget.setSizePolicy(sizePolicy) self.ogreWidget.setObjectName("ogreWidget") self.splitterV.addWidget(self.ogreWidget) self.ogreWidget.setBackgroundColor(og.ColourValue(0, 1, 1)) #################################### self.gridlayout.addWidget(self.splitterV,0,0,1,1) # register the eventfilters for the render windows # this is needed to catch mouse enter and mouse leave events for these windows self.ogreWidget.installEventFilter(self) self.ogreWidget.setAcceptDrops(True) self.lastMousePosX = 0 self.lastMousePosY = 0 self.retranslateUi(Form) QMetaObject.connectSlotsByName(Form) self.ogreWidget.setOgreViewportCreatedCallback(self.ogreViewportCreatedCallback)
def __init__(self): og.MaterialManager.Listener.__init__(self) self.currentColor = og.ColourValue(0.0, 0.0, 0.0) self.currentColorAsVector3 = og.Vector3() self.lastEntity = "" self.lastTechnique = None if platform.system() == "Windows": self.lastTechnique = og.MaterialManager.getSingleton().load("PlainColor", og.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).getTechnique(0) else: self.lastTechnique = og.MaterialManager.getSingleton().load("PlainColorGLSL", og.ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME).getTechnique(0) self.colorDict = {}
def setHighlight(self, highlight, colour=ogre.ColourValue().White): material = self.panel.material clone_material_name = "%s_highlight" % self.original_material material_manager = ogre.MaterialManager.getSingleton() if highlight: if not material_manager.resourceExists(clone_material_name): material_clone = material.clone(clone_material_name) texture = material_clone.getTechnique(0).getPass( 0).getTextureUnitState(0) texture.setColourOperationEx(ogre.LBX_MODULATE_X4, ogre.LBS_TEXTURE, ogre.LBS_MANUAL, colour) self.panel.materialName = clone_material_name else: self.panel.materialName = self.original_material material_manager.remove(clone_material_name) self.highlight = highlight
def setupScene(self): '''SETUP SCENEMANAGER''' self.sceneManager = self.root.createSceneManager( ogre.ST_GENERIC, "Default SceneManager") self.sceneManager.setAmbientLight(ogre.ColourValue(1, 1, 1)) '''SETUP ENVIRONMENT''' plane = ogre.Plane((0, 1, 0), 0) meshManager = ogre.MeshManager.getSingleton() meshManager.createPlane('Ground', 'General', plane, 100000, 100000, 20, 20, True, 1, 5, 5, (0, 0, 1)) ent = self.sceneManager.createEntity('GroundEntity', 'Ground') self.sceneManager.getRootSceneNode().createChildSceneNode( ).attachObject(ent) ent.setMaterialName('Ocean2_Cg') ent.castShadows = False self.sceneManager.setSkyBox(True, "Examples/MorningSkyBox", 5000, False)
def _onRootChanged(self, _isRoot): """Root mode changing """ import suit.core.render.engine as render_engine import ogre.renderer.OGRE as ogre if _isRoot: self._old_color_back = render_engine._ogreViewport.getBackgroundColour( ) clr = chem_env.color_back render_engine._ogreViewport.setBackgroundColour( ogre.ColourValue(clr[0], clr[1], clr[2], clr[3])) else: if self._old_color_back is not None: render_engine._ogreViewport.setBackgroundColour( self._old_color_back) BaseModeLogic._onRootChanged(self, _isRoot)
def selectObject(self, object_id, colour_value=ogre.ColourValue().White, scale_factor=3): """Appends a scene node to the current selection and highlights it""" scene_node = self.nodes[object_id] position = scene_node.position scale = 20 print scene_node, position, scale, scene_node.initialScale, scene_node.getChild( 0).initialScale billboard = self.selectionBillboard.createBillboard( position, colour_value) billboard.setDimensions(scale * scale_factor, scale * scale_factor) self.selection[object_id] = billboard if self.icons.has_key(object_id): self.icons[object_id].setHighlight(True)
def __init__(self, plugins_path='../plugins.cfg', resource_path='../resources.cfg'): ogre.Root.__init__(self, plugins_path) self.plugins_path = plugins_path # self.resource_path = resource_path self.sm = None #: scene manager self.s_root = None #: root scene node # self._load_resources(self.resource_path) self._choose_render_engine() self.initialise(False) self.initialisePlugins() self.window = self.createRenderWindow("daggertool", 800, 600, False) self.sm = self.createSceneManager( "TerrainSceneManager") #ogre.ST_GENERIC) self.sm.setShadowTechnique(ogre.SHADOWTYPE_STENCIL_ADDITIVE) self.sm.setAmbientLight((0.4, 0.4, 0.4)) self.light = self.sm.createLight('light1') self.light.setType(ogre.Light.LT_DIRECTIONAL) self.light.setDiffuseColour(1, 1, 1) self.light.setSpecularColour(1, 1, 1) self.light.setCastShadows = True self.camera = self.sm.createCamera("camera") self.camera.setPosition(100, 100, 100) self.camera.lookAt(ogre.Vector3(40, -80, 50)) self.camera.setNearClipDistance(1) self.viewport = self.window.addViewport(self.camera) self.viewport.setBackgroundColour(ogre.ColourValue(0.1, 0.1, 0.1)) self._build_scene() self.createFrameListener()
def drawLine(self, start, end, colour=ogre.ColourValue().White): line_index = len(self.lines) manual_object = self.sceneManager.createManualObject("line%i" % line_index) manual_object.setQueryFlags(self.parent.UNSELECTABLE) scene_node = self.rootNode.createChildSceneNode("line%i_node" % line_index) material = ogre.MaterialManager.getSingleton().create( "line%i_material" % line_index, "default") material.setReceiveShadows(False) material.getTechnique(0).getPass(0).setSelfIllumination(colour) manual_object.begin("line%i_material" % line_index, ogre.RenderOperation.OT_LINE_LIST) manual_object.position(start) manual_object.position(end) manual_object.end() scene_node.attachObject(manual_object) self.lines.append(manual_object) return manual_object
def __init__(self, ogreRoot, parent=None): QDialog.__init__(self, parent) self.ogreRoot = ogreRoot self.setupUi() self.connect(self.materialSearchBox, SIGNAL("textChanged(QString)"), self.updateMaterialList) self.connect(self.listWidget, SIGNAL("itemSelectionChanged ()"), self.setPreviewedMaterial) self.materialList = [] self.ogreMaterialPrevWindow.setBackgroundColor(og.ColourValue(0, 1, 0)) self.node = self.ogreMaterialPrevWindowSceneMgr.getRootSceneNode( ).createChildSceneNode() self.ent = None self.nodeScale = og.Vector3(1, 1, 1) self.lastMousePosX = 0 self.lastMousePosY = 0
def setupUi(self): self.setObjectName("materialPreviewDialog") self.resize( QSize(QRect(0, 0, 272, 744).size()).expandedTo(self.minimumSizeHint())) self.gridlayout = QGridLayout(self) self.gridlayout.setObjectName("materialSelectionLayout") self.gridlayout.setContentsMargins(2, 2, 2, 2) self.materialSearchBox = QLineEdit(self) self.materialSearchBox.setObjectName("materialSearchBox") self.gridlayout.addWidget(self.materialSearchBox, 0, 0, 1, 1) self.splitter = QSplitter(self) self.splitter.setOrientation(Qt.Vertical) self.splitter.setObjectName("splitter") self.listWidget = MaterialListWidget(self.splitter) self.listWidget.setObjectName("listWidget") self.ogreMaterialPrevWindowSceneMgr = self.ogreRoot.createSceneManager( og.ST_GENERIC, "ogreMaterialPrevWindowSceneMgr") self.ogreMaterialPrevWindow = OgreWidget.OgreWidget( "MaterialPrevWin", self.ogreRoot, self.ogreMaterialPrevWindowSceneMgr, "MaterialPrevCam", self.splitter) self.ogreMaterialPrevWindow.setBackgroundColor( og.ColourValue(1.0, 1.0, 1.0, 1.0)) self.ogreMaterialPrevWindow.setOgreViewportCreatedCallback( self.ogreViewportCreatedCallback) self.ogreMaterialPrevWindow.setMinimumSize(QSize(200, 200)) self.ogreMaterialPrevWindow.setObjectName("materialPreviewWindow") self.gridlayout.addWidget(self.splitter, 1, 0, 1, 1) self.retranslateUi()
#sys.path.append('pymodules/ogre.zip') #didn't work for some reason yet - should .pyd s work from zips too? #apparently it should work: http://mail.python.org/pipermail/python-list/2008-March/653795.html #based on the info in http://www.ogre3d.org/addonforums/viewtopic.php?f=3&t=8743&hilit=embed import ogre.renderer.OGRE as ogre root = ogre.Root.getSingleton() #print dir(r) print root.isInitialised() rs = root.getRenderSystem() #rs.setAmbientLight(1, 1, 1) vp = rs._getViewport() #print vp bg = vp.getBackgroundColour() #only affects when not connected, when caelum is not there i figure vp.setBackgroundColour(ogre.ColourValue(0.1, 0.2, 0)) cam = vp.getCamera() #print cam sm = root.getSceneManager("SceneManager") print sm def drawline(): try: mcounter = r.mcounter except: #first execution print "first exec" mcounter = 1 else: mcounter += 1
def __updatePersp(self): #! @todo Calculate the spacing multiplier mult = 1 #! @todo Interpolate alpha self.colour2.a = 0.5 #if(colour2.a > 1.0f) colour2.a = 1.0f # Calculate the horizontal zero-axis color horAxisColor = og.ColourValue().Red # Calculate the vertical zero-axis color vertAxisColor = og.ColourValue().Blue # The number of lines numLines = int(self.perspSize / mult) + 1 # Start creating or updating the grid self.pGrid.estimateVertexCount(4 * numLines) if self.created: self.pGrid.beginUpdate(0) else: self.pGrid.begin(self.sMatName, og.RenderOperation.OT_LINE_LIST) self.created = True # Vertical lines start = mult * int(-self.perspSize / 2 / mult) x = start while x <= (self.perspSize / 2): # Get the right color for this line #multX = (x == 0) ? x : (x < 0) ? int(x / mult - 0.5f) : int(x / mult + 0.5f) if x == 0: multX = x elif x < 0: multX = int(x / mult - 0.5) else: multX = int(x / mult +0.5) #colour = (multX == 0) ? vertAxisColor : (multX % (int) self.division) ? self.colour2 : self.colour1 if multX == 0: colour = vertAxisColor elif multX % int(self.division): colour = self.colour2 else: colour = self.colour1 # Add the line self.pGrid.position(x, 0, -self.perspSize / 2) self.pGrid.colour(colour) self.pGrid.position(x, 0, self.perspSize / 2) self.pGrid.colour(colour) x += mult # Horizontal lines y = start while y <= (self.perspSize / 2): # Get the right color for this line #multY = (y == 0) ? y : (y < 0) ? int(y / mult - 0.5f) : int(y / mult + 0.5f) if y == 0: multY = y elif y < 0: multY = int(y / mult - 0.5) else: multY = int(y / mult +0.5) #colour = (multY == 0) ? horAxisColor : (multY % int(self.division)) ? self.colour2 : self.colour1 if multY == 0: colour = horAxisColor elif multY % int(self.division): colour = self.colour2 else: colour = self.colour1 # Add the line self.pGrid.position(-self.perspSize / 2, 0, y) self.pGrid.colour(colour) self.pGrid.position(self.perspSize / 2, 0, y) self.pGrid.colour(colour) y += mult self.pGrid.end() # Normal orientation, grid in the X-Z plane self.pNode.resetOrientation()
def addFleet(self, object, position, parent, fleet_type=0, query_flag=None): # rotate between 3 ship types meshes = [('scout', 50), ('frigate', 75), ('plowshare', 75)] fleet_type %= len(meshes) mesh = meshes[fleet_type] pos = self.calculateRadialPosition(position, 200, 360, parent.fleets, object.index) node = self.createObjectNode(pos, object.id, '%s.mesh' % mesh[0], mesh[1]) self.nodes[object.id] = node self.fleets.append(object.id) entity_node = self.sceneManager.getSceneNode("Object%i_EntityNode" % object.id) entity_node.yaw(ogre.Radian(1.57)) entity_node.roll(ogre.Radian(1.57)) target_node = node.createChildSceneNode("Object%i_Target" % object.id, pos) # create a copy of the entity material so we can change it's colour owner = object.Ownership[0][1] random.seed(owner) entity = self.sceneManager.getEntity("Object%i" % object.id) if query_flag: entity.setQueryFlags(query_flag) material = entity.getSubEntity(0).getMaterial() material_name = "%s_%i" % (material.getName(), owner) material_manager = ogre.MaterialManager.getSingleton() if not material_manager.resourceExists(material_name): material = material.clone(material_name) self.fleet_colours.append(material) else: material = material_manager.getByName(material_name) entity.setMaterialName(material_name) r = random.random colour = ogre.ColourValue(r(), r(), r(), 1) material.setDiffuse(colour) icon = overlay.IconOverlay(entity_node, object, "Starmap/Icons/Fleets", 20, 20, colour) self.icons[object.id] = icon #if settings.sound_effects: #sm = ogreal.SoundManager.getSingleton() #sound_name = "roar_%d" % object.id #if sm.hasSound(sound_name): #engine_fx = sm.getSound(sound_name) #else: #engine_fx = sm.createSound(sound_name, "roar.ogg", True) #engine_fx.setGain(0.5) #engine_fx.setRolloffFactor(5) #node.attachObject(engine_fx) #self.sounds[object.id] = engine_fx return node
from space_objects import SpaceObject import suit.core.render.engine as render_engine #import space_panel import space_window #def getResourceLocation(): # """Return resource location folder # """ # return core.Kernel.getResourceLocation() + getResourceGroup() # #def getResourceGroup(): # """Return resource group name # """ # return 'space' prev_background = ogre.ColourValue(0, 0, 0) class SpaceViewer(BaseModeLogic): def __init__(self): """constructor """ BaseModeLogic.__init__(self) # view modes # self.appendMode(ois.KC_X, FlyMode(self)) # self._active_mode = self._modes[ois.KC_X] self.appendMode(ois.KC_S, SpaceViewMode(self)) self.switchMode(ois.KC_S) self.is_root = False
def reset(self): self.currentColor = og.ColourValue(0.0, 0.0, 0.0) self.lastEntity = ""