0

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()
Sokmixtp
  • 57
  • 5
  • I would recommend to aply the texture in a 3d-Modelling-Programm beforehand, so you dont have to do this in panda3d. This would be possible in blender pretty easy – ductTapeIsMagic Aug 12 '21 at 12:33

1 Answers1

0

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).

rdb
  • 1,488
  • 1
  • 14
  • 24