slot = mat.texture_slots.add() slot.texture = texchecker slot.texture_coords = 'UV' slot.diffuse_color_factor = 1 ################################################ # Face label fid = numpy.loadtxt(pthout + 'faces/faces_id.dat', dtype=int) stlabel = numpy.loadtxt(pthout + 'faces/face_uvlabel_' + strf + '.dat', delimiter=',') xyzfacelabel = chebval2d(stlabel[0], stlabel[1], c) myl.addEmpty('label', xyzfacelabel) u, v = lbf.convert_3d_to_2d_coords(xyzfacelabel) f = open(pthout + 'faces/face_xyzlabel_' + strf + '.dat', 'w') f.write(str(fid[iface] + 1) + ', ' + str(u) + ', ' + str(v)) f.close() ################################################ # Freestyle settings freestyle = scene.render.layers.active.freestyle_settings freestyle.use_smoothness = True bpy.ops.scene.freestyle_lineset_add() #2 lineset = freestyle.linesets["LineSet"] lineset.visibility = 'VISIBLE'
################################################################ # ADJUST CAMERA # align with average normal at vertex cam.rotation_mode = 'QUATERNION' cam.rotation_quaternion = Vector(normal_avg).to_track_quat('Z', 'Y') # fit view bpy.ops.object.select_all(action='DESELECT') obj.select = True bpy.ops.view3d.camera_to_view_selected() cam.data.angle += numpy.radians(1.) ################################################################ ################################################################ # EXPORT VERTEX IMAGE COORDS vx, vy = lbf.convert_3d_to_2d_coords(V.xyz, normalize=True) #print('(vx, vy) = (%s, %s)' % (vx, vy)) f = open(pthout + 'xy_vertex.dat', 'w') f.write('%s, %s' % (vx, vy)) f.close() ################################################################ ################################################################ # EXPORT FACE LABEL IMAGE COORDS Rfacelabel = 0.13 f = open(pthout + 'xy_facelabel.dat', 'w') for c in xyz_facecenter: cx, cy = lbf.convert_3d_to_2d_coords(c, normalize=True) #print('(cx, cy) = (%s, %s)' % (cx, cy)) dx = cx - vx
mat_EdS.alpha = 0.68 mat_EdS.emit = 1.0 mat_EdS.specular_intensity = 0.5 mat_EdS.specular_hardness = 30 mat_EdS.raytrace_transparency.fresnel = 2.7 mat_EdS.use_shadows = False mat_EdS.use_cast_buffer_shadows = False EdS.data.materials.append(mat_EdS) ################################################ ################################################ # EXPORT SPINE'S COORDINATES IN IMAGE f = open(pth + 'spine_xy.dat', 'w') for xyz in g: x, y = lbf.convert_3d_to_2d_coords(xyz, normalize=True) f.write('%s %s\n' % (x, y)) f.close() ################################################ ################################################ # ADD SPHERE, PLANE AND CHARACTERISTIC CIRCLE u0 = 0.5 g0 = Bxyz.eval(u0) dg0 = Bxyz.evald(u0) r0 = Br.eval(u0)[1] dr0 = Br.evald(u0)[1] f = open(pth + 'spine_point_tangent.dat', 'w')
lbe.set_smooth(obj) obj.data.materials.append(mat) quads.append(obj) fclr.close() ################################################################ ################################################################ # ADJUST CAMERA cam.rotation_mode = 'QUATERNION' if True: cam.location = (0.78856, 0.63725, 0.68383) cam.rotation_quaternion = (0.417, 0.241, 0.439, 0.758) cam.data.angle = numpy.radians(34.) if False: cx, cy = lbf.convert_3d_to_2d_coords(Vector(V.xyz) + rho * c, normalize=True) print(cx, cy) cam.data.shift_x -= (0.5 - cx) cam.data.shift_y -= (0.5 - cy) print( lbf.convert_3d_to_2d_coords(Vector(V.xyz) + rho * c, normalize=True)) else: cam.rotation_quaternion = c.to_track_quat('Z', 'Y') bpy.ops.object.select_all(action='DESELECT') for obj in bpy.data.objects: if obj.name[0:9] == 'spherical': obj.select = True bpy.ops.view3d.camera_to_view_selected()
cam.rotation_quaternion = (0.417, 0.241, 0.439, 0.758) cam.data.angle = numpy.radians(34.) else: bpy.ops.object.select_all(action='DESELECT') #obj_sphere.select = True pseudoEdS.select = True bpy.ops.view3d.camera_to_view_selected() cam.data.angle += numpy.radians(10.) bpy.ops.object.select_all(action='DESELECT') ################################################################ ################################################################ # EXPORT VERTEX IMAGE COORDS bpy.ops.object.empty_add(location=V.xyz) vx, vy = lbf.convert_3d_to_2d_coords(V.xyz, normalize=True) #print('(vx, vy) = (%s, %s)' % (vx, vy)) f = open(pthout + 'xy_vertex.dat', 'w') f.write('%s, %s' % (vx, vy)) f.close() ################################################################ ################################################################ # EXPORT PLANES IMAGE COORDS f = open(pthout + 'xy_planes.dat', 'w') scltng = 0.135 for tng, occ in end_planes: x, y = lbf.convert_3d_to_2d_coords(occ, normalize=True) X, Y = lbf.convert_3d_to_2d_coords(occ + scltng * tng, normalize=True) f.write('%s, %s, %s, %s\n' % (x, y, X, Y)) f.close()
## set face materials for i in range(nf): mat = bpy.data.materials["mat"+str(i+1)] mat.diffuse_color = clf[i%len(clf)] mat.diffuse_intensity = 1.0 mat.specular_intensity = 0.1 mat.specular_hardness = 8.0 ## vertices fin = open(pthin + 'debug/verts' + suffin + '.dat','r') fout = open(pthout + 'data/EoB_BRep/verts' + suffout + '.dat','w') for l in fin: v = [float(a) for a in l.split()] if len(v) > 7:# keep only vertices incident to at least 3 faces visible = lbu.is_visible_point(v[0:3], cam, tol=1.e-3, nrs=32, clean=True) x, y = lbf.convert_3d_to_2d_coords(v[0:3]) fout.write(str(x) + ', ' + str(y) + ', ' + str(int(visible)) + '\n') fin.close() fout.close() ## trace edges f = open(pthin + 'debug/edges_xyz' + suffin + '.dat', 'r') ne = int(f.readline()) edgesobj = [] for ie in range(ne): np = int(f.readline()) p = numpy.zeros((np,3)) for ip in range(np): x,y,z = [float(a) for a in f.readline().split()] p[ip,0] = x p[ip,1] = y
"""bpy.ops.mesh.primitive_uv_sphere_add( location=verts_xyz[v], size=1e-2 )""" scene.objects.active = None bpy.ops.object.empty_add(location=verts_xyz[v]) obj = bpy.context.active_object obj.name = 'corner' + str(v + 1) obj.empty_draw_size = 5e-2 print('Writing corners_xyza.dat...') f = open(pthout + 'corners_xya.dat', 'w') iverts.sort() for v in iverts: xyz = verts_xyz[v] u, v = lbf.convert_3d_to_2d_coords(xyz, normalize=True) visible = lbu.is_visible_point(xyz=xyz, cam=cam, tol=tolvis, nrs=nrsvis, clean=True) f.write('%s, %s, %d\n' % (u, v, int(visible))) f.close() print('done.') ################################################# ################################################# # GET SINGULAR CURVE MIDDLE POINTS print('Writing edge_midpoints_xyza.dat...') f = open(pthout + 'edge_midpoints_xya.dat', 'w') for e in iedges:
################################################################ ################################################################ # EDGE VISIBILITY edge.hide = True edge_vis = [] edge_hid = [] npts = len(edge_xyz) vis = numpy.zeros(npts, dtype=bool) for i in range(npts): vis[i] = is_visible(edge_xyz[i]) TOLxy = 1e-3 for i in range(npts): x, y = lbf.convert_3d_to_2d_coords(edge_xyz[i], normalize=True) if vis[i]: edge_vis.append([x, y]) else: edge_hid.append([x, y]) if i < npts - 1: if vis[i] != vis[i + 1]: tlim = [0, 1] xylim = numpy.zeros((2, 2)) vislim = [vis[i], vis[i + 1]] while True: tmid = 0.5 * (tlim[0] + tlim[1]) xyzmid = (1 - tmid) * edge_xyz[i] + tmid * edge_xyz[i + 1] # for j in range(2): xylim[j] = lbf.convert_3d_to_2d_coords(
linestyle.geometry_modifiers["Sampling"].sampling = 0.1 ## lbf.fit_camera_to_meshes([bpy.data.objects['surf_0'].data, bpy.data.objects['surf_1'].data]) cam.data.sensor_width *= 1.01 ## Intersection curve curve = numpy.loadtxt(pthin + 'curve_xyz.dat') f = open(pthout + 'data/simple_intersection/curve_xy.dat', 'w') for p in curve: x, y = lbf.convert_3d_to_2d_coords(p) f.write(str(x) + ' ' + str(y) + '\n') f.close() ipoint = int(numpy.around(0.33*len(curve))) x, y = lbf.convert_3d_to_2d_coords(curve[ipoint]) f = open(pthout + 'data/simple_intersection/point.dat', 'w') f.write(str(x) + ', ' + str(y) + '\n') for isurf in range(2): uv = numpy.loadtxt(pthin + 'curve_uv'+str(isurf+1)+'.dat') a = uv[ipoint] v = uv[ipoint+1] - a v = numpy.array([-v[1], v[0]])/numpy.hypot(v[0], v[1]) f.write(str(a[0]) + ', ' + str(a[1]) + '\n') f.write(str(v[0]) + ', ' + str(v[1]) + '\n')
mat_EdS.emit = 0.8 #1.0 mat_EdS.specular_intensity = 0.5 mat_EdS.specular_hardness = 30 mat_EdS.raytrace_transparency.fresnel = 2.7 mat_EdS.use_shadows = False mat_EdS.use_cast_buffer_shadows = False EdS.data.materials.append(mat_EdS) ################################################ ################################################ # EXPORT SPINE'S COORDINATES IN IMAGE f = open(pth + 'spine_xy.dat', 'w') if REVERSE: g = g[::-1] for xyz in g: x, y = lbf.convert_3d_to_2d_coords(xyz, normalize=True) f.write('%s %s\n' % (x, y)) f.close() ################################################ ################################################ # ADD SPHERE, PLANE AND CHARACTERISTIC CIRCLE u0 = 0.65 #0.5 if False: uc = numpy.linspace(0.3, 0.7, 100) emax = 0 for ui in uc: gi = Bxyz.eval(ui) gix, giy = lbf.convert_3d_to_2d_coords(gi, normalize=True) gui = Bxyz.evald(ui) guui = Bxyz.evald2(ui)