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

Textures with clear color but without RAM image are stripped when loading from BAM #844

Closed
el-dee opened this issue Jan 13, 2020 · 5 comments
Closed
Assignees
Labels
bug
Milestone

Comments

@el-dee
Copy link
Contributor

@el-dee el-dee commented Jan 13, 2020

A texture created using set_clear_color() has no ram image associated with it, but should still be applied on nodes as it contains a uniform color and so is not empty.

See Moguri/panda3d-gltf#47 : a fallback texture, normal-fallback, is applied on the node. When printing out the Attribs it is correctly displayed, but when listing the TextureStages applied on the node it is not present.

@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Jan 13, 2020

Could you create a sample to demonstrate this?

@el-dee

This comment has been minimized.

Copy link
Contributor Author

@el-dee el-dee commented Jan 14, 2020

With a trivial example, using CardMaker and directly applying the texture or the TexAttrib, there is no problem, so I will try and replicate how panda3d-gltf builds the model and applies the material and textures.

@el-dee

This comment has been minimized.

Copy link
Contributor Author

@el-dee el-dee commented Jan 14, 2020

Ok, I struggled to find the root cause, as it was not at all where I thought is was. Actually the problem is that the bam exporter (or loader) strips the textures without ram image. Without going through a bam file, there is no problem at all !

from panda3d.core import *

from direct.showbase.ShowBase import ShowBase

import tempfile

base = ShowBase()

texture = Texture()
texture = Texture('texture')
texture.setup_2d_texture(1, 1, Texture.T_unsigned_byte, Texture.F_rgb)
texture.set_clear_color(LColor(1, 0, 0, 1))

#texture.make_ram_image()

cm = CardMaker('card')
nproot = NodePath(cm.generate())
nproot.set_texture(texture)

print(nproot.findAllTextureStages())

with tempfile.NamedTemporaryFile(suffix='.bam') as bamfile:
    bamfilepath = Filename.from_os_specific(bamfile.name)
    bamfilepath.make_true_case()
    nproot.write_bam_file(bamfilepath)

    cube = loader.load_model(bamfilepath)

cube.reparent_to(render)
base.cam.set_pos(0, -6, 0)
base.cam.look_at(cube)

print(cube.findAllTextureStages())

base.run()
@rdb rdb added the bug label Jan 19, 2020
@rdb rdb added this to the 1.10.6 milestone Jan 19, 2020
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Mar 18, 2020

There are two problems here:
(1) Clear colors are not written to .bam files
(2) Textures without filenames are not loaded, as indicated by the info message:

:gobj: Cannot create texture 'texture' with no filename.

I think the short-term solution has to be that a RAM image is created for images with a clear color, until we can introduce a new .bam version in 1.11. This means that the loaded texture no longer has a clear color set, but instead has a raw image containing the clear color.

@rdb rdb changed the title Textures created using set_clear_color() are not applied on nodes Textures with clear color but without RAM image are stripped when loading from BAM Mar 18, 2020
rdb added a commit that referenced this issue Mar 18, 2020
This fix requires setting "bam-version 6 45" in Config.prc.

Part of the fix for #844
rdb added a commit that referenced this issue Mar 18, 2020
rdb added a commit that referenced this issue Mar 18, 2020
This makes it possible to write textures with clear colors to .bam files even when the default bam version of 6.44 is selected.  The clear color is converted automatically to a filled RAM image.

Third part of the fix for #844
@rdb rdb self-assigned this Mar 18, 2020
@rdb

This comment has been minimized.

Copy link
Member

@rdb rdb commented Mar 19, 2020

This is fixed. The textures are no longer stripped, and a RAM image is automatically generated by default. I've also added support for just storing the clear colors in the .bam file, instead of generating a RAM image, but due to compatibility considerations, you need to explicitly set bam-version 6 45 in Config.prc (noting that this makes your .bam files incompatible with Panda3D 1.10.5 and below).

@rdb rdb closed this Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.