JSCAD User Group

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Using JSCAD to build meshes for BabylonJS

    Design Discussions
    3
    10
    1308
    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.
    • ajw1970
      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

      z3dev 1 Reply Last reply Reply Quote 0
      • z3dev
        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
        • ajw1970
          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.

          z3dev 1 Reply Last reply Reply Quote 0
          • hrgdavor
            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
            • ajw1970
              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.

              hrgdavor 1 Reply Last reply Reply Quote 0
              • ajw1970
                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
                • hrgdavor
                  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.

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

                    @z3dev display only.

                    hrgdavor 1 Reply Last reply Reply Quote 0
                    • z3dev
                      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.

                      ajw1970 1 Reply Last reply Reply Quote 0
                      • hrgdavor
                        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.

                        ajw1970 1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB | Contributors