Пример #1
0
def createBirail(curveGrp) :
    
    eachCrvGrp = cmds.listRelatives(curveGrp)
    
    shapeEachCrvGrp = cmds.listRelatives(eachCrvGrp, children=True)
    meshInGrp = cmds.ls(shapeEachCrvGrp, type='mesh')
    
    if len(eachCrvGrp)>3 and len(meshInGrp)==0 :
        
        #checking if curves are in right order
        intersect1 = cmds.curveIntersect(eachCrvGrp[0], eachCrvGrp[1])
        intersect2 = cmds.curveIntersect(eachCrvGrp[0], eachCrvGrp[2])
        intersect3 = cmds.curveIntersect(eachCrvGrp[0], eachCrvGrp[3])
        curveOrder = []
        
        if str(intersect1)=='None' :
            curveOrder = [eachCrvGrp[0], eachCrvGrp[2], eachCrvGrp[1], eachCrvGrp[3]]
        elif str(intersect3)=='None' :
            curveOrder = [eachCrvGrp[0], eachCrvGrp[1], eachCrvGrp[3], eachCrvGrp[2]]
        else :
            curveOrder = eachCrvGrp
        #
                
        crv1shape = cmds.listRelatives(curveOrder[1], children=True)
        crv1spans = cmds.getAttr(crv1shape[0]+'.spans')
        crv2shape = cmds.listRelatives(curveOrder[0], children=True)
        crv2spans = cmds.getAttr(crv2shape[0]+'.spans')
        
        #creating birail
        if crv1spans<crv2spans :
            mesh = cmds.doubleProfileBirailSurface([curveOrder[1], curveOrder[3],  curveOrder[0] ,curveOrder[2]], bl =  0.5 ,tp2 =  0 , ch = True , po = 1 ,tm = 1 , tp1 = 0) 
        else :
            mesh = cmds.doubleProfileBirailSurface([curveOrder[0] ,curveOrder[2], curveOrder[1],  curveOrder[3]], bl =  0.5 ,tp2 =  0 , ch = True , po = 1 ,tm = 1 , tp1 = 0) 
    
        shape = cmds.listRelatives(mesh, children = True)[0] 
        tess = cmds.listConnections(shape + '.inMesh') 
        density = 12 
    
        bboxGrp = cmds.exactWorldBoundingBox(curveGrp)
        
        cmds.setAttr(tess[0] + '.polygonType', 1)
        cmds.setAttr(tess[0] + '.uType', 1)
        cmds.setAttr(tess[0] + '.vType', 1)
        cmds.setAttr(tess[0] + '.format', 2)
        
        #check the order of u and v for tesselation to be homogeneous
        if ((bboxGrp[3] - bboxGrp[0])*density)>((bboxGrp[4] - bboxGrp[1])*density) :
            cmds.setAttr(tess[0] + '.uNumber', int((bboxGrp[3] - bboxGrp[0])*density)) 
            cmds.setAttr(tess[0] + '.vNumber', int((bboxGrp[4] - bboxGrp[1])*density))
        else :
            cmds.setAttr(tess[0] + '.vNumber', int((bboxGrp[3] - bboxGrp[0])*density)) 
            cmds.setAttr(tess[0] + '.uNumber', int((bboxGrp[4] - bboxGrp[1])*density))
        
        cmds.parent(mesh[0], curveGrp)
Пример #2
0
def checkIntersection(curves):
	"""
	Check if any curve intersect each other

	:param curves: curves to check
	:return: None
	"""
	for c in curves:
		for i in range(0, len(curves)):
			if c != curves[i]:
				int_point = cmd.curveIntersect(c, curves[i])
				if int_point is not None:
					print 'La curva \'' + c + '\' si interseca con la curva \'' + curves[i] + '\''
					print 'Punto di intersezione: ' + int_point
					raise Exception('Curve di livello irregolari.')
Пример #3
0
def testIfInsideCurve(point, curve, direction):
	p1 = point
	pTmp = (direction[0]*1000, direction[1]*1000, direction[2]*1000)
	p2 = (p1[0]+pTmp[0], p1[1]+pTmp[1], p1[2]+pTmp[2])
	segment = cmd.curve(p=[p1, p2], d=1)
	node = cmd.curveIntersect(segment, curve, ud=True, d=(0, 1, 0), ch=True)

	if node:
		intCurve1 = cmd.getAttr(node+'.parameter1')
		numOfIntersection = len(intCurve1[0])
	else:
		numOfIntersection = 0
		print 'Node e\' NoneType!'

	cmd.delete(segment)
	cmd.delete(node)
	return numOfIntersection % 2 == 1
Пример #4
0
def constructRayCaster(obj, intersectors):
    iNodes = []
    arcLength = 'arcLen'
    maxSize = cmd.getAttr('%s.boundingBoxSize' % obj)
    pythag = math.sqrt(maxSize[0][0]**2 + maxSize[0][1]**2)
    ray = cmd.curve(d=1, p=[(0, 0, 0), (pythag, 0, 0)])
    cmd.setAttr('%s.overrideEnabled' % ray, 1)
    cmd.setAttr('%s.overrideRGBColors' % ray, 1)
    rayShape = cmd.listRelatives(ray, ni=True, s=True)[0]
    if not cmd.objExists(arcLength):
        arcLength = cmd.shadingNode('arcLengthDimension', au=True, n=arcLength)
    cmd.connectAttr('%s.worldSpace[0]' % rayShape,
                    '%s.nurbsGeometry' % arcLength)
    for one in intersectors:
        iNodes.append(
            cmd.curveIntersect(rayShape, one, ud=True, dz=True, ch=True))
    return iNodes, arcLength, rayShape, ray
Пример #5
0
def curveIntersectJoints(curve,
                         intersectCurveList,
                         jointAtBase=True,
                         jointAtTip=True,
                         useDirection=False,
                         intersectDirection=(0, 0, 1),
                         prefix=''):
    """
    Create joints along a curve at the points of intersection with a list of secondary curves
    @param curve: Curve to create joints along
    @type curve: list
    @param intersectCurveList: List of intersection curves
    @type intersectCurveList: list
    @param jointAtBase: Create a joint at the base of the curve
    @type jointAtBase: bool
    @param jointAtTip: Create a joint at the tip of the curve
    @type jointAtTip: bool
    @param useDirection: Project the curves in a specified direction before intersecting
    @type useDirection: bool
    @param intersectDirection: The direction to project the curves before intersecting
    @type intersectDirection: tuple or list
    @param prefix: Name prefix for newly created nodes
    @type prefix: str
    """
    # Check curve
    if not cmds.objExists(curve):
        raise Exception('Curve object ' + curve + ' does not exist!')

    # Check intersect curve list
    for i in range(len(intersectCurveList)):
        if not cmds.objExists(intersectCurveList[i]):
            raise Exception('Object ' + intersectCurveList[i] + ' is not a valid curve!')

    # Check prefix
    if not prefix: prefix = glTools.utils.stringUtils.stripSuffix(curve)

    # Get curve Range
    minU = cmds.getAttr(curve + '.minValue')
    maxU = cmds.getAttr(curve + '.maxValue')

    # Initialize return list
    cmds.select(cl=True)
    jointList = []

    # Create Base Joint
    if jointAtBase:
        # Get curve point position
        pos = cmds.pointOnCurve(curve, pr=minU, p=True)
        # Create joint
        ind = '01'
        jnt = prefix + nameUtil.delineator + nameUtil.subPart['joint'] + ind + nameUtil.delineator + nameUtil.node[
            'joint']
        jnt = cmds.joint(p=pos, n=jnt)
        jointList.append(jnt)

    # Create joints at curve intersections
    for n in range(len(intersectCurveList)):
        # Get string index
        ind = str(n + 1 + int(jointAtBase))
        if i < (9 - int(jointAtBase)): ind = '0' + ind
        # Get curve intersections
        uList = cmds.curveIntersect(curve, intersectCurveList[n], ud=useDirection, d=intersectDirection)
        if not uList: continue
        uList = uList.split(' ')

        # Create joints
        for u in range(len(uList) / 2):
            # Get curve point position
            pos = cmds.pointOnCurve(curve, pr=float(uList[u * 2]), p=True)
            # Create joint
            jnt = prefix + nameUtil.delineator + nameUtil.subPart['joint'] + ind + nameUtil.delineator + nameUtil.node[
                'joint']
            jnt = cmds.joint(p=pos, n=jnt)
            jointList.append(jnt)

    # Create Tip Joint
    if jointAtTip:
        # Get string index
        ind = str(len(intersectCurveList) + int(jointAtBase) + 1)
        if len(intersectCurveList) < (9 - int(jointAtBase)): ind = '0' + ind
        # Get curve point position
        pos = cmds.pointOnCurve(curve, pr=maxU, p=True)
        # Create joint
        jnt = prefix + nameUtil.delineator + nameUtil.subPart['joint'] + ind + nameUtil.delineator + nameUtil.node[
            'joint']
        jnt = cmds.joint(p=pos, n=jnt)
        jointList.append(jnt)

    # Return result
    return jointList
Пример #6
0
def curveIntersectJoints(curve,
                         intersectCurveList,
                         jointAtBase=True,
                         jointAtTip=True,
                         useDirection=False,
                         intersectDirection=(0, 0, 1),
                         prefix=''):
    """
    Create joints along a curve at the points of intersection with a list of secondary curves
    @param curve: Curve to create joints along
    @type curve: list
    @param intersectCurveList: List of intersection curves
    @type intersectCurveList: list
    @param jointAtBase: Create a joint at the base of the curve
    @type jointAtBase: bool
    @param jointAtTip: Create a joint at the tip of the curve
    @type jointAtTip: bool
    @param useDirection: Project the curves in a specified direction before intersecting
    @type useDirection: bool
    @param intersectDirection: The direction to project the curves before intersecting
    @type intersectDirection: tuple or list
    @param prefix: Name prefix for newly created nodes
    @type prefix: str
    """
    # Check curve
    if not cmds.objExists(curve):
        raise Exception('Curve object ' + curve + ' does not exist!')

    # Check intersect curve list
    for i in range(len(intersectCurveList)):
        if not cmds.objExists(intersectCurveList[i]):
            raise Exception('Object ' + intersectCurveList[i] +
                            ' is not a valid curve!')

    # Check prefix
    if not prefix: prefix = glTools.utils.stringUtils.stripSuffix(curve)

    # Get curve Range
    minU = cmds.getAttr(curve + '.minValue')
    maxU = cmds.getAttr(curve + '.maxValue')

    # Initialize return list
    cmds.select(cl=True)
    jointList = []

    # Create Base Joint
    if jointAtBase:
        # Get curve point position
        pos = cmds.pointOnCurve(curve, pr=minU, p=True)
        # Create joint
        ind = '01'
        jnt = prefix + nameUtil.delineator + nameUtil.subPart[
            'joint'] + ind + nameUtil.delineator + nameUtil.node['joint']
        jnt = cmds.joint(p=pos, n=jnt)
        jointList.append(jnt)

    # Create joints at curve intersections
    for n in range(len(intersectCurveList)):
        # Get string index
        ind = str(n + 1 + int(jointAtBase))
        if i < (9 - int(jointAtBase)): ind = '0' + ind
        # Get curve intersections
        uList = cmds.curveIntersect(curve,
                                    intersectCurveList[n],
                                    ud=useDirection,
                                    d=intersectDirection)
        if not uList: continue
        uList = uList.split(' ')

        # Create joints
        for u in range(len(uList) / 2):
            # Get curve point position
            pos = cmds.pointOnCurve(curve, pr=float(uList[u * 2]), p=True)
            # Create joint
            jnt = prefix + nameUtil.delineator + nameUtil.subPart[
                'joint'] + ind + nameUtil.delineator + nameUtil.node['joint']
            jnt = cmds.joint(p=pos, n=jnt)
            jointList.append(jnt)

    # Create Tip Joint
    if jointAtTip:
        # Get string index
        ind = str(len(intersectCurveList) + int(jointAtBase) + 1)
        if len(intersectCurveList) < (9 - int(jointAtBase)): ind = '0' + ind
        # Get curve point position
        pos = cmds.pointOnCurve(curve, pr=maxU, p=True)
        # Create joint
        jnt = prefix + nameUtil.delineator + nameUtil.subPart[
            'joint'] + ind + nameUtil.delineator + nameUtil.node['joint']
        jnt = cmds.joint(p=pos, n=jnt)
        jointList.append(jnt)

    # Return result
    return jointList
Пример #7
0
def curveIntersect(*args, **kwargs):
    res = cmds.curveIntersect(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
Пример #8
0
def readCrossSections():
  global csNum
  global cs
  global chNum
  global ch

  #mel.eval("layerEditorSelectObjects layerCross;")
  curveNames = mel.eval("ls -sl -type transform")

  # no curve drawn
  if not curveNames:
    return
  
  # init globals
  
  csNum = len(curveNames)
  cs = [None for x in range(csNum)]
  for i in range(csNum):
    cs[i] = CrossSection(i)
    cs[i].name = curveNames[i]
  
  chNum = 0
  ch = [[None]*csNum for x in range(csNum)]
  
  
  # process intersections
  
  for i in range(csNum):
    for j in range(i+1, csNum):

      rawIntersects = cmds.curveIntersect(cs[i].name, cs[j].name, useDirection=True, direction=(0,0,1))
      
      if rawIntersects:
        ch[i][j] = CrossHair(i,j)
        ch[j][i] = CrossHair(j,i)
      
        intersects = [float(k) for k in rawIntersects.split()]
        ch[i][j].t = intersects[0]
        ch[j][i].t = intersects[1]
        
        pi = cmds.pointOnCurve(cs[i].name, pr=ch[i][j].t, p=True)        
        ch[i][j].pos = np.array(pi)  # save
        ch[j][i].pos = np.array(pi)
        #cmds.spaceLocator(p=pi)   # place locator        
        
        t_ij = cmds.pointOnCurve(cs[i].name, pr=ch[i][j].t, nt=True)
        ch[i][j].tan = np.array(t_ij)
        
        t_ji = cmds.pointOnCurve(cs[j].name, pr=ch[j][i].t, nt=True)
        ch[j][i].tan = np.array(t_ji)
        
        
        print "(%s,%s) processed" % (i, j)
        
        chNum += 1
        
      else:
        print "(%s,%s) no intersect" % (i, j)
  
  # clear all selection
  mel.eval("select -cl")

  # store sorted list of ch for each cs
  for i in range(csNum):
    for j in range(csNum):
      if ch[i][j] is not None:
        cs[i].ch.append(ch[i][j])
        
    cs[i].ch = sorted(cs[i].ch, key=lambda ch: ch.t)