From: <ror...@us...> - 2007-08-03 00:39:50
|
Revision: 153 http://roreditor.svn.sourceforge.net/roreditor/?rev=153&view=rev Author: rorthomas Date: 2007-08-02 17:39:49 -0700 (Thu, 02 Aug 2007) Log Message: ----------- * improved SimpleTruckRepresentation.py, trucks and loads now have the correct texture! * fixed truck selection bug * removed unused materials Modified Paths: -------------- trunk/lib/ror/SimpleTruckRepresentation.py trunk/lib/rorterraineditor/RoRObjectPreviewOgreWindow.py trunk/media/materials/mysimple.material Modified: trunk/lib/ror/SimpleTruckRepresentation.py =================================================================== --- trunk/lib/ror/SimpleTruckRepresentation.py 2007-08-02 17:33:37 UTC (rev 152) +++ trunk/lib/ror/SimpleTruckRepresentation.py 2007-08-03 00:39:49 UTC (rev 153) @@ -19,6 +19,7 @@ return False try: + myManualObject = sceneManager.createManualObject(str(uuid)+"manual") #myManualObjectMaterial = ogre.MaterialManager.getSingleton().create("manualmaterial"+truckname+str(self.randomcounter),"debugger"); @@ -29,17 +30,86 @@ #myManualObjectMaterial.getTechnique(0).getPass(0).setSelfIllumination(0,0,1) #myManualObjectMaterial.getTechnique(0).getPass(0).setCullingMode(ogre.CULL_ANTICLOCKWISE) - matname = "" - if fn[-4:].lower() == "load": - matname = 'mysimple/loadcolor' - elif fn[-5:].lower() == "truck": - matname = 'mysimple/truckcolor' - + matname = "mysimple/water" + myManualObject.useIndexes = True myManualObject.estimateVertexCount(2000) myManualObject.estimateIndexCount(2000) - myManualObject.begin(matname+"grid", ogre.RenderOperation.OT_LINE_LIST) + minPos = ogre.Vector3(999,999,999) + maxPos = ogre.Vector3(-999,-999,-999) + matname = p.tree['globals'][0]['data'][2] + + if len(p.tree['submeshgroups']) > 0: + nodecounter = 0 + nodes = {} + myManualObject.begin(matname, ogre.RenderOperation.OT_TRIANGLE_LIST) + for nodeobj in p.tree['nodes']: + if nodeobj.has_key('type'): + continue + node = nodeobj['data'] + nodes[nodecounter] = [float(node[1]),float(node[2]),float(node[3])] + nodecounter +=1 + + # get min/max positions + if float(node[0]) < minPos.x: minPos.x = float(node[0]) + if float(node[1]) < minPos.y: minPos.y = float(node[1]) + if float(node[2]) < minPos.z: minPos.z = float(node[2]) + if float(node[0]) > maxPos.x: maxPos.x = float(node[0]) + if float(node[1]) > maxPos.y: maxPos.y = float(node[1]) + if float(node[2]) > maxPos.z: maxPos.z = float(node[2]) + + nodecounter = 0 + #print len(p.tree['submeshgroups']) + counter = 0 + if len(p.tree['submeshgroups']) > 0: + faces = [] + for smobj in p.tree['submeshgroups']: + uv = {} + for data in smobj['texcoords']: + tex = data['data'] + uv[int(tex[0])] = [float(tex[1]), float(tex[2])] + + for cabobj in smobj['cab']: + if cabobj.has_key('type'): + continue + cab = cabobj['data'] + #print "########face" + if cab != []: + try: + myManualObject.position(nodes[int(cab[2])]) + myManualObject.index(nodecounter) + nodecounter += 1 + myManualObject.textureCoord(uv[int(cab[2])][0], uv[int(cab[2])][1]) + + myManualObject.position(nodes[int(cab[1])]) + myManualObject.index(nodecounter) + nodecounter += 1 + + myManualObject.textureCoord(uv[int(cab[1])][0], uv[int(cab[1])][1]) + + myManualObject.position(nodes[int(cab[0])]) + myManualObject.index(nodecounter) + nodecounter += 1 + + myManualObject.textureCoord(uv[int(cab[0])][0], uv[int(cab[0])][1]) + + except: + print "error with cab: " + str(cab) + pass + else: + print "truck has no faces!" + + myManualObject.end() + myManualObject.setCastShadows(False) + mat = ogre.MaterialManager.getSingleton().getByName(matname) + if not mat is None: + mat.setCullingMode(ogre.CullingMode.CULL_NONE) + # create the mesh now + mesh = myManualObject.convertToMesh(str(uuid)+"manual") + + # add the lines! + myManualObject.begin(matname, ogre.RenderOperation.OT_LINE_LIST) for nodeobj in p.tree['nodes']: if nodeobj.has_key('type'): continue @@ -52,51 +122,16 @@ myManualObject.index(int(beam[0])) myManualObject.index(int(beam[1])) myManualObject.end() - myManualObject.begin(matname, ogre.RenderOperation.OT_TRIANGLE_LIST) - for nodeobj in p.tree['nodes']: - if nodeobj.has_key('type'): - continue - node = nodeobj['data'] - myManualObject.position(float(node[1]),float(node[2]),float(node[3])) - - #print len(p.tree['submeshgroups']) - if len(p.tree['submeshgroups']) > 0: - faces = [] - for smobj in p.tree['submeshgroups']: - for cabobj in smobj['cab']: - if cabobj.has_key('type'): - continue - cab = cabobj['data'] - #print "########face" - if cab != []: - try: - myManualObject.triangle(int(cab[0]),int(cab[1]),int(cab[2])) - except: - print "error with cab: " + str(cab) - pass - else: - print "truck has no faces!" - - myManualObject.end() + + entity = sceneManager.createEntity(str(uuid)+"entity", str(uuid)+"manual") + + myManualObjectNode = sceneManager.getRootSceneNode().createChildSceneNode(str(uuid)+"node") + newpos = (minPos+maxPos)/2 + #print "min:", minPos, "max:", maxPos, "newpos:", newpos + myManualObjectNode.setPosition(-newpos) + myManualObjectNode.attachObject(entity) + myManualObjectNode.attachObject(myManualObject) - try: - mesh = myManualObject.convertToMesh(str(uuid)+"manual") - entity = sceneManager.createEntity(str(uuid)+"entity", str(uuid)+"manual") - #trucknode = sceneManager.getRootSceneNode().createChildSceneNode() - myManualObjectNode = sceneManager.getRootSceneNode().createChildSceneNode(str(uuid)+"node") - myManualObjectNode.attachObject(myManualObject) - mesh = myManualObject.convertToMesh(str(uuid)+"manual") - entity = sceneManager.createEntity(str(uuid)+"entity", str(uuid)+"manual") - #trucknode = sceneManager.getRootSceneNode().createChildSceneNode() - myManualObjectNode = sceneManager.getRootSceneNode().createChildSceneNode(str(uuid)+"node") - myManualObjectNode.attachObject(entity) - myManualObjectNode.attachObject(myManualObject) - except: - mesh = None - entity = None - myManualObjectNode = sceneManager.getRootSceneNode().createChildSceneNode(str(uuid)+"node") - myManualObjectNode.attachObject(myManualObject) - return myManualObjectNode, entity, mesh except Exception, err: Modified: trunk/lib/rorterraineditor/RoRObjectPreviewOgreWindow.py =================================================================== --- trunk/lib/rorterraineditor/RoRObjectPreviewOgreWindow.py 2007-08-02 17:33:37 UTC (rev 152) +++ trunk/lib/rorterraineditor/RoRObjectPreviewOgreWindow.py 2007-08-03 00:39:49 UTC (rev 153) @@ -84,7 +84,6 @@ wx.WXK_DOWN:ogre.Vector3(0.0,0.0,d), wx.WXK_PAGEUP:ogre.Vector3(0.0,d,0.0), wx.WXK_PAGEDOWN:ogre.Vector3(0.0,-d,0.0)} - self.Bind(wx.EVT_KEY_DOWN, self.onKeyDown) self.Bind(wx.EVT_MOUSE_EVENTS, self.onMouseEvent) #create objects @@ -97,6 +96,7 @@ self.free() uuid = randomID() self.objnode, self.objentity, manualobject = createTruckMesh(self.sceneManager, filename, uuid) + print "aaa", self.objnode.getPosition() elif extension.lower() in [".odef"]: self.free() uuid = randomID() @@ -139,8 +139,8 @@ self.sceneManager.setShadowTechnique(ogre.ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE); self.sceneManager.setSkyDome(True, 'mysimple/terraineditor/previewwindowsky', 4.0, 8.0) - self.MainLight = self.sceneManager.createLight('MainLight') - self.MainLight.setPosition (ogre.Vector3(20, 80, 130)) + #self.MainLight = self.sceneManager.createLight('MainLight') + #self.MainLight.setPosition (ogre.Vector3(20, 80, 130)) # add some fog self.sceneManager.setFog(ogre.FOG_EXP, ogre.ColourValue.White, 0.0002) @@ -163,13 +163,11 @@ def updateCamera(self): if not self.objnode is None: - if self.objentity is None: - self.radius = 15 - height = 2 - else: - self.radius = self.objentity.getBoundingRadius() * 2 - height = self.objentity.getBoundingBox().getMaximum().z - pos = self.objnode.getPosition() + ogre.Vector3(0, height*0.4, 0) + self.radius = self.objentity.getBoundingRadius() * 2 + height = self.objentity.getBoundingBox().getMaximum().z + #pos = self.objnode.getPosition() + ogre.Vector3(0, height*0.4, 0) + # always look to the center! + pos = self.objnode.getPosition() + ogre.Vector3(0, height*0.4, 0) + (self.objentity.getBoundingBox().getMinimum() + self.objentity.getBoundingBox().getMaximum() ) / 2 dx = math.cos(self.camalpha) * self.radius dy = math.sin(self.camalpha) * self.radius self.camera.setPosition(pos - ogre.Vector3(dx, -5, dy)) @@ -184,14 +182,6 @@ self.updateCamera() wxOgreWindow.OnFrameStarted(self) - def onKeyDown(self,event): - validMove = self.ControlKeyDict.get(event.m_keyCode, False) - if validMove: - pos = self.camera.getPosition() - pos += validMove - self.camera.setPosition(pos) - event.Skip() - def onMouseEvent(self, event): #self.SetFocus() #Gives Keyboard focus to the window Modified: trunk/media/materials/mysimple.material =================================================================== --- trunk/media/materials/mysimple.material 2007-08-02 17:33:37 UTC (rev 152) +++ trunk/media/materials/mysimple.material 2007-08-03 00:39:49 UTC (rev 153) @@ -36,85 +36,6 @@ } } -material mysimple/loadcolor -{ - technique - { - pass - { - lighting on - depth_check on - scene_blend alpha_blend - depth_write off - cull_hardware none - texture_unit - { - colour_op_ex source1 src_manual src_current 0.8 0.8 0 - alpha_op_ex source1 src_manual src_current 0.7 - } - } - } -} - -material mysimple/loadcolorgrid -{ - technique - { - pass - { - lighting on - depth_check on - scene_blend alpha_blend - depth_write off - cull_hardware none - texture_unit - { - colour_op_ex source1 src_manual src_current 1 1 0 - alpha_op_ex source1 src_manual src_current 1 - } - } - } -} - -material mysimple/truckcolor -{ - technique - { - pass - { - lighting on - depth_check on - scene_blend alpha_blend - depth_write off - cull_hardware none - texture_unit - { - colour_op_ex source1 src_manual src_current 0.8 0 0.8 - alpha_op_ex source1 src_manual src_current 0.7 - } - } - } -} -material mysimple/truckcolorgrid -{ - technique - { - pass - { - lighting on - depth_check on - scene_blend alpha_blend - depth_write off - cull_hardware none - texture_unit - { - colour_op_ex source1 src_manual src_current 1 0 1 - alpha_op_ex source1 src_manual src_current 1 - } - } - } -} - material mysimple/terrainselect { technique This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |