Esempio n. 1
0
def drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length):
    if (iteration < branches):
        iteration = iteration + 1

        #Draw circle and extrude based on parameters
        shape = circle(nr=(nrX, nrY, nrZ), c=(cX, cY, cZ), r=radius)
        extrude(shape, et=0, d=(nrX, nrY, nrZ), l=length)
        #Delete the base circle, keep the cylinder
        delete(shape)

        #Define direction vector and normalize
        vector = MVector(nrX, nrY, nrZ)
        vector.normalize()

        cX = cX + (length * vector.x)
        cY = cY + (length * vector.y)
        cZ = cZ + (length * vector.z)

        randX = r.randint(0, 1) * 2 - 1
        randY = r.randint(0, 1) * 2 - 1
        randZ = r.randint(0, 1) * 2 - 1

        #Random direction vector
        #For X, Y, Z, ( -1 or 1 )*angle + (randint from -angleVariance to +angleVariance)
        nrX = nrX + ((angle * randX) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0
        nrY = nrY + ((angle * randY) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0
        nrZ = nrZ + ((angle * randZ) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0

        #Length and Radius based on factor + (randint from -variance to +variance)
        length = length * (lengthFactor +
                           (r.randint(0, lengthVariance * 2 * 100) / 100.0) -
                           lengthVariance)
        radius = radius * (radiusFactor +
                           (r.randint(0, radiusVariance * 2 * 100) / 100.0) -
                           radiusVariance)

        #Draw first branch
        drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length)

        #Use opposite base angle from previous branch
        nrX = nrX + ((angle * randX * -1) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0
        nrY = nrY + ((angle * randY * -1) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0
        nrZ = nrZ + ((angle * randZ * -1) + r.randint(0, angleVariance * 2) -
                     angleVariance) / 100.0

        length = length * (lengthFactor +
                           (r.randint(0, lengthVariance * 2 * 100) / 100.0) -
                           lengthVariance)
        radius = radius * (radiusFactor +
                           (r.randint(0, radiusVariance * 2 * 100) / 100.0) -
                           radiusVariance)

        #Draw second branch
        drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length)
Esempio n. 2
0
def look_at(source, target, up_vector=(0, 1, 0), as_vector=True):
    """
    allows the transform object to look at another target vector object.
    :return: <tuple> rotational vector.
    """
    source_world = transform_utils.Transform(source).world_matrix_list()
    target_world = transform_utils.Transform(target).world_matrix_list()
    source_parent_name = object_utils.get_parent_name(source)[0]
    if source_parent_name == 'world':
        source_parent_name = None
    else:
        parent_world = transform_utils.Transform(source_parent_name).world_matrix_list()

    # build normalized vector from the translations from matrix data
    z = MVector(target_world[12] - source_world[12],
                target_world[13] - source_world[13],
                target_world[14] - source_world[14])
    z *= -1
    z.normalize()

    # get normalized cross product of the z against the up vector at origin
    # x = z ^ MVector(-up_vector[0], -up_vector[1], -up_vector[2])
    x = z ^ MVector(up_vector[0], up_vector[1], up_vector[2])
    x.normalize()

    # get the normalized y vector
    y = x ^ z
    y.normalize()

    # build the aim matrix
    local_matrix_list = (
        x.x, x.y, x.z, 0,
        y.x, y.y, y.z, 0,
        z.x, z.y, z.z, 0,
        0, 0, 0, 1.0)

    matrix = object_utils.ScriptUtil(local_matrix_list, matrix_from_list=True).matrix

    if source_parent_name:
        # transform the matrix in the local space of the parent object
        parent_matrix = object_utils.ScriptUtil(parent_world, matrix_from_list=True)
        matrix *= parent_matrix.matrix.inverse()

    # retrieve the desired rotation for "source" to aim at "target", in degrees
    if as_vector:
        rotation = MTransformationMatrix(matrix).eulerRotation() * RADIANS_2_DEGREES
        vector = rotation.asVector()
        return vector.x, vector.y, vector.z,
    else:
        return local_matrix_list
def drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length):
	if(iteration < branches):
		iteration = iteration + 1
		
		#Draw circle and extrude based on parameters
		shape = circle( nr=(nrX, nrY, nrZ), c=(cX, cY, cZ), r=radius)
		extrude (shape, et=0, d= (nrX, nrY, nrZ), l= length)
		#Delete the base circle, keep the cylinder
		delete(shape)
		
		#Define direction vector and normalize
		vector = MVector(nrX, nrY, nrZ)
		vector.normalize()
		
		cX = cX + (length*vector.x)
		cY = cY + (length*vector.y)
		cZ = cZ + (length*vector.z)
		
		randX = r.randint(0, 1)*2 -1
		randY = r.randint(0, 1)*2 -1
		randZ = r.randint(0, 1)*2 -1
		
		#Random direction vector
		#For X, Y, Z, ( -1 or 1 )*angle + (randint from -angleVariance to +angleVariance)
		nrX = nrX + ((angle*randX) + r.randint(0, angleVariance*2) - angleVariance)/100.0
		nrY = nrY + ((angle*randY) + r.randint(0, angleVariance*2) - angleVariance)/100.0
		nrZ = nrZ + ((angle*randZ) + r.randint(0, angleVariance*2) - angleVariance)/100.0

		#Length and Radius based on factor + (randint from -variance to +variance)
		length = length * (lengthFactor + (r.randint(0, lengthVariance*2*100)/100.0) - lengthVariance)
		radius = radius * (radiusFactor + (r.randint(0, radiusVariance*2*100)/100.0) - radiusVariance)
		
		#Draw first branch
		drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length)
		
		#Use opposite base angle from previous branch
		nrX = nrX + ((angle*randX*-1) + r.randint(0, angleVariance*2) - angleVariance)/100.0
		nrY = nrY + ((angle*randY*-1) + r.randint(0, angleVariance*2) - angleVariance)/100.0
		nrZ = nrZ + ((angle*randZ*-1) + r.randint(0, angleVariance*2) - angleVariance)/100.0

		length = length * (lengthFactor + (r.randint(0, lengthVariance*2*100)/100.0) - lengthVariance)
		radius = radius * (radiusFactor + (r.randint(0, radiusVariance*2*100)/100.0) - radiusVariance)
		
		#Draw second branch
		drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length)
Esempio n. 4
0
def drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length,old_circle,ShereBool):
	if(iteration < branches):
		iteration = iteration + 1
		print("iteration= "+str(iteration))
		#Draw circle and extrude based on parameters
		R=radius*math.fabs(math.sin(iteration))
		R=radius+iteration-math.fabs(iteration)
		R=10-iteration
		circle( nr=(nrX, nrY, nrZ), c=(cX, cY, cZ), r=radius)
		shape = cmds.ls(sl=True)[0]
		circleReffArr.append(shape)
		cmds.select( clear=True )
		cmds.select( old_circle, add=True )
		cmds.select( shape, add=True )
		cmds.loft( c=0, ch=1, d=3, ss=1, rsn=True, ar=1, u=1, rn=0, po=0)
		extrudedSurface = cmds.ls(sl=True)[0]
		print("nrX= "+str(nrX)+" nrY= "+str(nrY)+" nrZ= "+str(nrZ))
		if(0==True):
			cmds.polySphere(createUVs=2, sy=20, ch=1, sx=20, r=radius*10)
			SpherePoly = cmds.ls(sl=True)[0]
			cmds.move( cX, cY, cZ, SpherePoly, absolute=True )
		#extrudedSurface=extrude (shape, et=0, d= (nrX, nrY, nrZ), l= length)
		#extrudedSurface=extrude (shape, extrudeType=0, d= (nrX, nrY, nrZ), l= length,polygon=1)
		#extrudedSurface=extrude (shape, extrudeType=0, d= (nrX, nrY, nrZ), l= length)
		
		cmds.nurbsToPoly(extrudedSurface, uss=1, ch=1, ft=0.01, d=0.1, pt=0, f=0, mrt=0, mel=0.001, ntr=0, vn=3, pc=1000, chr=0.9, un=3, vt=1, ut=1, ucr=0, cht=0.01, mnd=1, es=0, uch=0)
		delete(extrudedSurface)
		#print("extrudedSurface= "+str(extrudedSurface))
		extrudedPoly = cmds.ls(sl=True)[0]
		print("extrudedPoly= "+str(extrudedPoly))
		cmds.polyCloseBorder(extrudedPoly, ch=1)# Close Holl
		hollface = cmds.ls(sl=True)[0]
		print("hollface= "+str(hollface))
		cmds.polyTriangulate(hollface, ch=1)
		cmds.select(extrudedPoly)
		#cmds.polyClean(extrudedPoly)
		#cmds.eval('polyCleanupArgList 4 { "0","1","1","1","1","1","1","1","0","1e-05","0","1e-05","0","1e-05","0","1","1","0" };')
		#Delete the base circle, keep the cylinder
		#delete(shape)
		
		#Define direction vector and normalize
		vector = MVector(nrX, nrY, nrZ)
		vector.normalize()
		
		cX = cX + (length*vector.x)
		cY = cY + (length*vector.y)
		cZ = cZ + (length*vector.z)
		
		randX = random.randint(0, 1)*2 -1
		randY = random.randint(0, 1)*2 -1
		randZ = random.randint(0, 1)*2 -1
		
		#Random direction vector
		#For X, Y, Z, ( -1 or 1 )*angle + (randint from -angleVariance to +angleVariance)
		nrX = nrX + ((angle*randX) + random.randint(0, angleVariance*2) - angleVariance)/100.0
		nrY = nrY + ((angle*randY) + random.randint(0, angleVariance*2) - angleVariance)/100.0
		nrZ = nrZ + ((angle*randZ) + random.randint(0, angleVariance*2) - angleVariance)/100.0
		
		#Length and Radius based on factor + (randint from -variance to +variance)
		length = length * (lengthFactor + (random.randint(0, lengthVariance*2*100)/100.0) - lengthVariance)
		radius = radius * (radiusFactor + (random.randint(0, radiusVariance*2*100)/100.0) - radiusVariance)
		
		#Draw first branch
		drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length,shape,False)
		#drawBranch(iteration, cX, cY, cZ, 0, 1, 0, radius, length,shape,False)
		#--------------------
		#Use opposite base angle from previous branch
		nrX = nrX + ((angle*randX*-1) + random.randint(0, angleVariance*2) - angleVariance)/100.0
		nrY = nrY + ((angle*randY*-1) + random.randint(0, angleVariance*2) - angleVariance)/100.0
		nrZ = nrZ + ((angle*randZ*-1) + random.randint(0, angleVariance*2) - angleVariance)/100.0

		length = length * (lengthFactor + (random.randint(0, lengthVariance*2*100)/100.0) - lengthVariance)
		radius = radius * (radiusFactor + (random.randint(0, radiusVariance*2*100)/100.0) - radiusVariance)
		
		#Draw second branch
		drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length,shape,True)
    def drawBranch(self, iteration, cX, cY, cZ, nrX, nrY, nrZ, radius, length):
        if (iteration < self.branches):
            iteration = iteration + 1

            #Draw circle and extrude based on parameters
            shape = mc.circle(nr=(nrX, nrY, nrZ), c=(cX, cY, cZ), r=radius)
            poly = mc.extrude(shape, et=0, d=(nrX, nrY, nrZ), l=length)

            mc.group(poly, parent=self.grp)

            #Delete the base circle and keep the cylinder
            mc.delete(shape)

            #direction vector to grow
            vector = MVector(nrX, nrY, nrZ)
            vector.normalize()

            cX = cX + (length * vector.x)
            cY = cY + (length * vector.y)
            cZ = cZ + (length * vector.z)

            randX = r.randint(0, 1) * 2 - 1
            randY = r.randint(0, 1) * 2 - 1
            randZ = r.randint(0, 1) * 2 - 1

            #Random direction vector
            #For X, Y, Z, ( -1 or 1 )*angle + (randint from -angleVariance to +angleVariance)

            nrX = nrX + ((self.angle * randX) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0
            nrY = nrY + ((self.angle * randY) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0
            nrZ = nrZ + ((self.angle * randZ) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0

            #Length and Radius based on factor + (randint from -variance to +variance)

            length = length * (
                self.lengthFactor +
                (random.randint(0, self.lengthVariance * 2 * 100) / 100.0) -
                self.lengthVariance)
            radius = radius * (
                self.radiusFactor +
                (random.randint(0, self.radiusVariance * 2 * 100) / 100.0) -
                self.radiusVariance)

            #Draw first branch
            self.drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius,
                            length)

            #Use opposite base angle from previous branch

            nrX = nrX + ((self.angle * randX * -1) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0
            nrY = nrY + ((self.angle * randY * -1) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0
            nrZ = nrZ + ((self.angle * randZ * -1) + random.randint(
                0, self.angleVariance * 2) - self.angleVariance) / 100.0

            length = length * (
                self.lengthFactor +
                (random.randint(0, self.lengthVariance * 2 * 100) / 100.0) -
                self.lengthVariance)
            radius = radius * (
                self.radiusFactor +
                (random.randint(0, self.radiusVariance * 2 * 100) / 100.0) -
                self.radiusVariance)

            #Draw second branch
            self.drawBranch(iteration, cX, cY, cZ, nrX, nrY, nrZ, radius,
                            length)