JSCAD User Group
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Using JSCAD to build meshes for BabylonJS

    Scheduled Pinned Locked Moved Design Discussions
    10 Posts 3 Posters 2.8k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ajw1970A Offline
      ajw1970
      last edited by

      Does anybody have experience with using JSCAD to build meshes for use in BabylonJS?

      I'm looking to build some dynamic models which are going beyond the capabilities of BabylonJS but I would like to use them within BabylonJS.

      I'm looking for any advice I can find. Thank you.

      For context, I started out in Babylon and ran into limitations with their path2d fuctions:

      https://forum.babylonjs.com/t/trying-to-build-an-extruded-path2-with-ribbon/27808/3

      I then tried it in JSCAD:

      /**
       * 2D Primitives Demonstration
       * @category Creating Shapes
       * @skillLevel 1
       * @description Demonstrating the basics of a variety of 2D primitives
       * @tags circle, square, line, ellipse, polygon, shape, 2d
       * @authors Simon Clark
       * @licence MIT License
       */
      
      const { path2 } = require('@jscad/modeling').geometries
      const { expand, offset } = require('@jscad/modeling').expansions
      const { extrudeLinear, extrudeRectangular, extrudeRotate } = require('@jscad/modeling').extrusions
      const { translate } = require('@jscad/modeling').transforms
      
      const main = () => {
        let tdcPathCenter = path2.fromPoints({}, [[0,0]]);
        tdcPathCenter = path2.appendArc({endpoint: [-0.0596,-0.02], radius: [0.0988,0.0988]}, tdcPathCenter);
        tdcPathCenter = path2.appendPoints([[-0.0922,-0.0447]],tdcPathCenter);
        tdcPathCenter = path2.appendArc({endpoint: [-0.123,-0.055], radius: [0.051,0.051], clockwise: true}, tdcPathCenter);
        tdcPathCenter = path2.appendPoints([[-0.2432,-0.055]],tdcPathCenter);
        tdcPathCenter = path2.appendArc({endpoint: [-0.2942,-0.004], radius: [0.051,0.051], clockwise: true}, tdcPathCenter);
        tdcPathCenter = path2.appendPoints([[-0.2942,1.1196]],tdcPathCenter);
        tdcPathCenter = path2.appendArc({endpoint: [-0.2479,1.1704], radius: [0.051,0.051], clockwise: true}, tdcPathCenter);
        tdcPathCenter = path2.appendPoints([[-0.1272,1.1803]],tdcPathCenter);
        tdcPathCenter = path2.appendArc({endpoint: [-0.1002,1.1677], radius: [0.03,0.03], clockwise: true}, tdcPathCenter);
        tdcPathCenter = path2.appendArc({endpoint: [-0.0467,1.2829], radius: [0.0733,0.0733], clockwise: false, large: true}, tdcPathCenter);
        tdcPathCenter = path2.appendPoints([[-0.2466,1.2664]],tdcPathCenter);
      
      
        let tdcProfile = expand({delta:0.015}, tdcPathCenter);
      
        let tdcFlange = extrudeLinear({height: 10}, tdcProfile);
      
        return tdcFlange;
        }
      
      module.exports = { main }
      
      

      I'm wondering how to then extract from this solid something that could be used in BabylonJS

      z3devZ 1 Reply Last reply Reply Quote 0
      • hrgdavorH Offline
        hrgdavor
        last edited by

        Hi,
        I am currently working on compatibility layer for 3 webgl libs I know of: relg(currenttly used in jscad), threejs, babylonjs.

        I have pieces needed for threejs and regl, but I have just started with Exploring creating line segments and mesh via TypedArray directly (it is important for usability with web workers and performance of postMessage)

        The work is part of a prototype branch,
        https://github.com/jscad/OpenJSCAD.org/discussions/944

        If you use discord, I am more active there https://discord.gg/AaqGskur93

        Unfortunately email notifications do not work on this forum, and sometimes days go by before I remember to check for new topics . Actually @platypii alerted me about your question.

        I will check-in here also after I produce at least some working code for Babylonjs.

        ajw1970A 1 Reply Last reply Reply Quote 0
        • z3devZ Offline
          z3dev @ajw1970
          last edited by

          @ajw1970 welcome

          So, what are you expecting to,do with the meshes? Is this for display only? Or for export into models for 3D printing?

          JSCAD is focused on 3D printing. Of course, it can be used to display solids, but there are far better choices for creating complex renderings.

          ajw1970A 1 Reply Last reply Reply Quote 0
          • ajw1970A Offline
            ajw1970 @z3dev
            last edited by

            @z3dev display only.

            hrgdavorH 1 Reply Last reply Reply Quote 0
            • hrgdavorH Offline
              hrgdavor @ajw1970
              last edited by

              @ajw1970 I am curious, do you have a lot of experience with Babylonjs ?
              Is there a specific reason you are using it instead of Threejs ?
              I am not advocating Threejs or Babylon, it is just that I already have code that converts jscad models to Threejs geometries and Babylon is only in progress.

              ajw1970A 1 Reply Last reply Reply Quote 0
              • ajw1970A Offline
                ajw1970 @hrgdavor
                last edited by

                @hrgdavor I'm working with a consultant with experience in BabylonJs. The end goal will be a full coil processing line simulator and everything I'm seeing about BabylonJs looks to be right for the job with the exception of dynamically modeling this part. 🙂

                1 Reply Last reply Reply Quote 0
                • ajw1970A Offline
                  ajw1970 @hrgdavor
                  last edited by

                  @hrgdavor Thank you. I think for now I can just use JSCAD to get the points for my profile. I can then extrude that in BabylonJs to get the meshes.

                  hrgdavorH 1 Reply Last reply Reply Quote 0
                  • hrgdavorH Offline
                    hrgdavor @ajw1970
                    last edited by

                    @ajw1970 if you just push the jscad geometries to console or generate json, you will see the data inside is pretty intutive to to go through and convert to points for babylon or whatever you need.

                    1 Reply Last reply Reply Quote 0
                    • ajw1970A Offline
                      ajw1970
                      last edited by

                      In the end, I imported @jscad and used Path2 and Expand to build my profile for extruding and then handed those points over to Babylon to do the extrusion to mesh. Works well.

                      z3devZ 1 Reply Last reply Reply Quote 0
                      • z3devZ Offline
                        z3dev @ajw1970
                        last edited by

                        @ajw1970 super!

                        I'm interested in the final application. Why did you want to use Babylon for rendering? And do you further plans to create some online designs?

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        Powered by NodeBB | Contributors