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

    Has anyone had success using openjscad in react?

    Scheduled Pinned Locked Moved General Discussions
    15 Posts 4 Posters 4.3k 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.
    • K Offline
      kevinos @gilboonet
      last edited by

      @gilboonet Is this with React? I took the code in viewer-minimal.html, completely copied and pasted it into index.html added in the div with id root for react to pickup and that is all. I removed nothing from the example but it will not render.

      Just to be clear, I can get the view to render in a static html page, my question is more geared towards if anyone got it to render with react. I'm specifically using react and react-dom and this is on google chrome 84.0.4147.105 if that matters

      gilboonetG 1 Reply Last reply Reply Quote 0
      • gilboonetG Offline
        gilboonet @kevinos
        last edited by

        @kevinos No, as I wrote on my first reply, I don't use React.

        K 1 Reply Last reply Reply Quote 0
        • K Offline
          kevinos @gilboonet
          last edited by

          @gilboonet Ah ok, well thank you. So far I am able to embed openjscad into static pages, just have not been able to with react.

          1 Reply Last reply Reply Quote 0
          • K Offline
            kevinos @z3dev
            last edited by

            @z3dev Can you share your example with Vue? This might possibly give me some clues, or I might just switch to Vue.

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

              @kevinos sure.

              here's the code https://github.com/z3dev/vue-components

              this is only a viewer for a pre-compiled (JSON) design. V2 only!

              K 1 Reply Last reply Reply Quote 1
              • K Offline
                kevinos @z3dev
                last edited by

                @z3dev by V2 I assume you mean the V2 branch of the openjscad repo on github. What do you mean by pre-compiled (JSON) design? You won't insult my intelligence I'm fairly new to openjscad and web dev πŸ˜ƒ

                Also, thank you for sharing, I did test locally and your project works. Very exciting!

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

                  @kevinos no problem.

                  so, JSCAD designs are actually Javascript functions which perform calcuations, create geometry, perform operations with geometry, and finally return the geometry of interest.

                  const {primitives} = require('@jscad/modeling')
                  
                  const main = () => {
                    let object1 = primitives.circle({radius: 22, segments: 36})
                    object1.color = [1,0,0,1]
                  
                    return object1
                  }
                  module.exports = {main}
                  

                  The return of object1 from main() is a 2D geometry, i.e. a geom2 object. In the WEB UI, this object is passed to the 'rendering' function, and shows up on the screen as a red circle.

                  The Vue component requires 2D/3D geometries as well. And as a Vue component, it can live inside another Vue component (or application). This is the rendering piece only.

                  The JSCAD WEB UI is doing a whole lot more underneath. It loads all the code, evaluates (compiles?) each piece of code, and finally executes the main() function.

                  If you want this functionality then there's some more plumbing required.

                  N 1 Reply Last reply Reply Quote 1
                  • N Offline
                    noce2 @z3dev
                    last edited by

                    @z3dev thanks for the explanation. I am actually looking to implement something similar for Angular. Please do you have any general recommendations on how it could be done? On the minimal viewer I can see that the minified version of the UI js library is loaded onto the page and the desired example linked to in the viewer context element. Is that all that's required?

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

                      @noce2 you will have to piece together the components but it should be possible to implement something in Angular. i'm sure you'll find some help in this user group.

                      FYI, the V2 WEB UI uses 'most' which is a reactive framework based on the concept of 'streams'. So, Angular based components should be possible.

                      So, what kind of functionality are you looking to implement? This is always the BIG question, as everyone has a different idea. I suggest starting out with small goals, and then add features once the new components start to mature.

                      Please let us know where you will be working on the components. I'd like to follow along as I'm going to continue developing VUE components as well.

                      N 1 Reply Last reply Reply Quote 0
                      • N Offline
                        noce2 @z3dev
                        last edited by

                        @z3dev thank you. For now I would only like create a viewer element within an angular application. Is there a release of v2 on the public npm registry? I've had a look but can't seem to find it. If not, please could you point me to instructions on how to build it? I'd like to host it on my private registry for the rest of the work I intend to do.

                        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