Moguri / blend2bam

A CLI tool to convert Blender blend files to Panda3D BAM files
MIT License
68 stars 18 forks source link

Loading blend files with lights in second runs moves them in-game. #44

Closed Clockwork-Muse closed 3 years ago

Clockwork-Muse commented 3 years ago

Sorta.

Taking a blend file and loading it via loader.loadModel("reference/to/the/file.blend"), the second time the program is run the light is ...missing. Or something. It's no longer having the same effect on the render result, but the listed position from printing the tree hasn't changed.

This only seems to have an effect on "live" .blend files - manually packing the .bam file for distribution works fine. Saving the file resets the issue. So whatever is going is almost certainly related to the conversion cache, but it's not clear why.

First run: image

ModelRoot Scene S:(LightAttrib)
  PandaNode Cube
    GeomNode Cube (1 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))
  PandaNode Light T:m(pos 4.07625 1.00545 5.90386 hpr 104.532 37.1946 3.97274)
    PointLight Light ( PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens ):
      color 1000 1000 1000 1000
      attenuation 1 0 1
  PandaNode Camera T:m(pos 7.35889 -6.92579 4.95831 hpr 46.6919 63.5593 3.05786e-06)
    Camera Camera ( PerspectiveLens )
      PerspectiveLens fov = 40.7026 22.8952

Second run: image

ModelRoot Scene S:(LightAttrib)
  PandaNode Cube
    GeomNode Cube (1 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))
  PandaNode Light T:m(pos 4.07625 1.00545 5.90386 hpr 104.532 37.1946 3.97274)
    PointLight Light ( PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens PerspectiveLens ):
      color 1000 1000 1000 1000
      attenuation 1 0 1
  PandaNode Camera T:m(pos 7.35889 -6.92579 4.95831 hpr 46.6919 63.5593 3.05786e-06)
    Camera Camera ( PerspectiveLens )
      PerspectiveLens fov = 40.7026 22.8952

Changing the light type from point to directional (Sun) makes it imply that the light is rotated around somewhere: image

ModelRoot Scene S:(LightAttrib)
  PandaNode Cube
    GeomNode Cube (1 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))
  PandaNode Light T:m(pos 4.07625 1.00545 5.90386 hpr 104.532 37.1946 3.97274)
    DirectionalLight Light ( OrthographicLens ):
      color 1000 1000 1000 1000
      direction 0 1 0
  PandaNode Camera T:m(pos 7.35889 -6.92579 4.95831 hpr 46.6919 63.5593 3.05786e-06)
    Camera Camera ( PerspectiveLens )
      PerspectiveLens fov = 40.7026 22.8952

image

ModelRoot Scene S:(LightAttrib)
  PandaNode Cube
    GeomNode Cube (1 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))
  PandaNode Light T:m(pos 4.07625 1.00545 5.90386 hpr 104.532 37.1946 3.97274)
    DirectionalLight Light ( OrthographicLens ):
      color 1000 1000 1000 1000
      direction 0 1 0
  PandaNode Camera T:m(pos 7.35889 -6.92579 4.95831 hpr 46.6919 63.5593 3.05786e-06)
    Camera Camera ( PerspectiveLens )
      PerspectiveLens fov = 40.7026 22.8952

Trivial program file:

"""
Quick test module
"""
from panda3d.core import loadPrcFileData
from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):
    """
    Quick test class
    """

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

        # Load the environment model.
        self.scene = self.loader.loadModel("untitled.blend")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        self.scene.setPos(0, 0, 0)
        # Modify the default camera
        self.disableMouse()
        #self.useDrive()
        self.camera.setPos(7.3589, -6.9258, 4.9583)
        self.camera.lookAt(0, 0, 0)

        self.scene.ls()

def generate_synth():
    """
    Quick test method
    """

    loadPrcFileData("",
    """
        textures-power-2 none
        audio-library-name null # Prevent ALSA errors
        show-frame-rate-meter 0
        sync-video 0
    """ )

    base = MyApp()
    base.run()

generate_synth()
rdb commented 3 years ago

If you disable the model cache, by setting model-cache-dir (without arguments) in Config.prc, does the problem go away?

Clockwork-Muse commented 3 years ago

Yes

Clockwork-Muse commented 3 years ago

I suppose I should include the following:

Blender: 2.90/2.91 Panda: 1.10.7 blend2bam 0.17

I'm running this inside a vscode .devcontainer, but that shouldn't be making a difference.

rdb commented 3 years ago

It may be an issue with Panda's model cache then, could you add a self.scene.writeBamFile('scene.bam') call and run it after loading the file for the first time (or with model cache disabled)?

Then, try loading the resulting bam file and see if the problem is reproduced. If so, please share the bam file.

Clockwork-Muse commented 3 years ago

Issue is present in saved bam file, regardless of whether the model cache is disabled.

There's no difference in the information printed by self.scene.ls() scene.bam.zip

rdb commented 3 years ago

Thanks, and can you share the .blend file as well for comparison?

Clockwork-Muse commented 3 years ago

scene.blend.zip (Although it should be the default blend file)

rdb commented 3 years ago

I think this is a bug in Panda3D, and I will look into fixing it. You can use this as a workaround:

scene.clearLight()

for light in scene.findAllMatches("**/+Light"):
    scene.setLight(light)
rdb commented 3 years ago

I don't think this issue can be fixed in Panda3D 1.10.8 (but will need to be in 1.11), but a workaround can be implemented in blend2bam, see #45.

Clockwork-Muse commented 3 years ago

Thanks!