leozide / leocad

A CAD application for creating virtual LEGO models
https://www.leocad.org
2.49k stars 211 forks source link

Camera angles while CLI rendering #943

Closed tampe125 closed 1 month ago

tampe125 commented 1 month ago

This is not a bug report nor a feature request, but I could not find any better place to post this question.
I'm currently trying to use LeoCAD to render LEGO pieces from different angles and I'm using the following command:

leocad -w 1000 -h 1000 --line-width 1 --viewpoint home -l library/ldraw -i test.png library/ldraw/parts/3001.dat

That will correctly output a 2x4 brick in the "home" position (as well as top, bottom etc.). What I'm trying to achieve is to render the same piece from different angles, for example 45° from the bottom.
I tried to play with the option camera-angles but I could not find the proper way, it seems everything is a little "too close".
So I decided to play with the option camera-position. To better understand the values, I created a dummy project with just a brick and took a look at the contents of the file:

0 
0 Name: New Model.ldr
0 Author: 
1 7 50 -24 -90 1 0 0 0 1 0 0 0 1 3001.dat
0 !LEOCAD CAMERA FOV 30 ZNEAR 25 ZFAR 50000
0 !LEOCAD CAMERA POSITION 202.118 -336.217 -235.106
0 !LEOCAD CAMERA TARGET_POSITION 116.154 -193.448 -88.89
0 !LEOCAD CAMERA UP_VECTOR -0.266364 -0.763245 0.588648
0 !LEOCAD CAMERA NAME Camera 1

With those info I tried to run it from the CLI using this command:

leocad --fov 30 --zplanes 25 50000 --camera-position-ldraw 202.118 -336.217 -235.106 116.154 -193.448 -88.89 -0.266364 -0.763245 0.588648 -w 500 -h 500 --line-width 1 -l library/ldraw -i x.png library/ldraw/parts/3001.dat

But then leocad complained about the values for the camera-position-ldraw.
Obviously I'm missing something, can I get any direction?

app4soft commented 1 month ago

@tampe125, Has you tried to use existing camera directly?

leocad --camera "Camera 1" -w 500 -h 500 --line-width 1 -l library/ldraw -i x.png library/ldraw/parts/3001.dat
tampe125 commented 1 month ago

No, but I just tried and it works fine. But how can I render the piece from different angles?

EDIT It seems to be working fine because the option is ignored since there's no Camera on .dat files :) So it defaults to the home view and it works "fine", but it's not the desired output.

app4soft commented 1 month ago

But I also tried to use your sample LDR-file with both variants of this option, --camera-position and --camera-position-ldraw, and in both cases it returns the next errors (even there is a camera in the LDR-file):

So, there really is a bug in LeoCAD related to how this option expected to work.

Workaround

As a workaround, its possible to use Bash+sed+grep for creating temporary LDR-file (on the template you provided) with setting the camera angle and for each render job (use of --camera) just change the linked part in it.

tampe125 commented 1 month ago

Thank you! I was afraid I had to cobble together something like that, but at least I have a workaround

trevorsandy commented 1 month ago

Have you tried

--camera-angles <latitude> <longitude>: Set the camera angles in degrees around the model.

Here is the help output. You may have to direct --help to a file (leocad --help > help.out) as I don't believe output is sent to console.

``` Usage: leocad [options] [file] [options] can be: -l, --libpath : Set the Parts Library location to path. -i, --image : Save a picture in the format specified by ext and exit. -w, --width : Set the picture width. -h, --height : Set the picture height. -f, --from : Set the first step to save pictures. -t, --to : Set the last step to save pictures. -s, --submodel : Set the active submodel. -c, --camera : Set the active camera. -ss, --stud-style : Set the stud style 0=No style, 1=LDraw single wire, 2=LDraw double wire, 3=LDraw raised floating, 4=LDraw raised rounded, 5=LDraw subtle rounded, 6=LEGO no logo, 7=LEGO single wire. --viewpoint : Set the viewpoint. --camera-angles : Set the camera angles in degrees around the model. --camera-position : Set the camera position, target and up vector. --camera-position-ldraw : Set the camera position, target and up vector using LDraw coordinates. --orthographic: Render images using an orthographic projection. --fov : Set the vertical field of view used to render images (< 180). --zplanes : Set the near and far clipping planes used to render images (1 <= < ). --fade-steps: Render parts from prior steps faded. --no-fade-steps: Do not render parts from prior steps faded. --fade-steps-color : Renderinng color for prior step parts (#AARRGGBB). --highlight: Highlight parts in the steps they appear. --no-highlight: Do not highlight parts in the steps they appear. --highlight-color: Rendering color for highlighted parts (#AARRGGBB). --shading : Select shading mode for rendering. --line-width : Set the width of the edge lines. --aa-samples : AntiAliasing sample size (1, 2, 4, or 8). -nscc, --disable-stud-cylinder-color: Disable high contrast stud cylinder color. -scc, --stud-cylinder-color <#AARRGGBB>: High contrast stud cylinder color. -nec, --disable-edge-color: Disable high contrast edge color. -ec, --edge-color <#AARRGGBB>: High contrast edge color. -nbec, --disable-black-edge-color: Disable high contrast edge color for black parts. -bec, --black-edge-color <#AARRGGBB>: High contrast edge color for black parts. -ndec, --disable-dark-edge-color: Disable high contrast edge color for dark color parts. -dec, --dark-edge-color <#AARRGGBB>: High contrast edge color for dark color parts. -aec, --automate-edge-color: Enable automatically adjusted edge colors. -cc, --color-contrast : Color contrast value between 0.0 and 1.0. -ldv, --light-dark-value : Light/Dark color value between 0.0 and 1.0. -obj, --export-wavefront : Export the model to Wavefront OBJ format. -3ds, --export-3ds : Export the model to 3D Studio 3DS format. -dae, --export-collada : Export the model to COLLADA DAE format. -csv, --export-csv : Export the list of parts used in csv format. -html, --export-html : Create an HTML page for the model. -v, --version: Output version information and exit. -?, --help: Display this help message and exit. ```

Cheers,

tampe125 commented 1 month ago

I tried to play with the option camera-angles but I could not find the proper way, it seems everything is a little "too close".

Yep

app4soft commented 1 month ago

I just retried with other options — and LeoCAD renders it as expected:

./LeoCAD*.AppImage --fov 30 --zplanes 25 5000 --camera-position-ldraw 100 400 100 0 0 0 0 0 1 -w 500 -h 500 --line-width 1 -l ./ldraw -i ./x.png ./ldraw/parts/3001.dat
Saved './x.png'.

But it still fails with you command prompt:

./LeoCAD*.AppImage --fov 30 --zplanes 25 50000 --camera-position-ldraw 202.118 -336.217 -235.106 116.154 -193.448 -88.89 -0.266364 -0.763245 0.588648 -w 500 -h 500 --line-width 1 -l ./ldraw -i ./x.png ./ldraw/parts/3001.dat
Invalid parameter value(s) specified for the '--camera-position-ldraw' option.

So, the only difference between these two command promts is values of camera coordinates.

leozide commented 1 month ago

try latest

app4soft commented 1 month ago

try latest

@leozide, Just tried ­-- issue has been fixed.

Thanks.