trevorsandy / lpub3d

An LDraw™ editor for LEGO® style digital building instructions.
https://trevorsandy.github.io/lpub3d/
133 stars 19 forks source link

Custom transparent part with PNG not rendered correctly (also if with LDview it works) #373

Closed zero0n3 closed 4 years ago

zero0n3 commented 4 years ago

Subject

The brick 1x6 trans-red with knife fork and cup printed does not exist into studio or ldraw so i managed to create a custom one with a transparent PNG with white shapes. However, when I render the part with LPUB3D, the transparency of the part is rendered poorly. While if I use a solid color everything works correctly.

Opening the customized piece with LDview standalone app, the part does not present any problems, except for the fact that the face of the part where there is the PNG is not rendered transparent, but at least the rest of the piece is correctly displayed. Using the same default settings of LPView of LPUB3D instead there is some problem.

Here you can find my post on Ldraw Forum about that: https://forums.ldraw.org/thread-23013-post-34367.html#pid34367

As you can see, Philippe Hurbain, the admin of ldraw forum, tried to do the same with LPub3D and got the same result.

Environment

Configuration

Using LDview render engine with default settings.

Screenshots

Thi is the real part (3067pb02) 3067

Steps to reproduce

Open ldr and render it The custom part and the PNG are saved in: C:\Users\Public\Documents\ldraw\Unofficial\customparts\parts

Actual behaviour

Wrong render wrong render

This is the sticker used sticker

This is the code of the custom part: 0 Brick 1 x 6 without Bottom Tubes with White Knife & Fork, Cup & Saucer Pattern 0 Name: 3067pb02.dat 0 Author: [PTadmin] 0 !LDRAW_ORG Unofficial_Part 0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt

0 BFC CERTIFY CCW

0 !HISTORY 2017-12-30 [PTadmin] Official Update 2017-01

0 // Brick 1 x 6 without Centre Studs

1 16 0 0 0 1 0 0 0 1 0 0 0 1 s\3067s01.dat

0 !TEXMAP START PLANAR -60 0 -10 60 24 -10 -60 24 -10 3067pb02.png 4 16 -60 24 -10 60 24 -10 60 0 -10 -60 0 -10

0 !TEXMAP FALLBACK 4 16 -60 24 -10 60 24 -10 60 0 -10 -60 0 -10

0 !TEXMAP END

Expected behaviour

This is the part rendered via LDview standalone app. The face with sticker is not transparent but the rest of part is correctly trans-red. sticker 3067_custom.zip

trevorsandy commented 4 years ago

Hi Simone,

This behaviour is sourced from LDView's Snapshot module which functions independently of the MainWindow display; hence, the difference between when a part is "Displayed" in LDView versus when a Snapshot is rendered and exported. I am able to consistently produce the image as shown below when exporting a snapshot from either the command line or the user interface.

Screenshot - 24_10_2019 , 20_13_27

I could not find an obvious preference setting to manipulate the texmap behaviour in this case.

As I am able to produce this behaviour with my installed instance of LDView, I will say it is not a result of my modifications to the LPub3D instance of LDView.

Cheers,

trevorsandy commented 4 years ago

Solution

LDView has the following option in its Primitives preferences:

    - LDraw transparent textures last

You must check this option to properly render the texmap.

To set this on the command line, use -TexturesAfterTransparent=1.

This flag is not set by default in LPub3D. To do so you have 2 options.

  1. Using LDView Preferences:

Screenshot - 25_10_2019 , 20_53_02

  1. Or local/global meta command set in the model file using the new "Add Renderer Arguments" dialogue:

Screenshot - 25_10_2019 , 20_54_30

Screenshot - 25_10_2019 , 20_55_11

Don't forget to reset the appropriate cache(s) and click the editor's update button:

Screenshot - 25_10_2019 , 20_57_55

Screenshot - 25_10_2019 , 20_58_40

Note that if you get a result like shown in the screenshot above (where the texture is only partially visible), you may be able to improve the texture quality by increasing the "Offset" setting right underneath "Draw transparent textures last" in LDView Preferences. The command line argument for the "Add Renderer Arguments" dialogue is -TextureOffsetFactor=<value>, where <value> is a decimal number between 1.0 and 10.0. The default value is 5.0.

Cheers,