sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Output 3d model by small tiles

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 141 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.
    • J Offline
      jlai
      last edited by

      Hi all,

      I'd like to output my model into 4 quad images(each a 256x256 png) , and then combine them into a big one (512x512). I wrote a plugin that sort of worked, but the 4 quads don't EXACTLY align (please see the attachment, esp. the bottom 2 pngs). Could someone please help?

      • jay

      Here are my steps:

      1. I resize the SU window so make sure the view's client area is 512x512 pixels (used Spy++ to verify it).
      2. In SU, I set the camera to be paraline.
      3. In my plug in, I have a fucntion restore_camera, used to reset the camera each time before I output the quad image:

      def restore_camera(vx,vy,vz,tx,ty,tz,ux,uy,uz)
      new_eye = [vx,vy,vz]
      new_target = [tx,ty,tz]
      new_up = [ux,uy,uz]
      new_camera = Sketchup::Camera.new(new_eye,new_target,new_up,false)

      model = Sketchup.active_model
      view = model.active_view
      view.camera = new_camera

      view.zoom_extents
      view.zoom 1.0525
      view.refresh
      end

      1. For each quad, the outputting image part looks like the following. I'm adding each quad with 4 lines, selecting them, and zoom to selection. These quads are visible in the attached png.

      x, y below is the column/row index of the 4 quads, the 4 quads will be (0,0),(1,0),(0,1),(1,1) respectively

      z = 1
      tileWH = 256
      ip0 = view.inputpoint (xtileWH, ytileWH)
      ip1 = view.inputpoint ((x+1)tileWH, ytileWH)
      ip2 = view.inputpoint ((x+1)*tileWH, (y+1)tileWH)
      ip3 = view.inputpoint (x
      tileWH, (y+1)*tileWH)
      pt3d_0 = ip0.position
      pt3d_1 = ip1.position
      pt3d_2 = ip2.position
      pt3d_3 = ip3.position

      theEdges= []
      theEdges[0] = Sketchup.active_model.entities.add_line pt3d_0, pt3d_1
      theEdges[1] = Sketchup.active_model.entities.add_line pt3d_1, pt3d_2
      theEdges[2] = Sketchup.active_model.entities.add_line pt3d_2, pt3d_3
      theEdges[3] = Sketchup.active_model.entities.add_line pt3d_3, pt3d_0

      Sketchup.active_model.selection.add theEdges
      view.zoom theEdges
      view.zoom 1.0525
      view.refresh

      write_current_view("c:/temp/su_output/" + z.to_s() + "" + x.to_s() + "" + y.to_s() + ".png")


      the combined 4 quads png

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        I think you need to set the camera to Parallel Projection:

        camera.perspective=false

        I would think it may be less hassle.. to write out the large 512x512 image, then use another utility such as ImageMagic? to cut up the image into quads.

        Or you could bring the image back into Sketchup, explode it, and draw 2 lines from the midpoints of each opposite edge, cutting the image into quads.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • J Offline
          jlai
          last edited by

          Thanks, I was already doing paraline projection in the camera constructor.

          I was only using quads as an example. In the plugin I'm writing, it could be as many as 1024x1024 tiles (each 256x256 pixels), over the single file size/memory limit.

          Could someone please let me know what I did wrong in the code, or point me to a right direction?

          Much appreciated.

          1 Reply Last reply Reply Quote 0
          • J Offline
            jlai
            last edited by

            I still couldn't solve the problem. Could some guru here please help?
            Thanks a lot.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement