コード例 #1
0
ファイル: keep.py プロジェクト: i5anoff/ProceduralCastle
def divide(parent, size, iter):
  # choose either X or Z axis
  axis = random.choice([HOU.Vector3(1,0,0), HOU.Vector3(0,0,1)])
  
  if (size[0] > size[2]):
    axis = HOU.Vector3(1,0,0)
  else:
    axis = HOU.Vector3(0,0,1)

  
  # get the length of the axis and find an integer split
  axisLength = axis.dot(size)
  dist = round(0.5 * axisLength)
  u = dist / axisLength

  if (u == 0 or u == 1):
    return dontkeep(parent, size, iter)

  # Take current parent shape and split into 2 bins
  shapes = split.splitn(axis, 2, [u], split.Shape(center=parent.position(), size=size))

  for shape in shapes:
    s = split.Shape(center=shape.center, size=shape.size)
    newHeight = round(random.uniform(0.6, 1.2) * s.size[1])
    # s.size[1] = newHeight

    # create a new point, from the shape, copying attributes from the parent
    p = common.createPoint(parent)
    p.setPosition(s.center - HOU.Vector3(0, s.size[1] / 2, 0) + HOU.Vector3(0, newHeight / 2, 0))
    # p.setPosition(s.center)
    s.size[1] = newHeight
    p.setAttribValue("size", s.size)
    p.setAttribValue("type", "keep")

  GEO.deletePoints([parent])
コード例 #2
0
def divide(parent, size, iter):
    shapes = split.splitn(HOU.Vector3(0, 1, 0), 2, [0.5],
                          split.Shape(center=parent.position(), size=size))

    bottom = shapes[0]
    top = shapes[1]

    parent.setAttribValue("active", 0)
コード例 #3
0
ファイル: arch.py プロジェクト: i5anoff/ProceduralCastle
def makeArch(parent, size, iter):
    # if point.attribValue("type")
    if (size[0] > size[2]):
        axis = HOU.Vector3(1, 0, 0)
    else:
        axis = HOU.Vector3(0, 0, 1)

    axisLength = axis.dot(size)
    dist = round(0.5 * axisLength)
    u = dist / axisLength

    if (axisLength < 4):
        return

    shapes = split.splitn(axis, 2, [u],
                          split.Shape(center=parent.position(), size=size))

    tmp_points = []
    for shape in shapes:
        s = split.Shape(center=shape.center, size=shape.size)
        newHeight = round(random.uniform(0.6, 1.2) * s.size[1])
        # s.size[1] = newHeight

        # create a new point, from the shape, copying attributes from the parent
        p = common.createPoint(parent)
        p.setPosition(s.center - HOU.Vector3(0, s.size[1] / 2, 0) +
                      HOU.Vector3(0, newHeight / 2, 0))
        # p.setPosition(s.center)
        s.size[1] = newHeight
        p.setAttribValue("size", s.size - axis * 0.5)
        p.setAttribValue("type", "terminal_keep")
        tmp_points.append(p)

    tmp_points[0].setPosition(tmp_points[0].position() - axis * 0.25)
    tmp_points[1].setPosition(tmp_points[1].position() + axis * 0.25)

    min_height = min(tmp_points[0].attribValue('size')[1],
                     tmp_points[1].attribValue('size')[1])
    arch = common.createPoint(parent)
    arch.setAttribValue("size", HOU.Vector3(1, min_height, 1))
    arch.setPosition(
        HOU.Vector3(
            tmp_points[0].position()[0] +
            (tmp_points[0].attribValue('size')[0] / 2 + 0.5) * axis[0],
            parent.position()[1] - size[1] / 2 + min_height / 2,
            tmp_points[0].position()[2] +
            (tmp_points[0].attribValue('size')[2] / 2 + 0.5) * axis[2]))
    arch.setAttribValue("type", "arch_tower")

    N = GEO.findPointAttrib("N")
    arch.setAttribValue(N, axis)

    GEO.deletePoints([parent])
