Exemple #1
0
 def overrideColor(self, event=None):
     color=str(self.colorEntry.get())
     try:
         pixel=astEval(color)  
         self.sample['frameColor']=(pixel[0]/255.0, pixel[1]/255.0, pixel[2]/255.0, 1.0)            
     except:
         print "Unknown format!"
Exemple #2
0
 def overrideColor(self, event=None):
     color=str(self.colorEntry.get())
     try:
         pixel=astEval(color)  
         self.sample['frameColor']=(pixel[0]/255.0, pixel[1]/255.0, pixel[2]/255.0, 1.0)            
     except:
         print "Unknown format!"
Exemple #3
0
def LoadScene(path, file, quad_tree, actors, terrain, grass, flatten=False):
    json_data=None
    with open(path+file) as f:
        json_data=json.load(f)
    return_data=[]
    for object in json_data:
        model=None
        if 'textures' in object:
            i=0
            for tex in object['textures']:
                terrain.setTexture(terrain.findTextureStage('tex{0}'.format(i+1)), loader.loadTexture(path+tex, anisotropicDegree=2), 1)
                #normal texture should have the same name but should be in '/normal/' directory
                normal_tex=tex.replace('/diffuse/','/normal/')
                terrain.setTexture(terrain.findTextureStage('tex{0}n'.format(i+1)), loader.loadTexture(path+normal_tex,anisotropicDegree=2), 1)
                i+=1
            continue
        elif 'grass' in object:
            i=0
            for tex in object['grass']:
                grs_tex= loader.loadTexture(path+tex)
                grs_tex.setWrapU(Texture.WMClamp)
                grs_tex.setWrapV(Texture.WMClamp)
                grass.setTexture(grass.findTextureStage('tex{0}'.format(i+1)), grs_tex, 1)
                i+=1
            continue
        elif 'model' in object:
            model=loadModel(path+object['model'])
        elif 'actor' in object:
            model=loadModel(path+object['actor'],path+object['actor_collision'],path+object['actor_anims'])
            actors.append(model)
        else:
            return_data.append(object)
        if model:
            model.reparentTo(quad_tree[object['parent_index']])
            formatProps=None
            try:
                formatProps=astEval(str(object['props']))
            except:
                pass
            if formatProps:
                model.setPythonTag('formatProps', formatProps)
            model.setPythonTag('props', object['props'])
            model.setHpr(render,object['rotation_h'],object['rotation_p'],object['rotation_r'])
            model.setPos(render,object['position_x'],object['position_y'],object['position_z'])
            model.setScale(object['scale'])

    if flatten:
        for node in quad_tree:
            flat=render.attachNewNode('flatten')
            for child in node.getChildren():
                if child.getPythonTag('props')=='': #objects with SOME properties should be keept alone
                    child.clearPythonTag('model_file')
                    child.clearPythonTag('props')
                    child.clearModelNodes()
                    child.wrtReparentTo(flat)
            flat.flattenStrong()
            flat.wrtReparentTo(node)
    return return_data
Exemple #4
0
 def string2value(self, text, fail_value):
     value=None
     try:
         value=astEval(text)
         if isinstance(value, basestring):
             value=fail_value
     except:
         value=fail_value    
     return value    
Exemple #5
0
 def string2value(self, text, fail_value):
     value=None
     try:
         value=astEval(text)
         if isinstance(value, basestring):
             value=fail_value
     except:
         value=fail_value    
     return value    
Exemple #6
0
def LoadScene(path, file, quad_tree, actors, terrain, grass, flatten=False):
    json_data = None
    with open(path + file) as f:
        json_data = json.load(f)
    return_data = []
    for object in json_data:
        model = None
        if 'textures' in object:
            i = 0
            for tex in object['textures']:
                terrain.setTexture(
                    terrain.findTextureStage('tex{0}'.format(i + 1)),
                    loader.loadTexture(path + tex, anisotropicDegree=2), 1)
                #normal texture should have the same name but should be in '/normal/' directory
                normal_tex = tex.replace('/diffuse/', '/normal/')
                terrain.setTexture(
                    terrain.findTextureStage('tex{0}n'.format(i + 1)),
                    loader.loadTexture(path + normal_tex, anisotropicDegree=2),
                    1)
                i += 1
            continue
        elif 'grass' in object:
            i = 0
            for tex in object['grass']:
                grs_tex = loader.loadTexture(path + tex)
                grs_tex.setWrapU(Texture.WMClamp)
                grs_tex.setWrapV(Texture.WMClamp)
                grass.setTexture(
                    grass.findTextureStage('tex{0}'.format(i + 1)), grs_tex, 1)
                i += 1
            continue
        elif 'model' in object:
            model = loadModel(path + object['model'])
        elif 'actor' in object:
            model = loadModel(path + object['actor'],
                              path + object['actor_collision'],
                              object['actor_anims'])
            actors.append(model)
        else:
            return_data.append(object)
        if model:
            model.reparentTo(quad_tree[object['parent_index']])
            formatProps = None
            try:
                formatProps = astEval(str(object['props']))
            except:
                pass
            if formatProps:
                model.setPythonTag('formatProps', formatProps)
            model.setPythonTag('props', object['props'])
            model.setHpr(render, object['rotation_h'], object['rotation_p'],
                         object['rotation_r'])
            model.setPos(render, object['position_x'], object['position_y'],
                         object['position_z'])
            model.setScale(object['scale'])

    if flatten:
        for node in quad_tree:
            flat = render.attachNewNode('flatten')
            for child in node.getChildren():
                if child.getPythonTag(
                        'props'
                ) == '':  #objects with SOME properties should be keept alone
                    child.clearPythonTag('model_file')
                    child.clearPythonTag('props')
                    child.clearModelNodes()
                    child.wrtReparentTo(flat)
            flat.flattenStrong()
            flat.wrtReparentTo(node)
    return return_data