def updatePaintBrush(self): if self.currentPaintBrushName is None: return if self.currentPaintBrush is not None: self.currentPaintBrush = None image = og.Image() image.load(self.currentPaintBrushName, "ET") image.resize(self.paintBrushSize, self.paintBrushSize) self.currentPaintBrush = ET.loadBrushFromImage(image)
def _readFromScreenshotPictureToTexture(self): f = open(self.textureName, 'rb') data = f.read() f.close() stream = ogre.MemoryDataStream("%s" % str(self), len(data), False) stream.setData(data) img = ogre.Image() img.load(stream, ogre.Image.getFileExtFromMagic(stream)) txtrMngr = ogre.TextureManager.getSingleton() screenshot = txtrMngr.loadImage(self.textureName, env.resource_group, img) self.texture.getBuffer().blit(screenshot.getBuffer()) txtrMngr.remove(screenshot) screenshot.unload()
def _setSheet(self, _sheet): BaseModeLogic._setSheet(self, _sheet) _sheet.eventRootChanged = self._onRoot # trying to get data for showing import suit.core.sc_utils as sc_utils session = core.Kernel.session() _addr = _sheet._getScAddr() _fmt = sc_utils.getContentFormat(session, _addr) assert _fmt is not None _cont = session.get_content_const(_addr) assert _cont is not None _cont_data = _cont.convertToCont() _type = session.get_idtf(_fmt).lower() global count count += 1 # import os, pm.pm # self.imageName = os.path.join(env.res_tmp_dir, "%s.jpg" % str(_addr.this)) # pm.pm.saveContentToFile(self.imageName + "%d.jpg" % count, _cont) # file(self.imageName + "_", "wb").write(_cont.get_data(_cont_data.d.size)) data = _cont.get_data(_cont_data.d.size) stream = ogre.MemoryDataStream("%s" % str(self), _cont_data.d.size, False) stream.setData(data) # try: img = ogre.Image() img.load(stream, ogre.Image.getFileExtFromMagic(stream)) self._createTexture(img) self._createMaterial() self._resizeRect() except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout)
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 getFormatIcon(self, _format): """Return icon associated with specified format @param _format: sc-node that designate format @type _format: sc_addr @return: Name of texture that contains icon associated to _format, if there are no any icons, then return None """ import suit.core.sc_utils as sc_utils import sc_core.constants as sc_constants import sc_core.pm as sc import ogre.renderer.OGRE as ogre session = core.Kernel.session() icon = None idtf_set = sc_utils.searchOneShotBinPairAttrToNode( session, _format, keynodes.common.nrel_identification, sc.SC_CONST) if idtf_set is not None: it1 = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, idtf_set, sc.SC_A_CONST, sc.SC_N_CONST), True) while not it1.is_over(): if sc_utils.checkIncToSets(session, it1.value(2), [keynodes.common.group_image], sc.SC_CONST): icon = it1.value(2) break it1.next() if icon is None: return None _fmt = sc_utils.getContentFormat(session, icon) assert _fmt is not None _cont = session.get_content_const(icon) assert _cont is not None _cont_data = _cont.convertToCont() data = _cont.get_data(_cont_data.d.size) stream = ogre.MemoryDataStream("%s" % str(self), _cont_data.d.size, False) stream.setData(data) try: img = ogre.Image() img.load(stream, ogre.Image.getFileExtFromMagic(stream)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) icon_name = "icon_%s" % str(_format) ogre.TextureManager.getSingleton().loadImage( icon_name, "General", img) return icon_name return None
def create(self, cursorSize, arg): if arg is not None: self.name = arg["name"] self.position = og.Vector3(arg["positionX"], arg["positionY"], arg["positionZ"]) self.extends = og.Vector3(arg["extendsX"], arg["extendsY"], arg["extendsZ"]) self.terrainHeight = arg["terrainHeight"] self.terrainSize = arg["terrainSize"] + 1 self.splattingResGroup = "ETSplatting" self.splattingTextureSize = self.terrainSize = arg["terrainSize"] + 1 self.splattingNumTextures = 6 # self.splattingBaseName = arg["splattingBaseName"] # self.splattingResGroup = arg["splattingResGroup"] # self.splattingTextureSize = arg["splattingTextureSize"] # self.splattingNumTextures = arg["splattingNumTextures"] self.terrainManager = ET.TerrainManager(self.sceneManager, self.name) self.terrainManager.setLODErrorMargin(2, self.camera.getViewport().getActualHeight()) self.terrainManager.setUseLODMorphing(True, 0.2, "morphFactor") ## create a fresh, mid-high terrain for editing # Note heightMapValues = og.stdVectorFloat() ## ET.stdVectorFloat() for i in xrange(self.terrainSize): for j in xrange(self.terrainSize): heightMapValues.append(self.terrainHeight) # width, height, heightmapvalues as a float array self.terrainInfo = ET.TerrainInfo (self.terrainSize, self.terrainSize, heightMapValues ) ## save typing self terrainInfo = self.terrainInfo sceneManager = self.sceneManager terrainMgr = self.terrainManager ## set position and size of the terrain half = self.extends / 2 terrainInfo.setExtents(og.AxisAlignedBox(-half.x, -half.y, -half.z, half.x, half.y, half.z)) ## now render it terrainMgr.createTerrain(terrainInfo) ## create the splatting manager # * @param baseName base name for the map textures (will be appended by their number) # * @param group the resource group the textures will be placed in # * @param width width of the textures in pixels # * @param height height of the textures in pixels # * @param channels Number of channels per texture (must be in {1, 2, 3, 4}) self.splatMgr = ET.SplattingManager(self.splattingBaseName, self.splattingResGroup, self.terrainSize, self.terrainSize, 3) ## specify number of splatting textures we need to handle self.splatMgr.setNumTextures(self.splattingNumTextures) ## create a manual lightmap texture lightmapTex = og.TextureManager.getSingleton().createManual( "ETLightmap", self.splattingResGroup, og.TEX_TYPE_2D, self.splattingTextureSize, self.splattingTextureSize, 1, og.PF_BYTE_RGB) lightmap = og.Image() ET.createTerrainLightmap(terrainInfo, lightmap, 128, 128,\ og.Vector3(1, -1, 1),\ og.ColourValue().White,\ og.ColourValue(0.3, 0.3, 0.3,1.0)) lightmapTex.getBuffer(0, 0).blitFromMemory(lightmap.getPixelBox(0, 0)) ## load the terrain material and assign it material = og.MaterialManager.getSingleton().getByName("ETTerrainMaterial") # material = og.MaterialManager.getSingleton().getByName("Lockenwickler_Area") self.terrainManager.setMaterial(material) self.sceneNode = self.sceneManager.getSceneNode(self.name + "/Terrain") self.sceneNode.setPosition(self.position) self.parentSceneNode = self.sceneNode.getParentSceneNode() self.created = True self.decalCursor = TerrainDecalCursor.TerrainDecalCursor(self.sceneManager, material, og.Vector2(cursorSize, cursorSize), "cursorTex.png")