def process(self, mod_command): # OK cs_options = lwsdk.marshall_dynavalues('1 2 4') # OK # cs_options = lwsdk.marshall_dynavalues(' '.join(["1", "2", "4"])) # NG case # cs_options = lwsdk.marshall_dynavalues(["1", "2", "4"]) # NG case # layerList = [] # layerList.append(str(1)) # layerList.append(str(2)) # layerList.append(str(4)) # cs_options = lwsdk.marshall_dynavalues(layerList) # NG case # layerList = [] # layerList.append(1) # layerList.append(2) # layerList.append(4) # cs_options = lwsdk.marshall_dynavalues(layerList) cs_setlayer = mod_command.lookup(mod_command.data, "SETALAYER") result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('3 10') cs_setlayer = mod_command.lookup(mod_command.data, "setblayer") result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) return lwsdk.AFUNC_OK
def process(self, mod_command): cs_options = lwsdk.marshall_dynavalues( (self._radius, self._nsides, self._nsegments, self._center)) cs_makeball = mod_command.lookup(mod_command.data, "MAKEBALL") result, dyna_value = mod_command.execute(mod_command.data, cs_makeball, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('2') cs_setlayer = mod_command.lookup(mod_command.data, "SETLAYER") result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(([-0.5, -0.5, -0.5], [0.5, 0.5, 0.5], None)) cs_makebox = mod_command.lookup(mod_command.data, "MAKEBOX") result, dyna_value = mod_command.execute(mod_command.data, cs_makebox, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('1') result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('2') cs_setblayer = mod_command.lookup(mod_command.data, "SETBLAYER") result, dyna_value = mod_command.execute(mod_command.data, cs_setblayer, cs_options, lwsdk.OPSEL_USER) return lwsdk.AFUNC_OK
def select_layers(self, mod, data): obj_funcs = lwsdk.LWObjectFuncs() state_query = lwsdk.LWStateQueryFuncs() obj_name = state_query.object() layer_list = state_query.layerList(lwsdk.OPLYR_NONEMPTY, obj_name) # there is no mesh ! if layer_list == '': message_funcs = lwsdk.LWMessageFuncs() message_funcs.error('No mesh data', '') return lwsdk.AFUNC_OK current_obj = obj_funcs.focusObject() layers = layer_list.split(' ') foreground_layers = [] background_layers = [] for layer in layers: layer_int = int(layer) - 1 # layer name is (unnamed), display None layer_name = obj_funcs.layerName(current_obj, layer_int) if layer_name == None: layer_name = '' if data.select_contains == (0 if layer_name.find(data.string) < 0 else 1): foreground_layers.append(layer) else: background_layers.append(layer) if len(foreground_layers) == 0: raise NoForegroundLayer() if len(foreground_layers) > 0: cs_options = lwsdk.marshall_dynavalues(' '.join(foreground_layers)) cs_setlayer = mod.lookup(mod.data, "SETALAYER") mod.execute(mod.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) if len(background_layers) > 0 and data.select_others: cs_options = lwsdk.marshall_dynavalues(' '.join(background_layers)) cs_setlayer = mod.lookup(mod.data, "setblayer") mod.execute(mod.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER)
def process(self, mod_command): cs_options = lwsdk.marshall_dynavalues((self._radius, self._nsides, self._nsegments, self._center)) cs_makeball = mod_command.lookup(mod_command.data, "MAKEBALL") result, dyna_value = mod_command.execute(mod_command.data, cs_makeball, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('2') cs_setlayer = mod_command.lookup(mod_command.data, "SETLAYER") result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options,lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(([-0.5, -0.5, -0.5], [0.5, 0.5, 0.5], None)) cs_makebox = mod_command.lookup(mod_command.data, "MAKEBOX") result, dyna_value = mod_command.execute(mod_command.data, cs_makebox, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('1') result, dyna_value = mod_command.execute(mod_command.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('2') cs_setblayer = mod_command.lookup(mod_command.data, "SETBLAYER") result, dyna_value = mod_command.execute(mod_command.data, cs_setblayer, cs_options, lwsdk.OPSEL_USER) return lwsdk.AFUNC_OK
def process(self, mod_command): #cs_options = lwsdk.marshall_dynavalues('1') #cs_export_obj = mod_command.lookup(mod_command.data, "ExportOBJ") #result, dyna_value = mod_command.execute(mod_command.data, cs_export_obj, cs_options, lwsdk.OPSEL_USER) print "ExportThreeJS.process()" return lwsdk.AFUNC_OK #mod_command("SaveObject " + "E:/3Dstuff/Packaged Scenes/FirstAlphaConstruct10-19-12/Scenes/fivechairs.lwo") cs_dict = self.get_commands(mod_command) cs_options = lwsdk.marshall_dynavalues(("filename.obj",)) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["SaveObject"], cs_options, lwsdk.OPSEL_USER) print "ExportThreeJS.process() - end" return lwsdk.AFUNC_OK
def process(self, mod_command): #cs_options = lwsdk.marshall_dynavalues('1') #cs_export_obj = mod_command.lookup(mod_command.data, "ExportOBJ") #result, dyna_value = mod_command.execute(mod_command.data, cs_export_obj, cs_options, lwsdk.OPSEL_USER) print "ExportThreeJS.process()" return lwsdk.AFUNC_OK #mod_command("SaveObject " + "E:/3Dstuff/Packaged Scenes/FirstAlphaConstruct10-19-12/Scenes/fivechairs.lwo") cs_dict = self.get_commands(mod_command) cs_options = lwsdk.marshall_dynavalues(("filename.obj", )) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["SaveObject"], cs_options, lwsdk.OPSEL_USER) print "ExportThreeJS.process() - end" return lwsdk.AFUNC_OK
def process(self, mod_command): #deselect any Morph Targets command = mod_command.lookup(mod_command.data, "SELECTVMAP") cs_options = lwsdk.marshall_dynavalues(("MORF")) result = mod_command.execute(mod_command.data, command, cs_options, lwsdk.OPSEL_USER) file = tempfile.gettempdir() + os.sep + "ODVertexData.txt" #find existing Vmaps loaded_weight = []; loaded_uv = []; loaded_morph = [] for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_WGHT )): loaded_weight.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_WGHT, u)) for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_TXUV )): loaded_uv.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_TXUV, u)) for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_MORF )): loaded_morph.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_MORF, u)) mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPLYR_FG) if not mesh_edit_op: print >>sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK try: # Getting Point ID of selected Point points = [] edit_op_result = mesh_edit_op.fastPointScan(mesh_edit_op.state, self.fast_point_scan, (points,), lwsdk.OPLYR_FG, 0) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK point_count = len(points) edit_op_result = lwsdk.EDERR_NONE polys = [] edit_op_result = mesh_edit_op.fastPolyScan(mesh_edit_op.state, self.fast_poly_scan, (polys,), lwsdk.OPLYR_FG, 0) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK poly_count = len(polys) edit_op_result = lwsdk.EDERR_NONE #if there's no points, then we dont need to do anything if point_count == 0: lwsdk.LWMessageFuncs().info("No Points.", "") return lwsdk.AFUNC_OK f = open(file, "w") f.write ("VERTICES:" + str(point_count) + "\n") positions = [] uvMaps = [] weightMaps = [] morphMaps = [] # Filling Position Array for Selected Point for point in points: pos = mesh_edit_op.pointPos(mesh_edit_op.state, point) f.write(str(pos[0]) + " " + str(pos[1]) + " " + str(pos[2]*-1) + "\n") #write polygons-point connection for poly reconstruction f.write("POLYGONS:" + str(len(polys)) + "\n") x =0 for poly in polys: surf = mesh_edit_op.polySurface(mesh_edit_op.state,poly) ppoint = "" for point in reversed(mesh_edit_op.polyPoints(mesh_edit_op.state,poly)): ppoint += "," + str(self.pointidxmap[str(point)]) polytype = "FACE" subD = mesh_edit_op.polyType(mesh_edit_op.state, poly)# & lwsdk.LWPOLTYPE_SUBD if subD == lwsdk.LWPOLTYPE_SUBD: polytype = "CCSS" elif subD == lwsdk.LWPOLTYPE_PTCH: polytype = "SUBD" f.write(ppoint[1:] + ";;" + surf + ";;" + polytype + "\n") #grab all weights for weight in loaded_weight: mesh_edit_op.vMapSelect(mesh_edit_op.state, weight, lwsdk.LWVMAP_WGHT, 1) f.write("WEIGHT:" + weight + "\n") for point in points: if (mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) != None: f.write(str(mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) + "\n") else: f.write("0.0\n") #grab all UVs for uvs in loaded_uv: cont = [] discont = [] c = 0 #selecting uv map mesh_edit_op.vMapSelect(mesh_edit_op.state, uvs, lwsdk.LWVMAP_TXUV, 2) #check whether we are dealing with continuous or discontinous UVs, we have to look at points per poly for this for poly in polys: for point in mesh_edit_op.polyPoints(mesh_edit_op.state,poly): #vpget gets uv coordinates based on point in poly, if that has a value, the uv is discontinuous.. if it doesnt, its continuous. pInfo = mesh_edit_op.pointVPGet(mesh_edit_op.state,point, poly)[1] if pInfo != None: #check if discontinous curPos = [pInfo[0], pInfo[1]] #print "oh:", self.polyidxmap[str(poly)] discont.append([curPos, str(self.polyidxmap[str(poly)]), str(self.pointidxmap[str(point)])]) #discont.append([curPos, str(1), str(self.pointidxmap[str(point)])]) c+= 1 else: #otherwise, the uv coordinate is continuous if mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1] != None: curPos = [mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1][0], mesh_edit_op.pointVGet(mesh_edit_op.state, point)[1][1]] cont.append([curPos, str(self.pointidxmap[str(point)])]) c+= 1 f.write("UV:" + uvs + ":"+str(c) + "\n") for uvpos in discont: f.write(str(uvpos[0][0]) + " " + str(uvpos[0][1]) + ":PLY:" + str(uvpos[1]) + ":PNT:" + str(uvpos[2]) + "\n") for uvpos in cont: f.write(str(uvpos[0][0]) + " " + str(uvpos[0][1]) + ":PNT:" + str(uvpos[1]) + "\n") #grab all Morphs for morph in loaded_morph: mesh_edit_op.vMapSelect(mesh_edit_op.state, morph, lwsdk.LWVMAP_MORF, 3) f.write("MORPH:" + morph + "\n") for point in points: if (mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) != None: ms = mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1] f.write(str(ms[0]) + " " + str(ms[1]) + " " + str(ms[2]*-1) + "\n") else: f.write("0 0 0\n") except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) f.close() return lwsdk.AFUNC_OK
def set_layers(self, mod, cs, layers): cs_options = lwsdk.marshall_dynavalues(layers) cs_setlayer = mod.lookup(mod.data, cs) mod.execute(mod.data, cs_setlayer, cs_options, lwsdk.OPSEL_USER)
def process(self, mod_command): ui = lwsdk.LWPanels() panel = ui.create('Final Fantasy 7:Remake Import') controlWidth = 64 c1 = panel.load_ctl('Select File', controlWidth) c1.set_str(self._filepath) if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0: ui.destroy(panel) return lwsdk.AFUNC_OK self.filepath = c1.get_str() edit_op_result = lwsdk.EDERR_NONE cs_dict = self.get_commands(mod_command) progress_count = 8 cs_test0 = mod_command.lookup(mod_command.data, "cmdseq") t1 = time.time() files = path_wrangler(self.filepath) files.get_files() #Dump(files) md = open(files.data['uexp'], 'rb') ua = open(files.data['uasset'], 'rb') meshName = files.data['meshName'] submesh_name = files.data['submesh_name'] arm = False weightData = {} Weight_array = [] vertexArray = [] NA = [] normal_array = [] UVs0 = [] UVs1 = [] UVs2 = [] UVs3 = [] UVs4 = [] faces = [] names = readUasset(ua) ua.close() mod_command.undoGroupBegin() pattern0 = re.compile( b'\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00........') for x in xrange(20000): s1 = struct.unpack("18s", md.read(18))[0] if pattern0.match(s1): c0 = struct.unpack("<L", md.read(4))[0] c1 = struct.unpack("<L", md.read(4))[0] c2 = struct.unpack("<L", md.read(4))[0] c3 = struct.unpack("<L", md.read(4))[0] c4 = struct.unpack("<L", md.read(4))[0] if (c0 and c1 and c2 and c3 and c4 > 1000000000): break else: md.seek(-20, 1) md.seek(-17, 1) materialCount = struct.unpack("<L", md.read(4))[0] progress_count += materialCount materials = {} for m in xrange(materialCount): materials[m] = {} materials[m]['val0'] = struct.unpack("<l", md.read(4))[0] stringIndex = struct.unpack("<L", md.read(4))[0] unk0 = struct.unpack("<L", md.read(4))[0] unk1 = struct.unpack("<L", md.read(4))[0] unk2 = struct.unpack("<L", md.read(4))[0] unk3 = struct.unpack("<f", md.read(4))[0] unk4 = struct.unpack("<f", md.read(4))[0] unk5 = struct.unpack("<L", md.read(4))[0] unk6 = struct.unpack("<L", md.read(4))[0] materials[m]['name'] = names[stringIndex] boneCount = struct.unpack("<L", md.read(4))[0] joint_data = {} joint_names = [] for i in xrange(boneCount): string_index = struct.unpack("<L", md.read(4))[0] jName = names[string_index] unk = struct.unpack("<L", md.read(4))[0] parent = struct.unpack("<l", md.read(4))[0] joint_data[i] = {"name": jName, "parent": parent} joint_names.append(jName) boneCount2 = struct.unpack("<L", md.read(4))[0] if not moninit(progress_count, "Importing", title='Progress'): raise Exception('Hell!') layerindex = 1 for i in range(boneCount): m1 = struct.unpack("<10f", md.read(40)) monstep() cs_options = lwsdk.marshall_dynavalues(str(layerindex)) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(meshName) result = mod_command.execute(mod_command.data, cs_dict["SETLAYERNAME"], cs_options, lwsdk.OPSEL_USER) layerindex += 1 boneCount3 = struct.unpack("<L", md.read(4))[0] md.seek(boneCount3 * 12, 1) vertexGroups = {} unk0 = struct.unpack("<L", md.read(4))[0] unk1 = struct.unpack("B", md.read(1))[0] unk2 = struct.unpack("B", md.read(1))[0] groupCount = struct.unpack("<L", md.read(4))[0] for m in xrange(groupCount): z1 = struct.unpack("<H", md.read(2))[0] ID = struct.unpack("<H", md.read(2))[0] md.seek(24, 1) vertexGroups[ID] = {'range': 0, 'bones': []} # pragma region bone palette start = struct.unpack("<L", md.read(4))[0] count = struct.unpack("<L", md.read(4))[0] vertexGroups[ID]['bones_np'] = np.zeros((boneCount2, ), dtype=int) bone_names = [] for bn in xrange(count): bid = struct.unpack("<H", md.read(2))[0] vertexGroups[ID]['bones_np'][bn] = bid vertexGroups[ID]['bones'].append(bid) bone_names.append(joint_data[bid]["name"]) # pragma endregion bone palette size = struct.unpack("<L", md.read(4))[0] stop = start + size vertexGroups[ID]['range'] = np.arange(start, stop) vertexGroups[ID]["start"] = start vertexGroups[ID]["stop"] = stop vertexGroups[ID]["size"] = size vertexGroups[ID]["names"] = bone_names md.seek(34, 1) FFx4 = readHexString(md, 4) flag = struct.unpack("<L", md.read(4))[0] if flag: # extra data for this group count = struct.unpack("<L", md.read(4))[0] md.seek(count * 16, 1) else: null = struct.unpack("<L", md.read(4))[0] unk = struct.unpack("B", md.read(1))[0] checkHere = md.tell() stride = struct.unpack("<L", md.read(4))[0] fCount = struct.unpack("<L", md.read(4))[0] faceByteCount = fCount * stride fi = np.fromfile(md, dtype='B', count=faceByteCount) if stride == 4: fi_0 = fi.view(dtype='<L').reshape(fCount // 3, 3) elif stride == 2: fi_0 = fi.view(dtype='<H').reshape(fCount // 3, 3) fi_0[:, [0, 1]] = fi_0[:, [1, 0]] faces = fi_0.tolist() unkCount = struct.unpack("<L", md.read(4))[0] md.seek(unkCount * 2, 1) unk = struct.unpack("<L", md.read(4))[0] vertexCount = struct.unpack("<L", md.read(4))[0] boneCount = struct.unpack("<L", md.read(4))[0] md.seek(boneCount * 2, 1) null0 = struct.unpack("<L", md.read(4))[0] null1 = struct.unpack("<L", md.read(4))[0] uv_count = struct.unpack("<L", md.read(4))[0] unk0 = struct.unpack("<H", md.read(2))[0] uv_count2 = struct.unpack("<L", md.read(4))[0] null2 = struct.unpack("<L", md.read(4))[0] unk1 = struct.unpack("<f", md.read(4))[0] unk2 = struct.unpack("<f", md.read(4))[0] unk3 = struct.unpack("<f", md.read(4))[0] null3 = struct.unpack("<L", md.read(4))[0] null4 = struct.unpack("<L", md.read(4))[0] null5 = struct.unpack("<L", md.read(4))[0] vStride = struct.unpack("<L", md.read(4))[0] vCount = struct.unpack("<L", md.read(4))[0] byteCount = vCount * vStride vi = np.fromfile(md, dtype='B', count=byteCount).reshape( (vCount, vStride)) pos = vi[:, 8:20].ravel().view(dtype='<f').reshape((vCount, 3)) pos[:, [0, 2]] = pos[:, [2, 0]] pos[:, [0, 1]] = pos[:, [1, 0]] VA = pos.tolist() if uv_count > 0: uvData_0 = vi[:, 20:24].ravel().view(dtype='<f2').reshape( (vCount, 2)) uvData_0[:, 1:2] *= -1 uvData_0[:, 1:2] += 1 UVs0 = uvData_0.tolist() if uv_count > 1: uvData_1 = vi[:, 24:28].ravel().view(dtype='<f2').reshape( (vCount, 2)) uvData_1[:, 1:2] *= -1 uvData_1[:, 1:2] += 1 UVs1 = uvData_1.tolist() if uv_count > 2: uvData_2 = vi[:, 28:32].ravel().view(dtype='<f2').reshape( (vCount, 2)) uvData_2[:, 1:2] *= -1 uvData_2[:, 1:2] += 1 UVs2 = uvData_2.tolist() if uv_count > 3: uvData_3 = vi[:, 32:36].ravel().view(dtype='<f2').reshape( (vCount, 2)) uvData_3[:, 1:2] *= -1 uvData_3[:, 1:2] += 1 UVs3 = uvData_3.tolist() if uv_count > 4: uvData_4 = vi[:, 36:40].ravel().view(dtype='<f2').reshape( (vCount, 2)) uvData_4[:, 1:2] *= -1 uvData_4[:, 1:2] += 1 UVs4 = uvData_4.tolist() monstep() mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER) #points map(lambda x: v_f(x, vertexArray, mesh_edit_op), VA) monstep() #faces material_IDs = np.empty([1, fCount], dtype='U32').reshape(fCount // 3, 3) for g in vertexGroups: h = np.in1d(fi_0, vertexGroups[g]['range']).reshape(fi_0.shape) m = np.all(h, axis=1) material_IDs[m] = materials[g]['name'] monstep() map(lambda x, y: f_f(x, vertexArray, mesh_edit_op, y), faces, material_IDs) monstep() #UVs val = 0 if uv_count > 0: map(lambda x, y: uv_f(x, y, val, mesh_edit_op, meshName), vertexArray, UVs0) val += 1 if uv_count > 1: map(lambda x, y: uv_f(x, y, val, mesh_edit_op, meshName), vertexArray, UVs1) val += 1 if uv_count > 2: map(lambda x, y: uv_f(x, y, val, mesh_edit_op, meshName), vertexArray, UVs2) val += 1 if uv_count > 3: map(lambda x, y: uv_f(x, y, val, mesh_edit_op, meshName), vertexArray, UVs3) val += 1 if uv_count > 4: map(lambda x, y: uv_f(x, y, val, mesh_edit_op, meshName), vertexArray, UVs4) val += 1 monstep() unkS = struct.unpack("<H", md.read(2))[0] extraBoneWeights = struct.unpack("<L", md.read(4))[0] wCount = struct.unpack("<L", md.read(4))[0] stride = struct.unpack("<L", md.read(4))[0] wCount2 = struct.unpack("<L", md.read(4))[0] subStride = stride // 2 for q in xrange(len(vertexGroups)): boneNames = vertexGroups[q]["names"] start = vertexGroups[q]["start"] stop = vertexGroups[q]["stop"] for j in xrange(start, stop): b0 = struct.unpack("B", md.read(1))[0] b1 = struct.unpack("B", md.read(1))[0] b2 = struct.unpack("B", md.read(1))[0] b3 = struct.unpack("B", md.read(1))[0] b4 = struct.unpack("B", md.read(1))[0] b5 = struct.unpack("B", md.read(1))[0] b6 = struct.unpack("B", md.read(1))[0] b7 = struct.unpack("B", md.read(1))[0] bn0 = boneNames[b0] bn1 = boneNames[b1] bn2 = boneNames[b2] bn3 = boneNames[b3] bn4 = boneNames[b4] bn5 = boneNames[b5] bn6 = boneNames[b6] bn7 = boneNames[b7] w0 = struct.unpack("B", md.read(1))[0] / 255.0 w1 = struct.unpack("B", md.read(1))[0] / 255.0 w2 = struct.unpack("B", md.read(1))[0] / 255.0 w3 = struct.unpack("B", md.read(1))[0] / 255.0 w4 = struct.unpack("B", md.read(1))[0] / 255.0 w5 = struct.unpack("B", md.read(1))[0] / 255.0 w6 = struct.unpack("B", md.read(1))[0] / 255.0 w7 = struct.unpack("B", md.read(1))[0] / 255.0 mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn0, [w0]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn1, [w1]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn2, [w2]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn3, [w3]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn4, [w4]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn5, [w5]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn6, [w6]) mesh_edit_op.pntVMap(mesh_edit_op.state, vertexArray[j], lwsdk.LWVMAP_WGHT, bn7, [w7]) monstep() mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) monend() mod_command.undoGroupEnd() elapsed = time.time() - t1 print "Time: " + str(elapsed) md.close() return lwsdk.AFUNC_OK
def process(self, mod_command): def polytree(polys, points): #here we build a tree on which polys belong to a point. #n will store the polyIDs assignement per point #nfullNormals will add the poly normals together for that point from the belonging polys n = [] nfullNormals = [] #create empty arrays for p in points: n.append([]) nfullNormals.append([]) #go through each poly checking with points belong to it. count = 0 for poly in polys: pts = mesh_edit_op.polyPoints(mesh_edit_op.state,poly) for p in pts: n[self.pointidxmap[str(p)]].append(count) nfullNormals[self.pointidxmap[str(p)]] = lwsdk.Vector(nfullNormals[self.pointidxmap[str(p)]]) + lwsdk.Vector(mesh_edit_op.polyNormal(mesh_edit_op.state,polys[count])[1]) count += 1 return n, nfullNormals #deselect any Morph Targets command = mod_command.lookup(mod_command.data, "SELECTVMAP") cs_options = lwsdk.marshall_dynavalues(("MORF")) result = mod_command.execute(mod_command.data, command, cs_options, lwsdk.OPSEL_USER) #The temporary filename where it resides, typically this is the systems temp folder as it will resolve to the same on every system file = tempfile.gettempdir() + os.sep + "ODVertexData.txt" #find existing Vmaps loaded_weight = []; loaded_uv = []; loaded_morph = [] for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_WGHT )): loaded_weight.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_WGHT, u)) for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_TXUV )): loaded_uv.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_TXUV, u)) for u in range(0, lwsdk.LWObjectFuncs().numVMaps( lwsdk.LWVMAP_MORF )): loaded_morph.append(lwsdk.LWObjectFuncs().vmapName(lwsdk.LWVMAP_MORF, u)) #start mesh edit operations mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPLYR_FG) if not mesh_edit_op: print >>sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK try: # Query all points points = [] edit_op_result = mesh_edit_op.fastPointScan(mesh_edit_op.state, self.fast_point_scan, (points,), lwsdk.OPLYR_FG, 0) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK point_count = len(points) edit_op_result = lwsdk.EDERR_NONE # Query all polygons polys = [] edit_op_result = mesh_edit_op.fastPolyScan(mesh_edit_op.state, self.fast_poly_scan, (polys,), lwsdk.OPLYR_FG, 0) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK poly_count = len(polys) edit_op_result = lwsdk.EDERR_NONE #if there's no points, then we dont need to do anything if point_count == 0: lwsdk.LWMessageFuncs().info("No Points.", "") return lwsdk.AFUNC_OK #initializing some variables we'll need positions = [] uvMaps = [] weightMaps = [] morphMaps = [] vertexNormals = [] #open the file and start writing points header and point positions f = open(file, "w") f.write ("VERTICES:" + str(point_count) + "\n") # Writing point positions for each point for point in points: pos = mesh_edit_op.pointPos(mesh_edit_op.state, point) f.write(str(pos[0]) + " " + str(pos[1]) + " " + str(pos[2]*-1) + "\n") #check to see if any surfaces have smoothing on: smoothing = 0 surfIDs = lwsdk.LWSurfaceFuncs().byObject(lwsdk.LWStateQueryFuncs().object()) for surf in surfIDs: smooth = lwsdk.LWSurfaceFuncs().getFlt(surf, lwsdk.SURF_SMAN) if smooth > 0: smoothing = 1 break #Query which polygons belong to a point and build an array for easy lookup (only needed if there's any smoothing) if smoothing > 0: ptree = polytree(polys, points) #write Polygon Header f.write("POLYGONS:" + str(len(polys)) + "\n") x =0 for poly in polys: #check if the surface of a poly has smoothing enabled or not so that we either export smoothed or nonsmoothed normals surf = mesh_edit_op.polySurface(mesh_edit_op.state,poly) surfID = lwsdk.LWSurfaceFuncs().byName(surf, lwsdk.LWStateQueryFuncs().object()) smoothing = lwsdk.LWSurfaceFuncs().getFlt(surfID[0], lwsdk.SURF_SMAN) #Write poly construction with surface name and type, as well as storing the normals ppoint = "" for point in reversed(mesh_edit_op.polyPoints(mesh_edit_op.state,poly)): ppoint += "," + str(self.pointidxmap[str(point)]) if smoothing > 0: vertexNormals.append(lwsdk.Vector().normalize(ptree[1][self.pointidxmap[str(point)]]/float(len(ptree[0])))) else: vertexNormals.append(mesh_edit_op.polyNormal(mesh_edit_op.state,poly)[1]) polytype = "FACE" subD = mesh_edit_op.polyType(mesh_edit_op.state, poly)# & lwsdk.LWPOLTYPE_SUBD if subD == lwsdk.LWPOLTYPE_SUBD: polytype = "CCSS" elif subD == lwsdk.LWPOLTYPE_PTCH: polytype = "SUBD" f.write(ppoint[1:] + ";;" + surf + ";;" + polytype + "\n") #grab all weights for weight in loaded_weight: mesh_edit_op.vMapSelect(mesh_edit_op.state, weight, lwsdk.LWVMAP_WGHT, 1) f.write("WEIGHT:" + weight + "\n") for point in points: if (mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) != None: f.write(str(mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) + "\n") else: f.write("0.0\n") #grab all UVs for uvs in loaded_uv: cont = [] discont = [] c = 0 #selecting uv map mesh_edit_op.vMapSelect(mesh_edit_op.state, uvs, lwsdk.LWVMAP_TXUV, 2) #check whether we are dealing with continuous or discontinous UVs, we have to look at points per poly for this for poly in polys: for point in mesh_edit_op.polyPoints(mesh_edit_op.state,poly): #vpget gets uv coordinates based on point in poly, if that has a value, the uv is discontinuous.. if it doesnt, its continuous. pInfo = mesh_edit_op.pointVPGet(mesh_edit_op.state,point, poly)[1] if pInfo != None: #check if discontinous curPos = [pInfo[0], pInfo[1]] #print "oh:", self.polyidxmap[str(poly)] discont.append([curPos, str(self.polyidxmap[str(poly)]), str(self.pointidxmap[str(point)])]) #discont.append([curPos, str(1), str(self.pointidxmap[str(point)])]) c+= 1 else: #otherwise, the uv coordinate is continuous if mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1] != None: curPos = [mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1][0], mesh_edit_op.pointVGet(mesh_edit_op.state, point)[1][1]] cont.append([curPos, str(self.pointidxmap[str(point)])]) c+= 1 #Write UVs f.write("UV:" + uvs + ":"+str(c) + "\n") for uvpos in discont: f.write(str(uvpos[0][0]) + " " + str(uvpos[0][1]) + ":PLY:" + str(uvpos[1]) + ":PNT:" + str(uvpos[2]) + "\n") for uvpos in cont: f.write(str(uvpos[0][0]) + " " + str(uvpos[0][1]) + ":PNT:" + str(uvpos[1]) + "\n") #grab all Morphs for morph in loaded_morph: mesh_edit_op.vMapSelect(mesh_edit_op.state, morph, lwsdk.LWVMAP_MORF, 3) f.write("MORPH:" + morph + "\n") for point in points: if (mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1]) != None: ms = mesh_edit_op.pointVGet(mesh_edit_op.state,point)[1] f.write(str(ms[0]) + " " + str(ms[1]) + " " + str(ms[2]*-1) + "\n") else: f.write("0 0 0\n") #Write Vertex Normals f.write("VERTEXNORMALS:" + str(len(vertexNormals)) + "\n") for normal in vertexNormals: f.write(str(normal[0]) + " " + str(normal[1]) + " " + str(normal[2]*-1) + "\n") except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) f.close() return lwsdk.AFUNC_OK
def process(self, mod_command): ui = lwsdk.LWPanels() panel = ui.create('Gears') c1 = panel.hchoice_ctl('Axis', ['X', 'Y', 'Z']) c2 = panel.int_ctl('Number of Teeth') c3 = panel.dist_ctl('Inner Radius') c4 = panel.dist_ctl('Outer Radius') c5 = panel.dist_ctl('Thickness') c6 = panel.hchoice_ctl('Gear Type', ['Angular', 'Smooth']) c7 = panel.fvec_ctl('Center') panel.align_controls_vertical([c1, c2, c3, c4, c5, c6, c7]) panel.size_to_layout(5, 5) c1.set_int(self._axis) c2.set_int(self._teeth) c3.set_float(self._rad_inner) c4.set_float(self._rad_outer) c5.set_float(self._thickness) c6.set_int(self._geartype) c7.setv_fvec(self._center) if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0: ui.destroy(panel) return lwsdk.AFUNC_OK self._axis = c1.get_int() self._teeth = c2.get_int() self._rad_inner = c3.get_float() self._rad_outer = c4.get_float() self._thickness = c5.get_float() self._geartype = c6.get_int() self._center = c7.getv_fvec() ui.destroy(panel) cs_dict = self.get_commands(mod_command) cx = self._center[0] cy = self._center[1] cz = self._center[2] - (self._thickness / 2) t_ang = 360 / self._teeth / 57.2957794 # figure out the layers we need to use and those that are # available for our temporary work fg_layers = lwsdk.LWStateQueryFuncs().layerList(lwsdk.OPLYR_FG, None) fg_layers_list = fg_layers.split() empty_layers = lwsdk.LWStateQueryFuncs().layerList( lwsdk.OPLYR_EMPTY, None) empty_layers_list = empty_layers.split() cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) x = 0 empty_layer = empty_layers_list[x] while x < len(empty_layers_list) and (empty_layer in fg_layers_list): x += 1 empty_layer = empty_layers_list[x] # only punch a hole if we can get an empty layer to work in if x == len(empty_layers_list): print >> sys.stderr, "Cannot locate an empty background layer!" return lwsdk.AFUNC_OK mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER) if not mesh_edit_op: print >> sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK monitor_funcs = lwsdk.DynaMonitorFuncs() dyna_monitor = monitor_funcs.create("Gears", "Generating gear...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, self._teeth) edit_op_result = lwsdk.EDERR_NONE ptID = [] cancelled = False # catch exceptions to make sure Modeler ends up on a sane state try: tooth = 0 for tooth in range(self._teeth): a1 = t_ang * tooth a2 = a1 + (t_ang * 3 / 6) a3 = a1 + (t_ang * 4 / 6) a4 = a1 + (t_ang * 5 / 6) pt = [(self._rad_inner * math.sin(a1) + cx), (self._rad_inner * math.cos(a1) + cy), cz] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [(self._rad_inner * math.sin(a2) + cx), (self._rad_inner * math.cos(a2) + cy), cz] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [(self._rad_outer * math.sin(a3) + cx), (self._rad_outer * math.cos(a3) + cy), cz] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [(self._rad_outer * math.sin(a4) + cx), (self._rad_outer * math.cos(a4) + cy), cz] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) if dyna_monitor: result = dyna_monitor.step(dyna_monitor.data, 1) if result: cancelled = True break if cancelled: edit_op_result = lwsdk.EDERR_USERABORT else: if self._geartype == gears.ANGULAR: mesh_edit_op.addPoly(mesh_edit_op.state, lwsdk.LWPOLTYPE_FACE, None, "Gear", ptID) else: # Smooth ptID.append(ptID[0]) # close the loop mesh_edit_op.addCurve(mesh_edit_op.state, None, ptID, 0) except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) if cancelled: return lwsdk.AFUNC_OK if self._geartype == gears.SMOOTH: result = mod_command.execute(mod_command.data, cs_dict["FREEZECURVES"], None, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(('Z', self._thickness)) result = mod_command.execute(mod_command.data, cs_dict["EXTRUDE"], cs_options, lwsdk.OPSEL_USER) # make hole with a diameter 25% of the gear's radius cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(( [ self._rad_outer * 0.25, # radius self._rad_outer * 0.25, self._rad_outer * 0.25 ], -0.5, # top self._thickness + 1, # bottom 'Z', # axis 32, # number of sides 1, # number of segments [cx, cy, cz] # center )) result = mod_command.execute(mod_command.data, cs_dict["MAKEDISC"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETBLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('SUBTRACT') result = mod_command.execute(mod_command.data, cs_dict["BOOLEAN"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["DELETE"], None, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["MERGEPOINTS"], None, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["ALIGNPOLS"], None, lwsdk.OPSEL_USER) if self._geartype == gears.SMOOTH: result = mod_command.execute(mod_command.data, cs_dict["FLIP"], None, lwsdk.OPSEL_USER) if self._axis != gears.Z: angle = 90.0 if self._axis == gears.X: cs_options = lwsdk.marshall_dynavalues((angle, 'Y')) elif self._axis == gears.Y: cs_options = lwsdk.marshall_dynavalues((angle, 'X')) result = mod_command.execute(mod_command.data, cs_dict["ROTATE"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) return lwsdk.AFUNC_OK
def process(self, mod_command): ui = lwsdk.LWPanels() panel = ui.create('Bubbles') c1 = panel.hchoice_ctl('Sphere Type', ['Globe', 'Tesselated']) c2 = panel.int_ctl('Tesselation Level') c3 = panel.dist_ctl('Maximum Radius') c4 = panel.dist_ctl('Minimum Radius') c5 = panel.int_ctl('Globe Sides') c6 = panel.int_ctl('Globe Segments') c7 = panel.str_ctl('Surface', 50) panel.align_controls_vertical([c1, c2, c3, c4, c5, c6, c7]) panel.size_to_layout(5, 5) c1.set_int(self._sphereType) c2.set_int(self._tessLevel) c3.set_float(self._maxRadius) c4.set_float(self._minRadius) c5.set_int(self._globeSides) c6.set_int(self._globeSegments) c7.set_str(self._surface) if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0: ui.destroy(panel) return lwsdk.AFUNC_OK self._sphereType = c1.get_int() self._tessLevel = c2.get_int() self._maxRadius = c3.get_float() self._minRadius = c4.get_float() self._globeSides = c5.get_int() self._globeSegments = c6.get_int() self._surface = c7.get_str() ui.destroy(panel) cs_dict = self.get_commands(mod_command) random.seed() cs_options = lwsdk.marshall_dynavalues((self._surface,)) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["SURFACE"], cs_options, lwsdk.OPSEL_USER) mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER) if not mesh_edit_op: print >>sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK # gather up the point ids points = [] # NOTE: we will be passing in a sequence (list or tuple) as the argument to the callback. # internally, Python expects a sequence as an argument to the function, so it MUST be encased # in another sequence, or it will be mistaken for a sequence containing the arguments # (instead of an argument itself). edit_op_result = mesh_edit_op.fastPointScan(mesh_edit_op.state, self.fast_point_scan, (points,), lwsdk.OPLYR_FG, 1) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK point_count = len(points) # print some info to the PCore console print '%d points found for lwsdk.OPLYR_FG' % point_count edit_op_result = lwsdk.EDERR_NONE monitor_funcs = lwsdk.DynaMonitorFuncs() dyna_monitor = monitor_funcs.create("Bubbles", "Removing points...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, point_count) positions = [] # catch exceptions to make sure Modeler ends up on a sane state try: for point in points: print type(point) positions.append(lwsdk.Vector(mesh_edit_op.pointPos(mesh_edit_op.state, point))) mesh_edit_op.remPoint(mesh_edit_op.state, point) if dyna_monitor: if dyna_monitor.step(dyna_monitor.data, 1): edit_op_result = lwsdk.EDERR_USERABORT break except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) dyna_monitor = monitor_funcs.create("Bubbles", "Creating bubbles...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, point_count) for position in positions: percent = random.random() radius = lwsdk.Vector(self._minRadius + ((self._maxRadius - self._minRadius) * percent)) if self._sphereType == bubbles.GLOBE: cs_options = lwsdk.marshall_dynavalues((radius, self._globeSides, self._globeSegments, position)) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["MAKEBALL"], cs_options, lwsdk.OPSEL_USER) else: cs_options = lwsdk.marshall_dynavalues((radius, self._tessLevel, position)) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["MAKETESBALL"], cs_options, lwsdk.OPSEL_USER) if dyna_monitor: if dyna_monitor.step(dyna_monitor.data, 1): edit_op_result = lwsdk.EDERR_USERABORT break if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) return lwsdk.AFUNC_OK
def process(self, mod_command): ui = lwsdk.LWPanels() panel = ui.create('Gears') c1 = panel.hchoice_ctl('Axis', ['X', 'Y', 'Z']) c2 = panel.int_ctl('Number of Teeth') c3 = panel.dist_ctl('Inner Radius') c4 = panel.dist_ctl('Outer Radius') c5 = panel.dist_ctl('Thickness') c6 = panel.hchoice_ctl('Gear Type', ['Angular','Smooth']) c7 = panel.fvec_ctl('Center') panel.align_controls_vertical([c1, c2, c3, c4, c5, c6, c7]) panel.size_to_layout(5, 5) c1.set_int(self._axis) c2.set_int(self._teeth) c3.set_float(self._rad_inner) c4.set_float(self._rad_outer) c5.set_float(self._thickness) c6.set_int(self._geartype) c7.setv_fvec(self._center) if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0: ui.destroy(panel) return lwsdk.AFUNC_OK self._axis = c1.get_int() self._teeth = c2.get_int() self._rad_inner = c3.get_float() self._rad_outer = c4.get_float() self._thickness = c5.get_float() self._geartype = c6.get_int() self._center = c7.getv_fvec() ui.destroy(panel) cs_dict = self.get_commands(mod_command) cx = self._center[0] cy = self._center[1] cz = self._center[2] - (self._thickness / 2) t_ang = 360 / self._teeth / 57.2957794 # figure out the layers we need to use and those that are # available for our temporary work fg_layers = lwsdk.LWStateQueryFuncs().layerList(lwsdk.OPLYR_FG, None) fg_layers_list = fg_layers.split() empty_layers = lwsdk.LWStateQueryFuncs().layerList(lwsdk.OPLYR_EMPTY, None) empty_layers_list = empty_layers.split() cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) x = 0 empty_layer = empty_layers_list[x] while x < len(empty_layers_list) and (empty_layer in fg_layers_list): x += 1 empty_layer = empty_layers_list[x] # only punch a hole if we can get an empty layer to work in if x == len(empty_layers_list): print >>sys.stderr, "Cannot locate an empty background layer!" return lwsdk.AFUNC_OK mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER) if not mesh_edit_op: print >>sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK monitor_funcs = lwsdk.DynaMonitorFuncs() dyna_monitor = monitor_funcs.create("Gears", "Generating gear...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, self._teeth) edit_op_result = lwsdk.EDERR_NONE ptID = [] cancelled = False # catch exceptions to make sure Modeler ends up on a sane state try: tooth = 0 for tooth in range(self._teeth): a1 = t_ang * tooth a2 = a1 + (t_ang * 3 / 6) a3 = a1 + (t_ang * 4 / 6) a4 = a1 + (t_ang * 5 / 6) pt = [ (self._rad_inner * math.sin(a1) + cx), (self._rad_inner * math.cos(a1) + cy), cz ] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [ (self._rad_inner * math.sin(a2) + cx), (self._rad_inner * math.cos(a2) + cy), cz ] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [ (self._rad_outer * math.sin(a3) + cx), (self._rad_outer * math.cos(a3) + cy), cz ] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) pt = [ (self._rad_outer * math.sin(a4) + cx), (self._rad_outer * math.cos(a4) + cy), cz ] ptID.append(mesh_edit_op.addPoint(mesh_edit_op.state, pt)) if dyna_monitor: result = dyna_monitor.step(dyna_monitor.data, 1) if result: cancelled = True break if cancelled: edit_op_result = lwsdk.EDERR_USERABORT else: if self._geartype == gears.ANGULAR: mesh_edit_op.addPoly(mesh_edit_op.state, lwsdk.LWPOLTYPE_FACE, None, "Gear", ptID) else: # Smooth ptID.append(ptID[0]) # close the loop mesh_edit_op.addCurve(mesh_edit_op.state, None, ptID, 0) except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) if cancelled: return lwsdk.AFUNC_OK if self._geartype == gears.SMOOTH: result = mod_command.execute(mod_command.data, cs_dict["FREEZECURVES"], None, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(('Z', self._thickness)) result = mod_command.execute(mod_command.data, cs_dict["EXTRUDE"], cs_options, lwsdk.OPSEL_USER) # make hole with a diameter 25% of the gear's radius cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(([self._rad_outer * 0.25, # radius self._rad_outer * 0.25, self._rad_outer * 0.25], -0.5, # top self._thickness + 1, # bottom 'Z', # axis 32, # number of sides 1, # number of segments [cx, cy, cz] # center )) result = mod_command.execute(mod_command.data, cs_dict["MAKEDISC"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETBLAYER"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues('SUBTRACT') result = mod_command.execute(mod_command.data, cs_dict["BOOLEAN"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(empty_layer) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["DELETE"], None, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers_list[0]) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["MERGEPOINTS"], None, lwsdk.OPSEL_USER) result = mod_command.execute(mod_command.data, cs_dict["ALIGNPOLS"], None, lwsdk.OPSEL_USER) if self._geartype == gears.SMOOTH: result = mod_command.execute(mod_command.data, cs_dict["FLIP"], None, lwsdk.OPSEL_USER) if self._axis != gears.Z: angle = 90.0 if self._axis == gears.X: cs_options = lwsdk.marshall_dynavalues((angle, 'Y')) elif self._axis == gears.Y: cs_options = lwsdk.marshall_dynavalues((angle, 'X')) result = mod_command.execute(mod_command.data, cs_dict["ROTATE"], cs_options, lwsdk.OPSEL_USER) cs_options = lwsdk.marshall_dynavalues(fg_layers) result = mod_command.execute(mod_command.data, cs_dict["SETLAYER"], cs_options, lwsdk.OPSEL_USER) return lwsdk.AFUNC_OK
def process(self, mod_command): ui = lwsdk.LWPanels() panel = ui.create('Bubbles') c1 = panel.hchoice_ctl('Sphere Type', ['Globe', 'Tesselated']) c2 = panel.int_ctl('Tesselation Level') c3 = panel.dist_ctl('Maximum Radius') c4 = panel.dist_ctl('Minimum Radius') c5 = panel.int_ctl('Globe Sides') c6 = panel.int_ctl('Globe Segments') c7 = panel.str_ctl('Surface', 50) panel.align_controls_vertical([c1, c2, c3, c4, c5, c6, c7]) panel.size_to_layout(5, 5) c1.set_int(self._sphereType) c2.set_int(self._tessLevel) c3.set_float(self._maxRadius) c4.set_float(self._minRadius) c5.set_int(self._globeSides) c6.set_int(self._globeSegments) c7.set_str(self._surface) if panel.open(lwsdk.PANF_BLOCKING | lwsdk.PANF_CANCEL) == 0: ui.destroy(panel) return lwsdk.AFUNC_OK self._sphereType = c1.get_int() self._tessLevel = c2.get_int() self._maxRadius = c3.get_float() self._minRadius = c4.get_float() self._globeSides = c5.get_int() self._globeSegments = c6.get_int() self._surface = c7.get_str() ui.destroy(panel) cs_dict = self.get_commands(mod_command) random.seed() cs_options = lwsdk.marshall_dynavalues((self._surface, )) result, dyna_value = mod_command.execute(mod_command.data, cs_dict["SURFACE"], cs_options, lwsdk.OPSEL_USER) mesh_edit_op = mod_command.editBegin(0, 0, lwsdk.OPSEL_USER) if not mesh_edit_op: print >> sys.stderr, 'Failed to engage mesh edit operations!' return lwsdk.AFUNC_OK # gather up the point ids points = [] # NOTE: we will be passing in a sequence (list or tuple) as the argument to the callback. # internally, Python expects a sequence as an argument to the function, so it MUST be encased # in another sequence, or it will be mistaken for a sequence containing the arguments # (instead of an argument itself). edit_op_result = mesh_edit_op.fastPointScan(mesh_edit_op.state, self.fast_point_scan, (points, ), lwsdk.OPLYR_FG, 1) if edit_op_result != lwsdk.EDERR_NONE: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) return lwsdk.AFUNC_OK point_count = len(points) # print some info to the PCore console print '%d points found for lwsdk.OPLYR_FG' % point_count edit_op_result = lwsdk.EDERR_NONE monitor_funcs = lwsdk.DynaMonitorFuncs() dyna_monitor = monitor_funcs.create("Bubbles", "Removing points...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, point_count) positions = [] # catch exceptions to make sure Modeler ends up on a sane state try: for point in points: print type(point) positions.append( lwsdk.Vector( mesh_edit_op.pointPos(mesh_edit_op.state, point))) mesh_edit_op.remPoint(mesh_edit_op.state, point) if dyna_monitor: if dyna_monitor.step(dyna_monitor.data, 1): edit_op_result = lwsdk.EDERR_USERABORT break except: edit_op_result = lwsdk.EDERR_USERABORT raise finally: mesh_edit_op.done(mesh_edit_op.state, edit_op_result, 0) if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) dyna_monitor = monitor_funcs.create("Bubbles", "Creating bubbles...") if dyna_monitor: dyna_monitor.init(dyna_monitor.data, point_count) for position in positions: percent = random.random() radius = lwsdk.Vector(self._minRadius + ( (self._maxRadius - self._minRadius) * percent)) if self._sphereType == bubbles.GLOBE: cs_options = lwsdk.marshall_dynavalues( (radius, self._globeSides, self._globeSegments, position)) result, dyna_value = mod_command.execute( mod_command.data, cs_dict["MAKEBALL"], cs_options, lwsdk.OPSEL_USER) else: cs_options = lwsdk.marshall_dynavalues( (radius, self._tessLevel, position)) result, dyna_value = mod_command.execute( mod_command.data, cs_dict["MAKETESBALL"], cs_options, lwsdk.OPSEL_USER) if dyna_monitor: if dyna_monitor.step(dyna_monitor.data, 1): edit_op_result = lwsdk.EDERR_USERABORT break if dyna_monitor: dyna_monitor.done(dyna_monitor.data) monitor_funcs.destroy(dyna_monitor) return lwsdk.AFUNC_OK