Using LDCad flexible parts with Studio


Using LDCad flexible parts with Studio
#1
Studio is a nice LEGO CAD tool, but current version (2.0.1(39)) lacks flexible parts. Fortunately, with some tweaks (and a few caveats), it is possible to use LDCad flexible parts in Studio.

If you created your model with Studio, you need to
  • export it as LDraw
  • open the exported model with LDCad
  • add the flex parts using the guidelines that follow.
  • reload the LDraw model in Studio.
If, like me, you are a die-hard LDCad user, you can still use these tips to make use of the great photorealistic rendering engine included in Studio, or its fast and user friendly instruction generator. I find that Studio editor is not nearly as convenient, flexible and powerful as LDCad, but I'm probably biased Wink

How it works?
LDCad uses specialized meta-commands to describe the flexible parts but also create a generic fallback LDraw representation. It is this fallback which is visible in Studio if two conditions are met:
  • the fallback is made with segment parts present in the LDraw library of Studio
  • The segment parts are not scaled: Studio is not able to scale parts.
Important note:
This is NOT a LDCad flexible parts tutorial! For more details, see LDCad documentation, video tutorials and technical documentation.
Reply
1 - Directly compatible flexible parts
#2
[Image: easy-flex.jpg]
This is the easy case: LDCad fallback representation uses only unscaled LDraw parts. LDCAd model can then simply be loaded in Studio.
This is the case for all chains (Technic and System), System flexible hose and Technic ribbed hose. For this one, you must use the LQ template version (Technic Ribbed Hose LQ). HQ version doesn't use segment parts but a single mesh that can be visually better but doesn't import easily in Studio.
Files: LDraw, Studio
Reply
2 - Flexible parts with scaled segments
#3
[Image: unscaledflex.jpg]

Here LDCad fallback representation uses scaled LDraw segments, so you must tweak flexible parts to force LDCad to use unscaled segments. Otherwise flex parts looks like dashed lines in Studio, like this:
[Image: scaledflex.jpg]

This is the case for all Power Functions and Powered Up elements, as well as pneumatic hoses. You must always use the LQ template version (eg. Power Functions L Motor (LQ), Pneumatic Hose LQ). HQ versions don't use segment parts but a single mesh that can be visually better but don't import easily in Studio.

How to unscale segments:
  • In LDCad nested mode, click on the flexible section of the part to select it, then right-click -> properties
  • Set Basesize=100%, Segment size = 50%, maxmerge = 1 as shown in this screen capture.
[Image: skin1.jpg]

Of course you can also create a Studio compatible LDCad template instead of edit each and every flex part in your model!

I strongly suggest not to edit regular LDCad template, but copy it and edit the template copy. LDCad templates are located in %appdata%\LDCad\templates\ subfolders (Windows).

Here is for example a Studio-compatible pneumatic hose template. To use it place it in the same folder as regular template, in %appdata%\LDCad\templates\path\

Files: LDraw, Studio
Reply
RE: 2 - Flexible parts with scaled segments
#4
Philo,

Could you please copy these information into a wiki tutorial?

w.o
LEGO ergo sum
Reply
3 - Flexible parts that need segment changes
#5
[Image: trickyflex.jpg]

This is the most complex situation: LDCad uses (scaled) segment parts that are not in LDraw library, so you have to find a suitable segment that is in library and modify flex part accordingly.

This is the case for strings, rubber belts, 9V and NXT/EV3 cables, Technic flexible axles and flex-system hoses.

How to change and unscale segments:
  • In LDCad nested mode, click on the flexible section of the part to select it, then right-click -> properties
  • Set Basesize=100%, Segment size = 50%, maxmerge = 1 as shown in this screen capture.
  • Change Donor placement type to Static references and Final scale to Segment merge only
  • Change the Part to the name of LDraw segment file.

[Image: skin2.jpg]

Suggested segment files:
  • 9V cable: 993.dat
  • NXT/EV3 cable: 932.dat
  • flex-system hose: 77.dat
  • round rubber band, strings: 4-4cyli.dat (result is a bit thin, but...)
  • square rubber band: box4o8a.dat
  • Body of Technic flex axle: axlehol8.dat. But you must also provide appropriate segments for the ends, so the best is to use this template!
Two other templates I made: NXT/EV3 cable, string with end studs.

 To use them, place them in the same folder as the matching regular templates, in %appdata%\LDCad\templates\path\

Files: LDraw, Studio

