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

    Obj file with colors

    Scheduled Pinned Locked Moved Development Discussions
    4 Posts 2 Posters 995 Views 1 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.
    • gilboonetG Offline
      gilboonet
      last edited by gilboonet

      Hello, as on my workflow I'm using obj files where I have groups (facets) that I colored, I was wondering if it could be done with jcsad 2. I didn't realize that immediately, but obj require handle groups by creating an array instead of a sole polyhedron, so it was not hard to do. For the moment I read the groups colors by hand, but they are into the companion file .mtl and could be fetched (I suppose it's for each group on 'kd' entry. Anyway that's already very nice.

      const jscad = require('@jscad/modeling')
      const { colors } = jscad
      const { colorize } = colors
      
      //const obj = require('./Gargouille692.obj')
      const obj = require('./6ZonesMat.obj')
      
      const main = () => {
        let cols = [
        [0,153,0],
        [0,153,255],
        [153,214,255],
        [163,102,0],
        [163,254,102],
        [254,204,255],
        [255,255,1]
        ].map(x=> x.map(y => y/255))
        
        let r = obj.map((x, index)=> colorize(cols[index], x))
        
        return r
      }
      
      module.exports = { main }
      

      Capture d’écran de 2020-09-17 10-30-47.png

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

        @gilboonet sorry for the late reply. there was a change to the OBJ deserializer (import) to translate the 'material' name to an internal color specification. So, if the OBJ file has several groups (materials/colors) then result will have several colors.

        https://github.com/jscad/OpenJSCAD.org/tree/V2/packages/io/obj-deserializer

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

          That's nice to see such feature, it works fine...
          Capture d’écran de 2021-04-07 20-50-25.png

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

            @z3dev There's one thing that still makes me use obj from my obj2jscad.js. It is that the deserialized obj loses the polygon vertices list and it needs to be rebuild from the geometries, unless I didn'k look at the right place. But as 99 % of the time the user won't use those data, I understand that the deserializer don't keep track of them.

            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