コード例 #4
0
ファイル: keep.py プロジェクト: i5anoff/ProceduralCastle
def tower(parent, size, iter):
  axis = HOU.Vector3(0,1,0)

  # get the length of the axis and find an integer split
  axisLength = axis.dot(size)
  dist = round(0.5 * axisLength)
  u = dist / axisLength

  if size[0]*size[2] > 30:
    return

  # Take current parent shape and split into 2 bins
  shapes = split.splitn(axis, 2, [u], split.Shape(center=parent.position(), size=size))

  for s_idx in range(len(shapes)):
    shape = shapes[s_idx]
    s = split.Shape(center=shape.center, size=shape.size)

    # create a new point, from the shape, copying attributes from the parent
    p = common.createPoint(parent)

    if s_idx == 0:
      p.setPosition(s.center)
      p.setAttribValue("size", s.size)
      p.setAttribValue("type", "tower_lower")
    else:
      p.setAttribValue("type", "tower_upper")

      ratio = size[0] / size[2]
      if (0.8 < ratio and ratio < 1.2):
        s.size[0] = int(s.size[0] * 0.75)
        s.size[2] = int(s.size[2] * 0.75)
        p.setAttribValue("size", s.size)
        p.setPosition(s.center)
      else:
        if (size[0] > size[2]):
          s.center[0] -= size[0]/4
          s.size[0] /= 2
        else:
          s.center[2] -= size[2]/4
          s.size[2] /= 2
        
        s.size[0] = int(s.size[0] * 0.75)
        s.size[2] = int(s.size[2] * 0.75)

        p.setAttribValue("size", s.size)
        p.setPosition(s.center)

  GEO.deletePoints([parent])
コード例 #5
0
def spire(parent, size, iter):
    SPIRE_WIDTH = 2
    N = GEO.findPointAttrib("N")
    if (size[0] > SPIRE_WIDTH and size[2] > SPIRE_WIDTH
            and not parent.attribValue('hasSpire')):

        xaxis = HOU.Vector3(1, 0, 0)
        yaxis = HOU.Vector3(0, 1, 0)
        zaxis = HOU.Vector3(0, 0, 1)

        if (size[0] > size[2]):
            axes = [xaxis, zaxis]
        else:
            axes = [zaxis, xaxis]

        axis1Length = axes[0].dot(size)
        u1 = random.choice([
            SPIRE_WIDTH / axis1Length,
            (axis1Length - SPIRE_WIDTH) / axis1Length
        ])

        axis2Length = axes[1].dot(size)
        u2 = random.choice([
            SPIRE_WIDTH / axis2Length,
            (axis2Length - SPIRE_WIDTH) / axis2Length
        ])

        shapes = split.splitn(axes[0], 2, [u1],
                              split.Shape(center=parent.position(), size=size))

        side2 = 1 - int(u2 == SPIRE_WIDTH / axis2Length)

        if (u1 == SPIRE_WIDTH / axis1Length):  # spire is on the -x side
            shapes[0] = split.splitn(axes[1], 2, [u2], shapes[0])[side2]
            spireBlock = shapes[0]
            boxBlock = shapes[1]
        else:  # spire is on the +x side
            shapes[1] = split.splitn(axes[1], 2, [u2], shapes[1])[side2]
            boxBlock = shapes[0]
            spireBlock = shapes[1]

        # get the length of the axis and find an integer split
        axisyLength = yaxis.dot(size)
        dist = round(0.5 * axisyLength)
        u3 = dist / axisyLength

        # Take current parent shape and split into 2 bins
        boxShapes = split.splitn(yaxis, 2, [u3], boxBlock)
        spireShapes = split.splitn(yaxis, 2, [u3], spireBlock)

        p1 = common.createPoint(parent)
        p1.setPosition(boxShapes[0].center)
        p1.setAttribValue("size", boxShapes[0].size)
        # p1.setPosition(boxBlock.center)
        # p1.setAttribValue("size", boxBlock.size)
        p1.setAttribValue("active", 0)
        p1.setAttribValue("hasSpire", 1)

        # p2 = common.createPoint(parent)
        # p2.setPosition(boxShapes[1].center)
        # p2.setAttribValue("size", boxShapes[1].size)
        # p2.setAttribValue("type", "tower_lower")

        p3 = common.createPoint(parent)
        p3.setPosition(spireShapes[0].center)
        p3.setAttribValue("size", spireShapes[0].size)
        p3.setAttribValue("type", "spire_lower")

        p4 = common.createPoint(parent)
        p4.setPosition(spireShapes[1].center)
        p4.setAttribValue("size", spireShapes[1].size)
        p4.setAttribValue("type", "spire_upper")

        norm = -axes[0]
        if (u1 == SPIRE_WIDTH / axis1Length):
            norm = -norm
        p3.setAttribValue(N, norm)
        p4.setAttribValue(N, norm)

        GEO.deletePoints([parent])