[Image: trickyflexrender.png]
Reply
RE: 2 - Flexible parts with scaled segments
#6
(2018-11-02, 15:43)Philippe Hurbain Wrote: [Image: scaledflex.jpg]

Is there any similar workaround for using LSynth parts in Studio? I have exactly this issue with the renderer, where the part segments show as disconnected rather than continuous, for the flex system (rigid) hoses. (I'm using Mac, so Bricksmith is my LDraw editor which means LSynth is my option for flexible parts, since Studio's is not usable.)
Reply
RE: Using LDCad flexible parts with Studio
#7
Forgive me if this has been answered before, but is there something similar you have to do to use the spring parts? When I load a shock absorber into Studio, the spring mesh is not visible.
Reply
RE: Using LDCad flexible parts with Studio
#8
(2019-11-02, 5:54)N. W. Perry Wrote: Forgive me if this has been answered before, but is there something similar you have to do to use the spring parts? When I load a shock absorber into Studio, the spring mesh is not visible.
Well, yes, it's possible, but really convolved. The spring is generated by LDCad as a custom mesh, and there is no LQ version created with repeated LDraw elements. So the idea is to use the fallback code of the spring (used to see the spring outside LDCad) and put it as a custom part in Studio CustomParts\parts folder (Studio is unable to use parts embedded in MPD Sad ). Another drawback is that the spring is "frozen", so you can't adjust length after processing.

Here is the whole process...
- Start with LDCad code with shock absorbers (attachment shock1.mpd)
- Open it with a text editor.
- Search and replace string "springMesh.ldr" with "springMesh.dat" (Studio is unable to use part files with .ldr extensions Angry )
- Cut the section(s) of LDraw code after "0 FILE blahblah_springMesh.dat" and put them in separate file(s) named blahblah_springMesh.dat (attachments shock-06_5L-soft-1_springMesh.dat and shock-09_5L-hard-1_springMesh.dat).
- Place these files in Studio custom parts folder (C:\Users\<your user name>\AppData\Local\Stud.io\CustomParts\parts)
- Remove the 0 !LDCAD metacommand lines to avoid accidental changes of the code if you reopen file with LDCad
- Open resulting file in Studio (attachment shock2.mpd)

...but for most models I use uncompressed LDraw shortcuts to avoid the hassle!!!


Attached Files Thumbnail(s)
       

.mpd   shock1.mpd (Size: 1.77 MB / Downloads: 11)
.dat   shock-06_5L-soft-1_springMesh.dat (Size: 476.13 KB / Downloads: 12)
.dat   shock-09_5L-hard-1_springMesh.dat (Size: 1.3 MB / Downloads: 10)
.mpd   shock2.mpd (Size: 1.47 KB / Downloads: 9)
Reply
RE: Using LDCad flexible parts with Studio
#9
(2019-11-02, 10:52)Philippe Hurbain Wrote: Well, yes, it's possible, but really convolved. The spring is generated by LDCad as a custom mesh, and there is no LQ version created with repeated LDraw elements. So the idea is to use the fallback code of the spring (used to see the spring outside LDCad) and put it as a custom part in Studio CustomParts\parts folder (Studio is unable to use parts embedded in MPD Sad ). Another drawback is that the spring is "frozen", so you can't adjust length after processing.

Here is the whole process...
- Start with LDCad code with shock absorbers (attachment shock1.mpd)
- Open it with a text editor.
- Search and replace string "springMesh.ldr" with "springMesh.dat" (Studio is unable to use part files with .ldr extensions Angry )
- Cut the section(s) of LDraw code after "0 FILE blahblah_springMesh.dat" and put them in separate file(s) named blahblah_springMesh.dat (attachments shock-06_5L-soft-1_springMesh.dat and shock-09_5L-hard-1_springMesh.dat).
- Place these files in Studio custom parts folder (C:\Users\<your user name>\AppData\Local\Stud.io\CustomParts\parts)
- Remove the 0 !LDCAD metacommand lines to avoid accidental changes of the code if you reopen file with LDCad
- Open resulting file in Studio (attachment shock2.mpd)

...but for most models I use uncompressed LDraw shortcuts to avoid the hassle!!!

