def getCurveSegmentLength(self): pointA = Vector3( cmds.pointPosition(self.curveName + '.cv[0]')[0], cmds.pointPosition(self.curveName + '.cv[0]')[1], cmds.pointPosition(self.curveName + '.cv[0]')[2]) pointB = Vector3( cmds.pointPosition(self.curveName + '.cv[1]')[0], cmds.pointPosition(self.curveName + '.cv[1]')[1], cmds.pointPosition(self.curveName + '.cv[1]')[2]) return Vector3.getDistanceBetweenTwoPoints(pointA, pointB)
def createSegmentsWalls(self, wallName): wallsSegmentNames = [] segmentLength = self.getCurveSegmentLength() wallsNeeded = int(math.ceil(segmentLength / self.getWallSize().x)) spawnPointA = Vector3( cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[0], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[1], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[2]) spawnPointB = Vector3( cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution - 1) + ']')[0], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution - 1) + ']')[1], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution - 1) + ']')[2]) for i in range(0, self.resolution): #Create a segment of wall for j in range(0, wallsNeeded): spawnWallPosition = Vector3( spawnPointA.x - (spawnPointA.x - spawnPointB.x) * j / wallsNeeded - (spawnPointA.x - spawnPointB.x) / wallsNeeded / 2, 0, spawnPointA.z - (spawnPointA.z - spawnPointB.z) * j / wallsNeeded - (spawnPointA.z - spawnPointB.z) / wallsNeeded / 2) wall = self.createWall( spawnWallPosition, Vector3( 0.0, float(self.apertureAngle / 2.0 + (360.0 - self.apertureAngle) / self.resolution / 2), 0.0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n=wallName + str(self.wallsSegmentIndex)) cmds.xform(wallName + str(self.wallsSegmentIndex), piv=(0, 0, 0)) wallsSegmentNames = [] cmds.rotate(0, float((360.0 - self.apertureAngle) / self.resolution * i), 0, wallName + str(self.wallsSegmentIndex), p=(self.center.x, self.center.y, self.center.z)) self.IncrementWallsSegmentIndex()
class OuterDoor(Door): #Valeur indicative à modifier en fonction des assets doorSize = Vector3(80.0, 20.0, 30.0) def __init__(self, position, rotation): super(OuterDoor, self).__init__('outer_door') if (cmds.objExists("ASSET_Porte_ext:porte_exter")): self.door = cmds.duplicate("ASSET_Porte_ext:porte_exter", n='outer_door') else: self.door = cmds.polyCube(w=self.doorSize.x, h=self.doorSize.y, d=self.doorSize.z, n="outer_door") #cmds.xform('outer_door',piv=(0,-self.doorSize.y/2,0)) self.locatorLeft = cmds.spaceLocator( p=(-self.doorSize.x / 2, cmds.getAttr("outer_door.translateY"), 0), n='outer_door_locator_left') self.locatorRight = cmds.spaceLocator( p=(self.doorSize.x / 2, cmds.getAttr("outer_door.translateY"), 0), n='outer_door_locator_right') cmds.group(('outer_door', 'outer_door_locator_left', 'outer_door_locator_right'), n=self.groupName) cmds.xform(self.groupName, piv=cmds.getAttr("outer_door.translate")[0]) cmds.move(position.x, position.y, position.z, self.groupName) cmds.rotate(rotation.x, rotation.y, rotation.z, self.groupName) return
class OuterWall(Wall): wallSize = Vector3(20, 15, 2) if (not cmds.objExists("outer_wall_template")): if (cmds.objExists("ASSET_Muraille_ext_mur:Muraille_ext")): template = cmds.duplicate("ASSET_Muraille_ext_mur:Muraille_ext", n="outer_wall_template") else: template = cmds.polyCube(w=wallSize.x, h=wallSize.y, d=wallSize.z, n="outer_wall_template") cmds.hide("outer_wall_template") else: template = cmds.ls("outer_wall_template") def __init__(self, position, rotation): cmds.instance(self.template, n="outer_wall_" + str(self.index)) cmds.showHidden("outer_wall_" + str(self.index)) #cmds.xform("outer_wall_" + str(self.index),piv=(0,-self.wallSize.y/2,0)) cmds.move(position.x, position.y, position.z, "outer_wall_" + str(self.index)) cmds.rotate(rotation.x, rotation.y, rotation.z, "outer_wall_" + str(self.index)) super(OuterWall, self).__init__("outer_wall_" + str(self.index)) self.IncementWallIndex() return
def createDoorWalls(self, sideDoorPoint, curveExtremityPoint, wallGroupName, curveName): wallsSegmentNames = [] segmentLength = Vector3.getDistanceBetweenTwoPoints( sideDoorPoint, curveExtremityPoint) #Get amont of wall we need wallsNeeded = int(math.ceil(segmentLength / self.getWallSize().x)) #curve = cmds.curve(p=[(sideDoorPoint.x,sideDoorPoint.y,sideDoorPoint.z),(curveExtremityPoint.x,curveExtremityPoint.y,curveExtremityPoint.z)],d=1,n=curveName) vec1 = Vector3(sideDoorPoint.x, sideDoorPoint.y, self.center.z) - sideDoorPoint vec2 = curveExtremityPoint - sideDoorPoint angle = Vector3.getAngleBetweenVector(vec1, vec2) spawnPointA = sideDoorPoint spawnPointB = curveExtremityPoint for j in range(0, wallsNeeded): spawnWallPosition = Vector3( spawnPointA.x - (spawnPointA.x - spawnPointB.x) * j / wallsNeeded - (spawnPointA.x - spawnPointB.x) / wallsNeeded / 2, spawnPointA.y - (spawnPointA.y - spawnPointB.y) * j / wallsNeeded - (spawnPointA.y - spawnPointB.y) / wallsNeeded / 2, spawnPointA.z - (spawnPointA.z - spawnPointB.z) * j / wallsNeeded - (spawnPointA.z - spawnPointB.z) / wallsNeeded / 2) yRotation = 0.0 if sideDoorPoint.x > curveExtremityPoint.x: yRotation = -90.0 + angle else: yRotation = 90.0 - angle wall = self.createWall(spawnWallPosition, Vector3(0.0, yRotation, 0.0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n=wallGroupName) cmds.xform(wallGroupName, piv=(0, 0, 0)) self.IncrementWallsSegmentIndex()
def createTowers(self): #Array of tower's name to select them and positionAlongCurve towerNames = [] for i in range(0, self.towerAmount): tower = Tower(Vector3(0, 0, 0)) self.towers.append(tower) towerNames.append(tower.name) Tower.IncementTowerIndex() #Select towers then curve to positionAlongCurve cmds.select(towerNames) cmds.select(self.curveName, add=True) mayaGeneral.positionAlongCurve.positionAlongCurve()
def __init__(self, resolution, apertureAngle, wallHeight, wallDepth, radius, center): self.resolution = resolution self.wallHeight = wallHeight self.wallDepth = wallDepth self.center = center self.radius = radius self.apertureAngle = apertureAngle self.halfHoleVector = Vector3(0, 0, 0) self.walls = [] self.wallsSegmentIndex = 0 self.curveName = "" self.curve = ""
class OuterWall(Wall): index = 0 wallSize = Vector3(20, 10, 5) template = cmds.polyCube(w=wallSize.x, h=wallSize.y, d=wallSize.z, n="outer_wall_template") cmds.hide("outer_wall_template") def __init__(self, position, rotation): cmds.instance(self.template, n="outer_wall_" + str(self.index)) cmds.showHidden("outer_wall_" + str(self.index)) cmds.move(position.x, position.y + self.wallSize.y / 2, position.z, "outer_wall_" + str(self.index)) cmds.rotate(rotation.x, rotation.y, rotation.z, "outer_wall_" + str(self.index)) super(OuterWall, self).__init__("outer_wall_" + str(self.index)) self.IncementWallIndex() @classmethod def IncementWallIndex(cls): cls.index += 1
def instantiateRampartCurveBased(self): super(InteriorRampart, self).instantiateRampartCurveBased('InteriorRampart_curve') #Step 4 : Create Towers self.createTowers() #Step 5 : Create Door doorPosition = Vector3(self.center.x, self.center.y, self.radius) self.door = Doors.InnerDoor(doorPosition, Vector3(0, 0, 0)) #Step 6 : Create side door walls #Left leftSideDoorPositionList = cmds.getAttr(self.door.locatorLeft[0] + '.worldPosition')[0] leftSideDoorPosition = Vector3(leftSideDoorPositionList[0], leftSideDoorPositionList[1], leftSideDoorPositionList[2]) leftExtremityCurve = Vector3( cmds.pointPosition(self.curveName + '.cv[0]')[0], cmds.pointPosition(self.curveName + '.cv[0]')[1], cmds.pointPosition(self.curveName + '.cv[0]')[2]) self.createDoorWalls(leftSideDoorPosition, leftExtremityCurve, "left_in_side_door_walls", "left_in_side_door_curve") #Right rightSideDoorPositionList = cmds.getAttr(self.door.locatorRight[0] + '.worldPosition')[0] rightSideDoorPosition = Vector3(rightSideDoorPositionList[0], rightSideDoorPositionList[1], rightSideDoorPositionList[2]) rightExtremityCurve = Vector3( cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[0], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[1], cmds.pointPosition(self.curveName + '.cv[' + str(self.resolution) + ']')[2]) self.createDoorWalls(rightSideDoorPosition, rightExtremityCurve, "right_in_side_door_walls", "right_in_side_door_curve") #Step 7 : Group all self.groupRampart([ self.curveName, self.towersGroupName, self.wallsGroupName, self.door.groupName, "left_in_side_door_walls", "right_in_side_door_walls" ], self.groupName)
class Castle: def __init__(self, interiorRampart, exteriorRampart, groundRampart): groupNames = [] self.interiorRampart = interiorRampart self.exteriorRampart = exteriorRampart self.groundRampart = groundRampart self.interiorRampart.instantiateRampartCurveBased() groupNames.append(self.interiorRampart.groupName) self.exteriorRampart.instantiateRampartCurveBased() groupNames.append(self.exteriorRampart.groupName) self.groundRampart.instantiateRampartCurveBased() groupNames.append(self.groundRampart.groupName) self.name = cmds.group(groupNames, n="Castle") if (cmds.objExists("Castle")): cmds.select("Castle") cmds.delete() interiorRampart = Ramparts.InteriorRampart(8, 60.0, 0.5, 0.5, 80, Vector3(0, 10, 0), 9) exteriorRampart = Ramparts.ExteriorRampart(8, 60.0, 0.5, 0.5, 140, Vector3(0, 0, 0)) groundRampart = Ramparts.GroundRampart(12, 0.0, 0.5, 0.5, 90, Vector3(0, 10, 0), 10) castle = Castle(interiorRampart, exteriorRampart, groundRampart) cmds.editDisplayLayerMembers(rampartsLayer, 'Castle')
def instantiateRampartTrigo(self): # Amount of walls needed on doors side doorWallsNeeded = int( math.ceil( (self.getSegmentLength() / 2 - self.opertureVector.magnitude) / OuterWall.wallSize.x)) # WallRotation in radians wallAngle = math.degrees( (self.resolution - 2) * math.pi / self.resolution) # Calculate the length of a side : a = 2R sin(pi/r) sideLength = 2 * self.radius * math.sin(math.pi / self.resolution) # Array of points to draw the curve pointsArray = [] # Get two adjacents points on curve to create walls on xFirst = self.center.x + self.radius * math.cos(math.radians(0)) xLast = self.center.x + self.radius * math.cos( math.radians(360 * (self.resolution - 1) / self.resolution)) yFirst = self.center.z + self.radius * math.sin(math.radians(0)) yLast = self.center.z + self.radius * math.sin( math.radians(360 * (self.resolution - 1) / self.resolution)) for i in range(0, self.resolution): # Get coordinates of polygon's intersections xFirstIntersection = self.center.x + self.radius * math.cos( math.radians(360 * i / self.resolution)) yFirstIntersection = self.center.z + self.radius * math.sin( math.radians(360 * i / self.resolution)) if i == 0: wallsSegmentNames = [] # At the begining of the curve, we create the little wall next to the door xOpposite = self.center.x + self.radius * math.cos( math.radians(360 * (self.resolution - 1) / self.resolution)) yOpposite = self.center.z + self.radius * math.sin( math.radians(360 * (self.resolution - 1) / self.resolution)) xSideGate = xFirstIntersection + ( xOpposite - xFirstIntersection) / 2 - self.opertureVector.x ySideGate = yFirstIntersection + ( yOpposite - yFirstIntersection) / 2 - self.opertureVector.z for j in range(0, doorWallsNeeded): spawnWallPosition = Vector3( xSideGate - (xSideGate - xFirst) * j / doorWallsNeeded - (xSideGate - xFirst) / doorWallsNeeded / 2, 0, ySideGate - (ySideGate - yFirst) * j / doorWallsNeeded - (ySideGate - yFirst) / doorWallsNeeded / 2) wall = OuterWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="outer_walls_" + str(self.wallsSegmentIndex)) self.IncrementWallsSegmentIndex() pointsArray.append((xSideGate, 0, ySideGate)) pointsArray.append((xFirstIntersection, 0, yFirstIntersection)) # If we are not on the last segment where we build the entrance, create walls if i != (self.resolution - 1): wallsSegmentsNames = [] for j in range(0, self.wallsPerSegment): spawnWallPosition = Vector3( xFirst - (xFirst - xLast) * j / self.wallsPerSegment - (xFirst - xLast) / self.wallsPerSegment / 2, 0, yFirst - (yFirst - yLast) * j / self.wallsPerSegment - (yFirst - yLast) / self.wallsPerSegment / 2) wall = OuterWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentsNames.append(wall.name) cmds.group(wallsSegmentsNames, n="outer_walls_" + str(self.wallsSegmentIndex)) cmds.rotate(0, 360.0 * (i + 1) / self.resolution, 0, "outer_walls_" + str(self.wallsSegmentIndex), p=self.center) self.IncrementWallsSegmentIndex() # At the end of the curve, we create the little wall next to the door if i == (self.resolution - 1): wallsSegmentsNames = [] xOpposite = self.center.x + self.radius * math.cos( math.radians(0)) yOpposite = self.center.z + self.radius * math.sin( math.radians(0)) xSideGate = xFirstIntersection + ( xOpposite - xFirstIntersection) / 2 + self.opertureVector.x ySideGate = yFirstIntersection + ( yOpposite - yFirstIntersection) / 2 + self.opertureVector.z print("j'ai besoin de :" + str(doorWallsNeeded)) for j in range(0, doorWallsNeeded): spawnWallPosition = Vector3( xSideGate - (xSideGate - xLast) * j / doorWallsNeeded - (xSideGate - xLast) / doorWallsNeeded / 2, 0, ySideGate - (ySideGate - yLast) * j / doorWallsNeeded - (ySideGate - yLast) / doorWallsNeeded / 2) wall = OuterWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="outer_walls_" + str(self.wallsSegmentIndex)) self.IncrementWallsSegmentIndex() pointsArray.append((xSideGate, 0, ySideGate)) cmds.curve(bez=False, p=pointsArray, d=1) print("instantiateRempart exterieur!")
def instantiateRampartTrigo(self): # WallRotation in radians wallAngle = math.degrees( (self.resolution - 2) * math.pi / self.resolution) # Calculate the length of a side : a = 2R sin(pi/r) sideLength = 2 * self.radius * math.sin(math.pi / self.resolution) xFirst = self.center.x + self.radius * \ math.cos(math.radians(0)) xLast = self.center.x + self.radius * \ math.cos(math.radians( 360 * (self.resolution-1)/self.resolution)) yFirst = self.center.z + self.radius * \ math.sin(math.radians(0)) yLast = self.center.z + self.radius * \ math.sin(math.radians( 360 * (self.resolution-1)/self.resolution)) pointsArray = [] doorWallsNeeded = int(math.ceil(self.wallsPerSegment / 3.0)) # Gates for i in range(0, self.resolution): # Get coordinates of polygon's intersections xFirstIntersection = self.center.x + self.radius * \ math.cos(math.radians(360 * i/self.resolution)) yFirstIntersection = self.center.z + self.radius * \ math.sin(math.radians(360 * i/self.resolution)) xNextIntersection = self.center.x + self.radius * \ math.cos(math.radians(360 * (i-1)/self.resolution)) yNextIntersection = self.center.z + self.radius * \ math.sin(math.radians(360 * (i-1)/self.resolution)) # At the begining of the curve, we create the little wall next to the door if i == 0: wallsSegmentNames = [] xOpposite = self.center.x + self.radius * math.cos( math.radians(360 * (self.resolution - 1) / self.resolution)) yOpposite = self.center.z + self.radius * math.sin( math.radians(360 * (self.resolution - 1) / self.resolution)) xSideGate = xFirstIntersection + \ (xOpposite - xFirstIntersection)/3 ySideGate = yFirstIntersection + \ (yOpposite - yFirstIntersection)/3 pointsArray.append((xSideGate, 0, ySideGate)) self.setHalfHoleVector( Vector3((xOpposite - xFirstIntersection) / 6, 0, (yOpposite - yFirstIntersection) / 6)) for j in range(0, doorWallsNeeded): spawnWallPosition = Vector3( xSideGate - (xSideGate - xFirst) * j / doorWallsNeeded - (xSideGate - xFirst) / doorWallsNeeded / 2, 0, ySideGate - (ySideGate - yFirst) * j / doorWallsNeeded - (ySideGate - yFirst) / doorWallsNeeded / 2, ) wall = InnerWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="inner_walls_" + str(self.wallsSegmentIndex)) self.IncrementWallsSegmentIndex() pointsArray.append((xFirstIntersection, 0, yFirstIntersection)) towerPosition = Vector3(xFirstIntersection, 0, yFirstIntersection) self.intersectionPoints.append(towerPosition) self.towers.append(Tower(towerPosition)) if i != (self.resolution - 1): wallsSegmentNames = [] for j in range(0, self.wallsPerSegment): spawnWallPosition = Vector3( xFirst - (xFirst - xLast) * j / self.wallsPerSegment - (xFirst - xLast) / self.wallsPerSegment / 2, 0, yFirst - (yFirst - yLast) * j / self.wallsPerSegment - (yFirst - yLast) / self.wallsPerSegment / 2, ) wall = InnerWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="inner_walls_" + str(self.wallsSegmentIndex)) cmds.rotate(0, 360.0 * (i + 1) / self.resolution, 0, "inner_walls_" + str(self.wallsSegmentIndex), p=self.center) self.IncrementWallsSegmentIndex() if i == (self.resolution - 1): wallsSegmentNames = [] # At the end of the curve, we create the little wall next to the door xOpposite = self.center.x + \ self.radius * math.cos(math.radians(0)) xSideGate = xFirstIntersection + \ (xOpposite - xFirstIntersection)/3 yOpposite = self.center.z + \ self.radius * math.sin(math.radians(0)) ySideGate = yFirstIntersection + \ (yOpposite - yFirstIntersection)/3 pointsArray.append((xSideGate, 0, ySideGate)) for j in range(0, doorWallsNeeded): spawnWallPosition = Vector3( xSideGate - (xSideGate - xLast) * j / doorWallsNeeded - (xSideGate - xLast) / doorWallsNeeded / 2, 0, ySideGate - (ySideGate - yLast) * j / doorWallsNeeded - (ySideGate - yLast) / doorWallsNeeded / 2, ) wall = InnerWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="inner_walls_" + str(self.wallsSegmentIndex)) self.IncrementWallsSegmentIndex() cmds.curve(bez=False, p=pointsArray, d=1) return
ySideGate - (ySideGate - yLast) * j / doorWallsNeeded - (ySideGate - yLast) / doorWallsNeeded / 2) wall = OuterWall(spawnWallPosition, Vector3(0, -wallAngle / 2, 0)) self.walls.append(wall) wallsSegmentNames.append(wall.name) cmds.group(wallsSegmentNames, n="outer_walls_" + str(self.wallsSegmentIndex)) self.IncrementWallsSegmentIndex() pointsArray.append((xSideGate, 0, ySideGate)) cmds.curve(bez=False, p=pointsArray, d=1) print("instantiateRempart exterieur!") internalRampart = InteriorRampart(8, 60.0, 0.5, 0.5, 60, Vector3(0, 0, 0), 4) internalRampart.instantiateRempartCurveBased() externalRampart = ExteriorRampart(8, 60, 0.5, 0.5, 100, Vector3(0, 0, 0), internalRampart.halfHoleVector) externalRampart.instantiateRempartCurveBased() #Interface de fortune # window = c.window() # c.window(t="Generateur de temple", widthHeight=(800, 600)) # c.columnLayout(adj=True, cal='left', cw=50, w=400, # co=('both', 25), bgc=[0.1, 0.3, 0.5]) # c.text("-- Creation de temple --", h=50, al='center') # c.rowLayout(nc=7, co1=200)
def createWall(self, spawnPos, rotation): #return Walls.GroundWall(Vector3(spawnPos.x,spawnPos.y - Walls.GroundWall.wallSize.y,spawnPos.z),rotation) return Walls.GroundWall(Vector3(spawnPos.x, spawnPos.y, spawnPos.z), rotation)