def apply(self, nodePath):
        texture = self.get_texture()

        if not texture:
            return

        #if 'palette' in texture.name and not getattr(texture, 'edited', False):
        #    texture.name = texture.name.replace('palette', 'palette_converted')

        if texture.alpha_name:
            #if 'palette' in texture.alpha_name and not getattr(texture, 'edited', False):
            #    texture.alpha_name = texture.alpha_name.replace('palette', 'palette_converted')

            tex = TexturePool.load_texture(texture.name, texture.alpha_name)
        else:
            tex = TexturePool.load_texture(texture.name)

        if not tex:
            print('Texture missing!', texture.name, texture.alpha_name)
            return

        #texture.edited = True
        tex.set_wrap_u(texture.wrap_u)
        tex.set_wrap_v(texture.wrap_v)
        tex.set_minfilter(texture.minfilter)
        tex.set_magfilter(texture.magfilter)
        tex.set_anisotropic_degree(texture.anisotropic_degree)
        nodePath.setTexture(tex, 0)
Beispiel #2
0
 def __init__(self, verbose_name, source_path):
     self.name = verbose_name
     self.path = source_path
     self.tex = TexturePool.load_texture(source_path)
     self.w = self.tex.get_x_size()
     self.h = self.tex.get_y_size()
     self.area = self.w * self.h
     self.assigned_pos = None
Beispiel #3
0
def loadTerrain(name, widthScale = 0.5, heightScale = 10.0):
    """load terrain stuff"""

    global app, terrain, terrainRootNetPos
        
    steerMgr = OSSteerManager.get_global_ptr()

    terrain = GeoMipTerrain("terrain")
    heightField = PNMImage(Filename(dataDir + "/heightfield.png"))
    terrain.set_heightfield(heightField)
    # sizing
    environmentWidthX = (heightField.get_x_size() - 1) * widthScale
    environmentWidthY = (heightField.get_y_size() - 1) * widthScale
    environmentWidth = (environmentWidthX + environmentWidthY) / 2.0
    terrain.get_root().set_sx(widthScale)
    terrain.get_root().set_sy(widthScale)
    terrain.get_root().set_sz(heightScale)
    # set other terrain's properties
    blockSize, minimumLevel = (64, 0)
    nearPercent, farPercent = (0.1, 0.7)
    terrainLODmin = min(minimumLevel, terrain.get_max_level())
    flattenMode = GeoMipTerrain.AFM_off
    terrain.set_block_size(blockSize)
    terrain.set_near(nearPercent * environmentWidth)
    terrain.set_far(farPercent * environmentWidth)
    terrain.set_min_level(terrainLODmin)
    terrain.set_auto_flatten(flattenMode)
    # terrain texturing
    textureStage0 = TextureStage("TextureStage0")
    textureImage = TexturePool.load_texture(Filename("terrain.png"))
    terrain.get_root().set_tex_scale(textureStage0, 1.0, 1.0)
    terrain.get_root().set_texture(textureStage0, textureImage, 1)
    # reparent this Terrain node path to the object node path
    terrain.get_root().reparent_to(steerMgr.get_reference_node_path())
    terrain.get_root().set_collide_mask(mask)
    terrain.get_root().set_name(name)
    # brute force generation
    bruteForce = True
    terrain.set_bruteforce(bruteForce)
    # Generate the terrain
    terrain.generate()
    # check if terrain needs update or not
    if not bruteForce:
        # save the net pos of terrain root
        terrainRootNetPos = terrain.get_root().get_net_transform().get_pos()
        # Add a task to keep updating the terrain
        app.taskMgr.add(terrainUpdate, "terrainUpdate", appendTask=True)
    #
    return terrain.get_root()