Not applicable
02-19-2021
02:24 PM
I'm working on a greebling script as my first attempt at writing a complex Python script for Maya. However, I have an issue where faces extrude into other pieces of geometry and I'm not sure how to remedy it. I was thinking locators could be used but I'm not sure how efficient that would be. I've been testing it using a cube scaled to 12 in XYZ, with 3 subdivisions in width, height and depth. Here's the code:
import maya.cmds as cmds
import math
import random as rand
terrainPlane = cmds.ls(sl = True, o = True) [0]
cycles = 1
def greeble(terrainPlane,cycles):
print ('Cycle ' + str(cycles))
facesNo = cmds.ls('{}.f[:]'.format(terrainPlane), fl=True)
facesTotalNo = len(facesNo)
print ('Total Faces: ' + str(facesTotalNo))
cmds.select(clear = True)
greebleRange =(facesTotalNo/(cycles *2))
print ('Greeble Range: ' + str(greebleRange))
for i in range (0,greebleRange):
randomFace = rand.randint(0,facesTotalNo)
print ('Random Face ' + str(i) + ':' + str(randomFace) + ' of ' + str(greebleRange))
cmds.select('{}.f[{}]'.format(terrainPlane,randomFace),add = True)
cmds.filterExpand(ex = True, sm = 34)
print ('Greeble Range: ' + str(greebleRange))
tkMultiplier = ((greebleRange/(10*cycles))*1+(4*(cycles-1)))
print ('tkMultiplier: ' + str(tkMultiplier))
tkUpper = greebleRange/(2*cycles)
print ('tkUpper: ' + str(tkUpper))
tkVal = rand.uniform(0,tkUpper/tkMultiplier)
print ('tkVal: ' + str(tkVal))
cmds.polyExtrudeFacet(tk = tkVal,keepFacesTogether = True,d = 1)
cmds.scale(scaleXYZ = (rand.uniform(0.6,10.5)))
cmds.select(clear = True)
cmds.select(clear = True)
cmds.select(terrainPlane)
cmds.polySubdivideFacet(divisions = 1)
cycles = cycles + 1
for i in range(0,2):
greeble(terrainPlane,cycles)
Apologies if the code is a bit rough, I've been trying to work a proof of concept version before refining the full script.
Solved! Go to Solution.
Link copied