コード例 #6
0
ファイル: initial.py プロジェクト: i5anoff/ProceduralCastle
def initializeGroups(parent, size, iter):
    center = HOU.Vector3(GEO.points()[0].attribValue("origin"))
    center[1] = 0
    furthest = min(size[0], size[1]) / 2
    
    # count = random.randint(MIN, MAX)
    # xshapes = split.splitn(HOU.Vector3(1,0,0), count, [random.choice([0.25, 0.5, 0.75]) for x in range(count)], split.Shape(center=parent.position(), size=size))
    # for xshape in xshapes:

    #     count = random.randint(MIN, MAX)
    #     zshapes = split.splitn(HOU.Vector3(0,0,1), count, [random.random() for x in range(count)], xshape)
    #     for zshape in zshapes:

    #         u = random.random()

    #         shape_center = zshape.center
    #         shape_center[1] = 0
    #         dist = center.distanceTo(shape_center)

    #         u = 1 - dist / furthest + random.uniform(-0.2, 0.2)

    #         if u < 0.1:
    #             continue
    #         newHeight = zshape.size[1] * u
    #         newsize = HOU.Vector3(zshape.size)
    #         newsize[1] = newHeight
    #         yshape = split.Shape(center=zshape.center + HOU.Vector3(0,newHeight/2,0), size=newsize)

    #         p = common.createPoint(parent)
    #         p.setPosition(yshape.center)
    #         p.setAttribValue("size", yshape.size)

    #         if yshape.size[1] < HEIGHT0:
    #             p.setAttribValue("type", "level0")
    #         else:
    #             p.setAttribValue("type", "tall")

    def spawnBox(parentsize, parentCenter):
        u = random.random()
        newHeight = size[1] * u
        newsize = HOU.Vector3(parentsize)
        newsize[1] = newHeight
        s = split.Shape(center=parentCenter + HOU.Vector3(0,newHeight/2,0), size=newsize)

        p = common.createPoint(parent)
        p.setPosition(s.center)
        p.setAttribValue("size", s.size)
        p.setAttribValue("type", "level0")

    axis = random.choice([HOU.Vector3(1,0,0), HOU.Vector3(0,0,1)])
    axisLength = axis.dot(size)
    dist = round(0.5 * axisLength)
    u = dist / axisLength

    # If we get to the point where our bins are too small, stop and spawn boxes.
    if u == 1 or u == 0:
        spawnBox(size, parent.position())
        parent.setAttribValue("active", 0)
        return

    # Take current parent shape and split into n bins
    shapes = split.splitn(axis, 2, [u], split.Shape(center=parent.position(), size=size))

    # for each shape 
    for shape in shapes:
        # If we've hit the iteration cap, stop recursing and spawn box, randomizing height
        if iter > 2:
            spawnBox(shape.size, shape.center)

        # Otherwise split more 
        else:
            s = split.Shape(center=shape.center, size=shape.size)
            p2 = common.createPoint(parent)
            p2.setPosition(s.center)
            p2.setAttribValue("size", s.size)
            p2.setAttribValue("type", "initial")

        
        
        
        
        # if random.random() > 0.9:
            
        # else:
        #     p.setAttribValue("type", "level0")


    parent.setAttribValue("active", 0)