Wow, convolved indeed, but superbly helpful, thanks! I don't have much fear of accidentally ruining the file in Studio, as I'll only bring it in there for rendering…we'll see how that goes.
Reply
RE: Using LDCad flexible parts with Studio
#10
(2019-11-03, 5:34)N. W. Perry Wrote: Wow, convolved indeed, but superbly helpful, thanks! I don't have much fear of accidentally ruining the file in Studio, as I'll only bring it in there for rendering…we'll see how that goes.
No risk indeed with Custom parts folder. Actually I tend to use it in a "project specific" manner, I put there only the parts needed, and cleanup everything at the end (sometimes I zip the whole folder if I want to keep it for later). Too many parts there slows down Studio part editor startup.
Reply
RE: 3 - Flexible parts that need segment changes
#11
(2018-11-03, 19:44)Philippe Hurbain Wrote: Body of Technic flex axle: axlehol8.dat. But you must also provide appropriate segments for the ends, so the best is to use this template!

Perhaps I should have used your template, Philo…I used the regular LDCad template, but just changing all of the different segments to the appropriate part. (I wanted to use the LDCad template so the path caps would have the proper grouping and snap info.)

Unfortunately, I get some visible gaps in the render—does your template account for this? or is there some setting I can tweak?

   
Reply
RE: 3 - Flexible parts that need segment changes
#12
(2020-03-29, 4:56)N. W. Perry Wrote: Unfortunately, I get some visible gaps in the render—does your template account for this? or is there some setting I can tweak?
Basically for LQ flex parts, the trick is to increase overlap between segments. To do that, lower "Segment size" below 100%. If the visual length of the segment must be preserved (ends of flex axle), increase "Base size" proportionnally.
I tweaked my flex axle template (http://www.brickshelf.com/gallery/Philo/...studio.ldr) because there were gaps in the ends of axles. I changed Segment size to 80% and Base size to 125%, now it looks good:
[Image: flexaxle.png]
Reply
RE: 3 - Flexible parts that need segment changes
#13
(2020-03-29, 11:11)Philippe Hurbain Wrote: Basically for LQ flex parts, the trick is to increase overlap between segments. To do that, lower "Segment size" below 100%. If the visual length of the segment must be preserved (ends of flex axle), increase "Base size" proportionnally.
I tweaked my flex axle template (http://www.brickshelf.com/gallery/Philo/...studio.ldr) because there were gaps in the ends of axles. I changed Segment size to 80% and Base size to 125%, now it looks good:

OK, that's better indeed. (I still have some minuscule seams visible, but I can tell they're due to primitive substitution, not segment overlap, since they're not at the joints between segments.) However, I thought we had to set all basesizes to 100%, because Studio isn't able to scale segments; why does it work in this case?
   
Also…does it look like I have a little gap between the subparts of the path cap (at the "hilt" of the axle end)? I don't think that's just a shadow. Perhaps I'll try the Philo version with the added 77.dat segments…
Reply
RE: 3 - Flexible parts that need segment changes
#14
(2020-03-29, 18:20)N. W. Perry Wrote: However, I thought we had to set all basesizes to 100%, because Studio isn't able to scale segments; why does it work in this case?
Question is not "in this case", it's "now"... this has been corrected some time ago. Still a bit buggy, faked seams are also scaled in renders. This prevents to use large scaling factors.
Reply
RE: 3 - Flexible parts that need segment changes
#15
(2020-03-29, 18:33)Philippe Hurbain Wrote: Question is not "in this case", it's "now"... this has been corrected some time ago. Still a bit buggy, faked seams are also scaled in renders. This prevents to use large scaling factors.

Ah, good—I never realized that had been fixed! So it's still a good idea to change the base size from, say, 400% to 100% (and maxmerge to 1, to avoid super-long straight segments)?

Also, I just figured out that for the flex axle, you don't actually have to change the donor part at all, because all of the LDCad donor parts are just references to regular library parts. You can just select "static references", and then either check "inline donor references", or leave it unchecked and just copy the LDCad donor files into Studio's custom parts directory.
Reply
RE: 3 - Flexible parts that need segment changes
#16
(2020-03-30, 0:42)N. W. Perry Wrote: Ah, good—I never realized that had been fixed! So it's still a good idea to change the base size from, say, 400% to 100% (and maxmerge to 1, to avoid super-long straight segments)?
The idea is to keep scaling factor "low enough" since fake seam sizes are scaled by the same amount. For a plausible gap of 0.25 ldu, a 400% scaling gives a 1 ldu gap, something easily accounted for by segment overlaps. And hopefully this will be corrected. One day. Or another.  Angel

Quote:Also, I just figured out that for the flex axle, you don't actually have to change the donor part at all, because all of the LDCad donor parts are just references to regular library parts. You can just select "static references", and then either check "inline donor references", or leave it unchecked and just copy the LDCad donor files into Studio's custom parts directory.
Yes, that's a possibility. The benefit of using LDraw segments is that they are already in Studio library.
Reply
RE: 3 - Flexible parts that need segment changes
#17
One final (hopefully) update: I investigated the gap in the end piece; see below for an image of the problem. The top axle uses LDCad's default flex axle template; note the space at the "hilt" of the cap part on the lower end. (Segment sizes have been adjusted at the lower end of the piece, but not the upper, hence the visible seams there.) The bottom axle shows the problem corrected after making my own adjustments—read on…
   

I tried using Philo's flex axle template, and it does indeed fix the problem. This template uses additional segments (77.dat) in the "handle" portion of the axle so that it, too, is flexible (it isn't in the LDCad version). It seems that the adjustment of segment sizes in this section creates enough overlap to eliminate the gap—which I bet comes from the same issue of the rendering software scaling the fake seams, because LDCad's version of the handle is a stud3a primitive scaled to a factor of 5. (Also, Philo's 77.dat segments aren't scaled, so any fake seams between them would likewise not be scaled.)

However, I wanted to keep using LDCad's version of the end piece, because I actually want the handle to remain rigid (along with retaining the snap info and path cap auto-grouping). So I made my own version of the LDCad donor part (ldcFlexAxleCap.dat), with some extra overlap hardcoded in by increasing the scaling factor for the stud3a primitive, with an appropriate Y-offset to compensate.

I then made my own version of the LDCad flex axle template, substituting my new cap donor part, as well as adjusting the base and segment sizes for the flexible segments, and setting them to static donor references. Finally, I copied all of LDCad's donor files into Studio's custom parts folder and rendered the file, resulting in the bottom part in the picture, with all of the issues corrected.  Big Grin

Here is my version of the flex axle template adapted for rendering in Studio; use this one if you want the "handle" portion to stay rigid. (If you want it to be flexible, use Philo's template.) There are two files provided: use the second one if you have copied the LDCad donor files into Studio's custom parts folder; otherwise, use the first one. Place the file into LDCad's "templates->path" directory.

.ldr   technicFlexAxle-Inline.ldr (Size: 3.25 KB / Downloads: 12)

.ldr   technicFlexAxle-noInline.ldr (Size: 3.25 KB / Downloads: 9)

To use either of these files, you need my modified path cap donor part; place it in LDCad's "donors" folder.

.dat   ldcFlexAxleCap2.dat (Size: 309 bytes / Downloads: 15)
Reply
RE: 3 - Flexible parts that need segment changes
#18
(2020-03-30, 20:08)N. W. Perry Wrote: This template uses additional segments (77.dat) in the "handle" portion of the axle so that it, too, is flexible (it isn't in the LDCad version).
It used to be, but I changed it in 1.6b, I think, in order to make it snap.
Reply
RE: 3 - Flexible parts that need segment changes
#19
(2020-03-30, 21:59)Roland Melkert Wrote: It used to be, but I changed it in 1.6b, I think, in order to make it snap.

Having the snap info definitely helps, but also I think you need the PATH_CAP meta in order to predictably place the ends (particularly at the non-origin end).
Reply
RE: 3 - Flexible parts that need segment changes
#20
(2020-03-30, 21:59)Roland Melkert Wrote: It used to be, but I changed it in 1.6b, I think, in order to make it snap.

These days the flex axles are being used very often with 11090, which only holds about half the length of the tip. So I made a version of the template that still snaps in to this part, but only to a depth of 10 LDU, and then is flexible after that like the real thing. It's attached below, along with the custom end cap donor you need.

.ldr   technicFlexAxle-bendy.ldr (Size: 4.41 KB / Downloads: 5)

.dat   ldcFlexAxleCap3.dat (Size: 299 bytes / Downloads: 6)

For some reason that I don't fully understand, I had to change the edge deletion setting for the ldcFlexAxleEndC (and only at one end). None of the other donors needed any adjustments.
Reply
RE: Using LDCad flexible parts with Studio
#21
Code:
import argparse,os,re

parser = argparse.ArgumentParser(description='LDCAD to Stud.io Converter')
parser.add_argument('file', help='name of input file')

args = parser.parse_args()
if os.path.exists(args.file):
    f = open(args.file,"r")
    in_data = f.readlines()
else:
    print(''.join([args.file," does not exist"]))
    #exit()

file_name = args.file.rsplit(".",1)[0]
output_file_name = ''.join([file_name + "_studio.ldr"])

output_buff = ""
output_file = output_file_name
just_started = False

for line in in_data:
    if line.startswith("0 FILE "):
        if output_file == output_file_name and len(output_buff) > 0:
            of = open(output_file,'a')
        else:
            if os.path.exists(output_file):
                print("Output File " + output_file + " exists, overwriting...")
            of = open(output_file,'w')
        of.writelines(output_buff)
        of.close()
        output_file = output_file_name
        loc_file_name = ''.join([file_name,"_subpart_",line[7:].rsplit(".",1)[0],".dat"])
        loc_file_name_split = loc_file_name.split(" ")
        loc_file_name = '_'.join(loc_file_name_split)
        print(loc_file_name)
        output_buff = ''.join(["0 FILE ",loc_file_name,"\n"])
        just_started = True
    else :
        if just_started and line.startswith("0 Name:"):
            output_buff += ''.join(["0 ",loc_file_name,"\n"])
        just_started = False
        if line.strip().endswith(".ldr"):
            num_fields = 0
            if line.startswith("1"):
                num_fields = 14
            if line.startswith("0 Name:"):
                num_fields = 2
            if not num_fields:
                print("This line cannot be handled, exiting...")
                print(line)
                exit()
            new_line = ''.join([line.rsplit(".",1)[0],".dat\n"])
            line_data = new_line.split(" ")
            new_line = ' '.join([' '.join(line_data[:num_fields]),'_'.join([file_name,'subPart','_'.join(line_data[num_fields:])])])
            output_buff += new_line
        else:
            output_buff += line
        if line[0].isdigit() and int(line[0]) > 1:
            output_file = loc_file_name
print(output_file)
of = open(output_file,'a')
of.writelines(output_buff)
of.close()
I'm new to Lego designing so please bear with me, however this is what I've got so far.

I started with Stud.io and found it pretty nice and the render engine is really great to showcase your work.

Unfortunately it is not the best at manipulating elements, the drag/drop of blocks is useless, the coordinate system sucks in it and parts that are stuck together are not on round values at all, they're all over the place. If you're not looking at the source data some of it wouldn't bother you but I'm a stickler for nice round numbers and engineered precision.

So I found LDCAD and it does everything beautifully and intuitively once you get the hang of it. The keyboard shortcuts are amazing and overall the user interface is definitely for an engineer not an artist. Since I am one it fits me perfectly.

The only shortcoming I was missing was the rendering engine of Stud.io and the problem as everyone in this thread noticed has to do with how it handles flexible parts. Actually the rendering wasn't the issue, as LDView renders the fallback mesh just fine and the spring description hinted at Stud.io being able to handle meshes just in a convoluted way.

So the problem is that Stud.io only allows meshes to be present in part (.dat) files and not in model (.ldr) files. Any mesh that is in a model file gets ignored and fails to render. So the trick is to convert any part/sub-part of a model that contains meshes into .dat files and make them custom part(s).

Since the process outlined was rather labor intensive by hand I wrote a quick and dirty python script to take care of it. This will take the source file and output a new .ldr file with the mesh elements stripped out and put in .dat files that can easily be added to Stud.io as custom parts.

I also fixed the issue with step and subcomponent names not showing in Stud.io for LDRaw files output from LDCAD.

So my workflow now entails
1) Design and work in LDCAD
2) Embed all unofficial parts
3) Run the python script on the <orig>.mpd file
4) copy the produced .dat files into C:\Users\<user>\AppData\Local\Stud.io\CustomParts\parts\
5) Open the <orig>_studio.ldr file in Stud.io
6) Render away.

This produces much nicer renders and is a one step solution after I save the file in LDCAD.

Code might have bugs, let me know...

   

   
Reply
RE: Using LDCad flexible parts with Studio
#22
Welcome here!

(2021-01-03, 4:23)Greg Takacs Wrote: Code might have bugs, let me know...
Very interesting! One thing that could be improved is the management of subfolder. I would like to see files go to the right folder in the folder tree needed by Studio,
  • CustomParts
    • parts (parts)
      - s (subparts)
    • p (primitives)
      - 48 (Hires primitives)
      - 8 (lores primitives)
That would allow to directly copy the complete folder tree and use custom parts or any embedded part unknown by Studio.
Now that needs a significantly more elaborate parser, especially to sort primitive (need to use the part type line https://www.ldraw.org/article/398.html#ldraworg)
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 5 Guest(s)