Sokmixtp
Sokmixtp

Reputation: 57

(Python) Panda3D loads solid color instead of full texture

I am trying to add a simple grass texture on my imported plane. Instead of loading the full texture, it loads a solid color. Any help is appreciated.

Here is the texture:

enter image description here

Here is the result:

enter image description here

Here is my code

from direct.showbase.ShowBase import ShowBase
from direct.task.TaskManagerGlobal import taskMgr
from panda3d.core import WindowProperties, Texture, TextureStage
from panda3d.core import AmbientLight
from panda3d.core import Vec4


class Game(ShowBase):

    player_x = 1
    player_y = 22
    player_speed = 1

    def __init__(self):
        ShowBase.__init__(self)

        properties = WindowProperties()
        properties.setSize(1000, 750)
        self.win.requestProperties(properties)

        ambientLight = AmbientLight("ambient light")
        ambientLight.setColor(Vec4(0.2, 0.2, 0.2, 1))
        self.ambientLightNodePath = self.render.attachNewNode(ambientLight)
        self.render.setLight(self.ambientLightNodePath)

        grass_tex = self.loader.loadTexture("Models/Misc/Untitled.jpg")
        grass_tex.setWrapU(Texture.WM_repeat)
        grass_tex.setWrapV(Texture.WM_repeat)

        self.scene = self.loader.loadModel("Models/Misc/floor.bam")
        self.scene.setTexture(grass_tex, 16)
        self.scene.setTexScale(TextureStage.getDefault(), 8, 4)
        self.scene.reparentTo(self.render)
        self.scene.setScale(0.5, 0.5, 0.5)
        self.scene.setPos(1, 22, 1)
        self.updateTask = taskMgr.add(self.update, "update")

    def update(self, task):
        self.accept('d', self.change_x)
        self.camera.setPos(self.player_x, self.player_y, 1.5)
        return task.cont

    def change_x(self):
        self.player_x += self.player_speed
        self.camera.setPos(self.player_x, self.player_y, 1.5)


game = Game()
game.run()

Upvotes: 0

Views: 529

Answers (1)

rdb
rdb

Reputation: 1617

This could be due to a number of reasons, but I suspect that your plane isn't UV-unwrapped, in other words, doesn't have a set of coordinates defined that map the texture to the model. You would need to fix this in the modelling program or use automatically generated texture coordinates (see the Panda3D manual).

Upvotes: 0

Related Questions