def prepareLocatorList(): global fslocator_IDList global fslocator_NameList locatorNames = [] locatorIDs = [] lx.out('Prepping locator list') numberOfSceneItems = lx.eval('query sceneservice item.N ?') monitor = lx.Monitor(numberOfSceneItems) for i in range(numberOfSceneItems): type = lx.eval('query sceneservice item.type ? %s' % i) if (type == "locator"): locatorIDs.append(lx.eval('query sceneservice item.id ? %s' % i)) locatorNames.append( lx.eval('query sceneservice item.name ? %s' % i)) monitor.step() monitor = lx.Monitor(len(locatorIDs)) for index in range(len(locatorIDs)): myParentID = lx.eval('query sceneservice item.parent ? {%s}' % locatorIDs[index]) if (myParentID != None): myParentName = lx.eval('query sceneservice item.name ? {%s}' % myParentID) if (myParentName == "Blendshapes"): fslocator_IDList.append( lx.eval('query sceneservice item.id ? {%s}' % locatorIDs[index])) fslocator_NameList.append( lx.eval('query sceneservice item.name ? {%s}' % locatorNames[index])) monitor.step()
def main(): scene = modo.Scene() i = 0 instance_types = [] items = [] for item in scene.selected: m = lx.Monitor(len(scene.selected)) m.init(len(scene.selected)) if item.isAnInstance: scene.select(item) if item.type == "meshInst": lx.eval("item.setType mesh") lx.eval("mesh.setBBox false") else: lx.eval("item.setType {0}".format(item.type)) i += 1 items.append(item.name) instance_types.append(item.type) m.step() output = ["{0} Instances de-instanced.\n\n".format(i)] for instance_type in set(instance_types): out = "{0} {1}s".format(instance_types.count(instance_type), instance_type) output.append(out) message = "\n".join(output) modo.dialogs.alert("De-instance complete", message, dtype='info')
def main(): scene = modo.Scene() graph = lx.object.ItemGraph(scene.GraphLookup('deformers')) items = scene.items('mesh') if (len(items) == 0): sys.exit() targetFile = customfile('fileOpen', 'Choose any MDD file', 'mdd', 'MDD', '*.mdd', None) if (targetFile != None): targetLocation = os.path.dirname(targetFile) lx.out('targetLocation: {%s}' % targetLocation) monitor = lx.Monitor(len(items)) for item in items: monitor.step() lx.eval('select.drop item') meshName = item.UniqueName() # Take out character naming off the end. Only for Anima 1.x tempArray = meshName.split('--') if len(tempArray) > 1: # Add back a trailing dash to match naming convention for MDD files meshName = tempArray[0] + "-" lx.out('meshName: {%s}' % meshName) filepath = targetLocation + os.sep lx.out('filepath: {%s}' % filepath) filepath = filepath + meshName + ".mdd" ''' mesh = item.Ident()''' deformer = scene.addItem('deformMDD2') graph.AddLink(deformer, item) deformer.channel('file').set(filepath) lx.eval('select.drop item') lx.eval('select.item {%s}' % deformer.Ident()) lx.eval('deform.mddReload') else: sys.exit()
def parseTarget(targetFile): global fsMorphs global assetMorphs with open(targetFile) as f: content = f.read().splitlines() # Let's find the beginning of our relationship definition section. line = 0 while (not content[line].startswith('bs')): if (line == len(content)): # Didn't find anything, we'll exit lx.out('Could not find data in file!') sys.exit() line += 1 # OK, we found something. # Each line now should be of the form : bs = EyeSquint_R = Victoria4_unwelded_blendShape.head.PHMEyeSquintR = 2 monitor = lx.Monitor(len(content)) monitor.step() while (line < len(content)): tempArray = content[line].split(' = ') faceShiftMorph = tempArray[1] myAssetMorph = tempArray[2] # take our *_blendShape. off the front. myAssetMorph = myAssetMorph[(myAssetMorph.index('.') + 1):] # OK. We can't use dictionaries here because each morph can appear more than once. So we use a pair of matched arrays fsMorphs.append(faceShiftMorph) assetMorphs.append(myAssetMorph) line += 1 monitor.step() for item in range(len(fsMorphs)): lx.out("fsmorph {%s} matched to assetmorph {%s}" % (fsMorphs[item], assetMorphs[item]))
def linkMorphs(meshID): global assetMorphs global fsMorphs global morphInfluenceIDs global fslocator_IDList global fslocator_NameList # We need a list of locators that match our expectations for the faceShift imported dataset. # This populates our fslocator_IDList and fslocator_NameList lists prepareLocatorList() # Now we need the morph influences against our selected mesh item # This populates our morphInfluenceIDs list findMorphInfluences(meshID) # OK so we need by morph deformers and check that the associated morph map property matches our faceShift-associated morph. monitor = lx.Monitor(len(morphInfluenceIDs)) lx.out('Processing morph influences') for index in range(len(morphInfluenceIDs)): lx.out("Number of influences in total {%s}" % len(morphInfluenceIDs)) morphID = morphInfluenceIDs[index] # We need to extract our map name from this deformer. lx.eval('select.deformer {%s} set' % morphID) morphMapName = lx.eval('item.channel mapName ? {%s}' % morphID) # So we have a valid deformer and the associated map. # Let's see if the morph map was used in faceShift # morphIndices will hold the position(s) of the map in the assetMorphs array. morphIndices = indices(assetMorphs, morphMapName) if (len(morphIndices) > 0): lx.out('morphs to process : {%d}' % len(morphIndices)) for index in range(len(morphIndices)): # Retrieve the corresponding faceshift morph name fsMorphName = fsMorphs[morphIndices[index]] # Retrieve the locator ID from the matched array based on the name fsLink_Locator_ID = fslocator_IDList[fslocator_NameList.index( fsMorphName)] # We need the xfrmScl locator for this locator. scl_xfrm_item = lx.eval( 'query sceneservice item.xfrmScl ? {%s}' % fsLink_Locator_ID) # Select our driver channel first lx.out('Selecting locator {%s} channel scl.Z' % scl_xfrm_item) lx.eval('select.channel {%s:%s} set' % (scl_xfrm_item, "scl.Z")) # Select our morph influence strength channel next. lx.out('Selecting morph {%s} channel strength' % morphID) lx.eval('select.channel {%s:%s} add' % (morphID, "strength")) # Link them together lx.eval('channel.link toggle') monitor.step()
def doMainProcess() : main = lx.eval("query layerservice layers ? main") poly=lx.eval("query layerservice polys ? selected") r1 = lx.eval("user.value zReStep_density ?") #percent from center diagonal to start of next polygon r1 = int(r1)/100 dw = lx.eval("user.value zReStep_minAmplitude ?") #Minimum amplitude - Ratio of minimum width of generated polygon to the initially selected polygon (%) (given as interger) dh = lx.eval("user.value zReStep_shiftDistance ?") #Shift distance - Distance to shift out ri = lx.eval("user.value zReStep_insetRate ?") #Inset rate - Distance to inset minSize = float(lx.eval("user.value zReStep_minSize ?")) #min poly size to create fracCnt = lx.eval("user.value zReStep_fractalCount ?") totalPolySelected = lx.eval("user.value zReStep_polygonsSelected ?") replayLoops = lx.eval("user.value zReStep_replayRestep ?") chunkSize = (totalPolySelected*replayLoops) polChunks = 1 if poly != None : if type(poly) == tuple : for pol in poly: polChunks+=1 t = lx.Monitor() t.init(polChunks+1) if poly != None : limit = lx.eval("user.value zReStep_fractalCount ?") if type(poly) == tuple : for pol in poly: t.step(1) vid = getPVList(pol) if len(vid) != 4 : continue long = idistance(vid[0],vid[2]) limitw = long / dw rh = long * dh / 100.0 normal = getPNormal(pol) if limitw > minSize and normal > 0: process(vid,main,normal,limit,rh,limitw) poly = list(poly) poly.sort() poly.reverse() else : vid = getPVList(poly) if len(vid) == 4 : long = idistance(vid[0],vid[2]) limitw = long / dw rh = long * dh / 100.0 normal = getPNormal(poly) if limitw > minSize and normal > 0: process(vid,main,normal,limit,rh,limitw) lx.eval("select.drop polygon")
def prepareLocatorList(): global fslocator_IDList global fslocator_NameList lx.out('Prepping locator list') locators = [ l for l in modo.Scene().items('locator') if l.type == 'locator' ] monitor = lx.Monitor(len(locators)) for locator in locators: myParentID = locator.parent if (myParentID != None): myParentName = myParentID.UniqueName() if (myParentName == "Blendshapes"): fslocator_IDList.append(locator.Ident()) fslocator_NameList.append(locator.UniqueName()) monitor.step()
def findMorphInfluences(meshID): global morphInfluenceIDs lx.out('Finding morph influences') numberOfDeformers = modo.Scene().items('morphDeform') # numberOfDeformers = modo.Scene().morphDeform('morphDeform') lx.out('Morph influences : {%d}' % len(numberOfDeformers)) monitor = lx.Monitor(len(numberOfDeformers)) for influence in numberOfDeformers: if influence.type == 'morphDeform': #safety check influenceObject = modo.item.Deformer(influence) for mesh in influenceObject.meshes: deformerMeshID = mesh.id lx.out('Deformer mesh ID is : {%s}' % deformerMeshID) lx.out('meshID is : {%s}' % meshID) if (meshID == deformerMeshID): lx.out('Matched influence {%s} to mesh {%s}' % (influence.id, deformerMeshID)) morphInfluenceIDs.append(influence.id) monitor.step()
def findMorphInfluences(meshID): global morphInfluenceIDs lx.out('Finding morph influences') numberOfDeformers = lx.eval('query sceneservice morphDeform.N ?') lx.out('Morph influences : {%d}' % numberOfDeformers) monitor = lx.Monitor(numberOfDeformers) for influence in range(numberOfDeformers): currentMorphID = lx.eval('query sceneservice morphDeform.id ? {%s}' % influence) currentMorphName = lx.eval( 'query sceneservice morphDeform.name ? {%s}' % influence) deformerMeshID = lx.eval('query sceneservice deformer.meshes ? {%s}' % currentMorphID) lx.out('Deformer mesh name is : {%s}' % deformerMeshID) if (meshID == deformerMeshID): lx.out('Matched influence {%s} to mesh {%s}' % (currentMorphName, deformerMeshID)) morphInfluenceIDs.append(currentMorphID) monitor.step()
else: files = _find_files(file_path, wildcard='#') status = modo.dialogs.okCancel( 'Creating Proxies', 'Creating proxies for following files:\n%s' % '\n'.join(files)) if status == 'ok': for fp in files: create_proxy(fp, file_type='JPG', force=True) if arg == 'createShotsub': try: file_path = modo.dialogs.dirBrowse('Image Sequence Path', path=filename) except: print 'Abort' else: files = _find_files(file_path) status = modo.dialogs.okCancel( 'Creating Shotsub', 'Creating Shotssub(s) for:\n%s' % '\n'.join(files)) if status == 'ok': m = lx.Monitor(len(files)) for f in files: m.step(1) create_video(f) if arg == 'setRenderCamera': camera = scene.selectedByType(modo.constants.CAMERA_TYPE)[0] if camera: set_renderCam(camera, renderItem)
lx.eval("select.drop edge") lx.eval("select.edge add poly equal 1") open_edges = set(lx.eval("query layerservice edges ? selected")) lx.eval("select.drop edge") lx.out(time.clock() - timer) for edge in open_edges: x, y = edge[1:-1].split(',') lx.eval("select.element " + str(layer) + " edge add " + x + " " + y) lx.eval("select.convert vertex") open_vertices = lx.eval("query layerservice verts ? selected") lx.out(time.clock() - timer) for vertex in open_vertices: vert_pos = lx.eval("query layerservice vert.pos ? " + str(vertex)) vert_range = tuple(int(math.ceil(x/y)-1) for x,y in izip(vecSub(layer_bounds[1],vert_pos), sector_range)) sector_space[vert_range[0]][vert_range[1]][vert_range[2]].append(vertex) m = lx.Monitor(len(open_edges)) lx.out(time.clock() - timer) ################# # MAIN LOOP for edge in open_edges: monstep(1) old_verts = [] edge_sectors = [] sector_vertices = [] edge_vertices = lx.eval("query layerservice edge.vertList ? " + str(edge)) vec1, vec2 = (lx.eval("query layerservice vert.pos ? " + str(edge_vertex)) for edge_vertex in edge_vertices) edge_bounds = getBoundingBox((vec1,vec2),threshold) sample_points = [vec1] + lineSamples (vec1, vec2, SECTORS) + [vec2] for point in sample_points:
sv = otherv(e, sv) seqv.append(sv) loopedge.remove(e) break if not term: which.append(seqv) if len(which) == 2: if len(which[0]) < len(which[1]): return which[0] else: return which[1] else: return which[0] mon = lx.Monitor() main = lx.eval("query layerservice layers ? main") pseledges = lx.evalN("query layerservice edges ? selected") lx.eval("select.convert vertex") everts = list(lx.evalN("query layerservice verts ? selected")) selverts = set(everts * 1) lx.eval("select.drop edge") lx.eval("select.drop vertex") vs = lx.evalN("query layerservice vert.vertList ? %s" % everts[0]) for v in vs: if str(v) in selverts: lx.eval("select.type edge") lx.command("select.element", layer=main, type="edge", mode="set",
delete = True if arg == "collision": collision = True if reducep.search(arg): reduction = int(reducep.search(arg).group()) timer = time.clock() selmode = lx.eval("query layerservice selmode ?") threshold = math.radians(threshold) num_layers = lx.eval("query layerservice layer.N ? all") vertex_offset = 1 #this is an offset used when making obj normal_offset = 1 object_list = [] m = lx.Monitor() filename = "temp" layer_list = modoutil.getLayerNames() lx.out(layer_list) while filename in layer_list: filename = modoutil.idGenerator() obj_file = open((lx.eval("query platformservice path.path ? user") + "\\" + filename + ".obj"), 'w') layer = lx.eval("query layerservice layers ? main") vertex_index_list = set() if selmode == "vertex": vertex_index_list = set(lx.eval("query layerservice verts ? selected"))
def main(): start_timer = bd_helpers.timer() scene = modo.Scene() sel = scene.selected path = modo.dialogs.dirBrowse(" V-Ray Proxy Path") if path: proxies = get_proxies(path) all_items = [] meshes = [] # Get all mesh items in the selected hierarchy for i in sel: all_items.append(i) children = i.children(recursive=True, itemType=lx.symbol.sITYPE_MESH) if len(children) > 0: all_items += children all_items = set(all_items) # Filter out any non-meshes for i in all_items: if i.type == lx.symbol.sITYPE_MESH: meshes.append(i) meshes = set(meshes) if len(meshes) > 0: found = False m = lx.Monitor(len(proxies)) m.init(len(proxies) * 2) # Go through all proxy files and compare their names to the mesh names for proxy in proxies: regex = "{}".format(re.escape(proxy)) m.step(1) for i in meshes: match = re.match(regex, i.name) if match: found = True try: convert_proxy(i, proxy, path) except: pass # Second round with looser regex to catch any misses reduced = [] for i in meshes: if i.type == lx.symbol.sITYPE_MESH: reduced.append(i) meshes = set(reduced) if len(meshes) > 0: for proxy in proxies: regex = "{}[ _\d]*$".format(re.escape(proxy)) m.step(1) for i in meshes: match = re.match(regex, i.name) if match: found = True print i print proxy try: convert_proxy(i, proxy, path) except: pass else: m.step(len(proxies)) if not found: print("No V-Ray Proxies found for the selected meshes.") else: print("No meshes to replace. Please select some meshes first.") bd_helpers.timer(start_timer, os.path.splitext(os.path.basename(__file__))[0])
#select = lx.evalN("query layerservice polys ? selected") # file dialog try: lx.eval("dialog.setup fileOpen") lx.eval("dialog.title {select files}") lx.eval("dialog.fileTypeCustom bvh \"BVH\" \"*.bvh\" bvh") lx.eval("dialog.open") fInputFilePath = lx.eval("dialog.result ?") except: lx.out("File read Aborted or some error") sys.exit() monitor = lx.Monitor() #read via bvh bvhRd = BVHReader(fInputFilePath) # set user values bvhRd.frameMode = lx.eval("user.value BVHLoader.frameMode ?") bvhRd.scaleFactor = lx.eval("user.value BVHLoader.scaleFactor ?") bvhRd.readJointOnly = True if lx.eval( "user.value BVHLoader.readJointOnly ?") == "on" else False bvhRd.rotOrder = lx.eval("user.value BVHLoader.rotOrder ?") # bvhRd.adaptFPS = True if lx.eval("user.value BVHLoader.adaptFPS ?") == "on" else False bvhRd.keyReduction = True if lx.eval( "user.value BVHLoader.keyReduction ?") == "on" else False bvhRd.faceShift = True if lx.eval( "user.value BVHLoader.faceShift ?") == "on" else False