Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Clockwork-Muse opened this issue Dec 1, 2020 · 10 comments · Fixed by #45
Closed

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

Clockwork-Muse opened this issue Dec 1, 2020 · 10 comments · Fixed by #45

Comments

@Clockwork-Muse
Copy link
Contributor

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
Copy link
Contributor

rdb commented Dec 2, 2020

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

@Clockwork-Muse
Copy link
Contributor Author

Yes

@Clockwork-Muse
Copy link
Contributor Author

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
Copy link
Contributor

rdb commented Dec 3, 2020

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
Copy link
Contributor Author

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
Copy link
Contributor

rdb commented Dec 3, 2020

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

@Clockwork-Muse
Copy link
Contributor Author

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

@rdb
Copy link
Contributor

rdb commented Dec 4, 2020

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
Copy link
Contributor

rdb commented Dec 4, 2020

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
Copy link
Contributor Author

Thanks!

@Moguri Moguri closed this as completed in #45 Dec 4, 2020
Moguri pushed a commit that referenced this issue Dec 4, 2020
rdb added a commit to panda3d/panda3d that referenced this issue Dec 9, 2020
When a LightAttrib is set on the root of a model and the light is contained within that model, creating a copy (like the one Loader makes automatically) causes the LightAttrib to still point to the original light, not to the newly copied light.

This works around it only for the case when the LightAttrib is set on the root, and only for the case of NodePath::copy_to() (it turns out there are edge cases when doing it in PandaNode::copy_subgraph() that would be hard to explain).

See Moguri/blend2bam#44
lachbr pushed a commit to toontownretro/panda that referenced this issue Dec 20, 2020
When a LightAttrib is set on the root of a model and the light is contained within that model, creating a copy (like the one Loader makes automatically) causes the LightAttrib to still point to the original light, not to the newly copied light.

This works around it only for the case when the LightAttrib is set on the root, and only for the case of NodePath::copy_to() (it turns out there are edge cases when doing it in PandaNode::copy_subgraph() that would be hard to explain).

See Moguri/blend2bam#44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants