コード例 #1
0
ファイル: octahedron.py プロジェクト: HadibOo/Forms
    def generate( self, radius = 10, iterations = 1 ):
        
        self.radius     = radius
        self.iterations = iterations
        
        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.radius, self.iterations ) )

        octahedronRadius = float(self.radius) / util.pow( float(2), float(self.iterations ) )
        octahedron       = self.mesh( radius = octahedronRadius )
        octahedra        = [ octahedron ]
        
        pm.polySoftEdge( angle = 0 )   

        octahedronHeight = octahedron[ 1 ].getSideLength() / util.sqrt( 2 )
    
        for i in range( iterations ):
            
            mesh = self.__generateMesh( octahedra[ 0 ], octahedronHeight, octahedronRadius, ( i + 1 ) )
            
            octahedronHeight *= 2            
            octahedronRadius *= 2            
            
            octahedra = [ mesh ]
        

        pm.xform( mesh[ 0 ], centerPivots = True )

        print( "Construction complete" )
        
        return mesh
コード例 #2
0
    def generate( self, size = 10, iterations = 1, grid = 3, holes = [ 4, 10, 12, 13, 14, 16, 22 ] ):

        self.size       = size
        self.iterations = iterations
        self.grid       = grid
        self.holes      = holes

        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.size, self.iterations ) )
    
        cubeSize = float(self.size) /  util.pow( float(self.grid), float(self.iterations) )
        cube     = self.mesh( width = cubeSize, height = cubeSize, depth = cubeSize )    
        cubes    = [ cube ]
        
        for i in range( iterations ):

            mesh     = self.__generateMesh( cubes[ 0 ], cubeSize, ( i + 1 ) )
            cubeSize = cubeSize * self.grid
            cubes    = [ mesh ]


        pm.xform( mesh[ 0 ], centerPivots = True )

        print( "Construction complete" )

        return mesh
コード例 #3
0
    def generate(self, radius=10, iterations=1):

        self.radius = radius
        self.iterations = iterations

        print("%s radius %f iterations %i" %
              (self.__class__.__name__, self.radius, self.iterations))

        octahedronRadius = float(self.radius) / util.pow(
            float(2), float(self.iterations))
        octahedron = self.mesh(radius=octahedronRadius)
        octahedra = [octahedron]

        pm.polySoftEdge(angle=0)

        octahedronHeight = octahedron[1].getSideLength() / util.sqrt(2)

        for i in range(iterations):

            mesh = self.__generateMesh(octahedra[0], octahedronHeight,
                                       octahedronRadius, (i + 1))

            octahedronHeight *= 2
            octahedronRadius *= 2

            octahedra = [mesh]

        pm.xform(mesh[0], centerPivots=True)

        print("Construction complete")

        return mesh
コード例 #4
0
    def __generateMesh( self, mesh, size, iteration ):

        instanceGroup   = pm.group( empty = True, name = "meshInstanceGroup" )
        
        instances = [ None ] * util.pow( self.grid, 3 )
        
        # Instance a sponge, position it, then add it to the group
        
        def makeInstance( levels, rows, columns, index ):

            x = ( size * 1 ) - ( rows * size )
            y = ( size * 1 ) - ( levels * size )
            z = ( size * 1 ) - ( columns * size )

            if index == 0:

                meshInstance = mesh

            else:

                meshInstance = pm.instance( mesh[ 0 ] )

            meshInstance[ 0 ].setTranslation( [ x, y, z ] )
            instances.append( meshInstance[ 0 ] )
        

        # Generate the sponge instances
        
        i = 0   
        j = 0   
        
        for levels in range( self.grid ):

            for rows in range( self.grid ):

                for columns in range( self.grid ):

                    if i not in self.holes:

                        makeInstance( levels, rows, columns, j ) 

                        j += 1

                    i += 1

        
        pm.parent( instances, instanceGroup, add = True )
        
        return combineClean( instanceGroup, "Sierpinski_Iteration_%i" % iteration, True )
コード例 #5
0
ファイル: tetrahedron.py プロジェクト: n1ckfg/Forms
    def generate( self, radius = 10, iterations = 1 ):
        
        self.radius     = radius
        self.iterations = iterations
        
        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.radius, self.iterations ) )

        tetrahedronRadius = float(self.radius) / util.pow( float(2), float(self.iterations ) )
        tetrahedron       = self.mesh( radius = tetrahedronRadius )
        tetrahedra        = [ tetrahedron ]

        pm.polySoftEdge( angle = 0 )
        
        sideLength        = tetrahedron[ 1 ].getSideLength()
        tetrahedronHeight = util.sqrt(6) / 3 * sideLength
        
        positions = [ ]

        for vertex in tetrahedron[ 0 ].vtx:

            position = vertex.getPosition()
            positions.append( dt.FloatVector( position ) );


        for i in range( iterations ):

            mesh = self.__generateMesh( tetrahedra[ 0 ], tetrahedronHeight, tetrahedronRadius, sideLength, positions, ( i + 1 ) )
            
            for j in range( len( positions ) ):
                
                positions[ j ] *= 2
            
            tetrahedronHeight = tetrahedronHeight * 2
            tetrahedronRadius = tetrahedronRadius * 2
            sideLength        = sideLength * 2
            
            tetrahedra = [ mesh ]
        

        print( "Construction complete" )

        return mesh
コード例 #6
0
ファイル: icosahedron.py プロジェクト: n1ckfg/Forms
    def generate(self, radius=10, iterations=1):

        self.radius = radius
        self.iterations = iterations

        print("%s radius %f iterations %i" %
              (self.__class__.__name__, self.radius, self.iterations))

        icosahedronRadius = float(self.radius) / util.pow(
            float(self.scaleRatio), float(self.iterations))
        icosahedron = self.mesh(radius=icosahedronRadius)
        icosahedra = [icosahedron]

        pm.polySoftEdge(angle=0)

        positions = []
        vertices = icosahedron[0].vtx

        for vertex in vertices:

            position = vertex.getPosition()
            positions.append(dt.FloatVector(position))

        for i in range(iterations):

            for j in range(len(positions)):

                positions[j] *= self.scaleRatio

            mesh = self.__generateMesh(icosahedra[0], positions,
                                       icosahedronRadius, (i + 1))

            icosahedronRadius *= self.scaleRatio

            icosahedra = [mesh]

        pm.xform(mesh[0], centerPivots=True)

        print("Construction complete")

        return mesh
コード例 #7
0
ファイル: icosahedron.py プロジェクト: HadibOo/Forms
    def generate( self, radius = 10, iterations = 1 ):
        
        self.radius     = radius
        self.iterations = iterations
        
        print( "%s radius %f iterations %i" % ( self.__class__.__name__, self.radius, self.iterations ) )

        icosahedronRadius = float(self.radius) / util.pow( float(self.scaleRatio), float(self.iterations) )
        icosahedron       = self.mesh( radius = icosahedronRadius )
        icosahedra        = [ icosahedron ]
        
        pm.polySoftEdge( angle = 0 )
        
        positions = [ ]
        vertices  = icosahedron[ 0 ].vtx

        for vertex in vertices:

            position = vertex.getPosition()
            positions.append( dt.FloatVector( position ) )

    
        for i in range( iterations ):

            for j in range( len( positions ) ):

                positions[ j ] *= self.scaleRatio
                
            mesh = self.__generateMesh( icosahedra[ 0 ], positions, icosahedronRadius, ( i + 1 ) )
            
            icosahedronRadius *= self.scaleRatio

            icosahedra = [ mesh ]


        pm.xform( mesh[ 0 ], centerPivots = True )

        print( "Construction complete" )

        return mesh