trevorsandy / lpub3d

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

Sub-model which uses inherited colour only displayed with first colour instance #719

Closed d-j-m-0 closed 1 year ago

d-j-m-0 commented 1 year ago

Subject

If a sub-model contains parts defined with the LDraw inherited colour (i.e. colour value 16) and there are multiple instances of the sub-model contained in the model, if the parent file is using different colours for the sub-model instance, the generated instructions indicate two instances of the sub-model but both use the colour of the first occurring instance.

Environment

Steps to reproduce

Open the model in the attached zip file and step through the pages. Note the model within the zip file is a simple model whose sole purpose is to illustrate the issue.

Expected behaviour

A separate instance of the sub-model should be generated for each differing colour as specified within the parent file.

Actual behaviour

One instance of the sub-model is generated using only the first colour as specified within the parent with a 2x multiplier. The Bill of Materials correctly contains the appropriately coloured parts.

Workaround

Use multiple copies of the sub-model, with different names and the different instance accordingly. However, this then defeats the purpose of having a common sub-model and using colour inheritance.

Solution suggestion

When a sub-model uses the inherited colour, the colour specified in its parent (or other ancestors going back multiple layers as necessary) should determine whether it is okay to generate a single instance of the sub-model of multiple instance with appropriate colour variations.

inherited_colour.zip

trevorsandy commented 1 year ago

Thank you for reporting this behaviour - good catch!

I have added new behaviour that takes into account the submodel colour code when consolidating instances. By default the new behaviour is enabled. However, editors can change to the previous behaviour in Project Globals Setup.

CountInstanceByColour_01_719

The following model file displays 9 pages with this change enabled, versus 7 pages with the old behaviour.

CountInstanceByColour_02_719

0 FILE main.ldr
0 Name: inherited_colour
0 Author: David Manley
0 !LICENSE Free for non-commercial use.
0 !LPUB MULTI_STEP BEGIN
1 1 0 0 -40 1 0 0 0 1 0 0 0 1 common.ldr
0 STEP
1 4 0 0 40 1 0 0 0 1 0 0 0 1 common.ldr
0 STEP
0 !LPUB MULTI_STEP END
0 !LPUB INSERT PAGE
0 !LPUB INSERT BOM
0 NOFILE
0 FILE common.ldr
0 Name: common.ldr
0 Author: David Manley
0 !LICENSE Free for non-commercial use.
1 2 0 0 0 1 0 0 0 1 0 0 0 1 3003.dat
1 16 0 -24 0 1 0 0 0 1 0 0 0 1 3003.dat
1 16 0 48 0 1 0 0 0 1 0 0 0 1 sub-common.ldr
0 STEP
1 9 0 96 0 1 0 0 0 1 0 0 0 1 sub-common.ldr
0 NOFILE
0 FILE sub-common.ldr
0 Name: sub-common.ldr
0 Author: David Manley
0 !LICENSE Free for non-commercial use.
1 3 0 0 0 1 0 0 0 1 0 0 0 1 3003.dat
1 16 0 -24 0 1 0 0 0 1 0 0 0 1 3003.dat
0 NOFILE

Cheers,