Output 3d model by small tiles
-
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:
- I resize the SU window so make sure the view's client area is 512x512 pixels (used Spy++ to verify it).
- In SU, I set the camera to be paraline.
- 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_cameraview.zoom_extents
view.zoom 1.0525
view.refresh
end- 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 (xtileWH, (y+1)*tileWH)
pt3d_0 = ip0.position
pt3d_1 = ip1.position
pt3d_2 = ip2.position
pt3d_3 = ip3.positiontheEdges= []
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_0Sketchup.active_model.selection.add theEdges
view.zoom theEdges
view.zoom 1.0525
view.refreshwrite_current_view("c:/temp/su_output/" + z.to_s() + "" + x.to_s() + "" + y.to_s() + ".png")
-
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.
-
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.
-
I still couldn't solve the problem. Could some guru here please help?
Thanks a lot.
Advertisement