sghr / iGeo

iGeo: Computational Design and 3D Modeling Library for Processing
http://igeo.jp
GNU Lesser General Public License v3.0
146 stars 34 forks source link

IGeo with P3D #23

Open co-ord opened 4 years ago

co-ord commented 4 years ago

Dear @sghr ,

I would like to use some of the classes of IGeo with the P3D renderer in draw(), is that possible ?

For instance, could I turn this sketch (IG.GL with Python mode)...:

add_library('igeo')

def setup():
    size(1000,600,IG.GL)

    for i in xrange(25):
        MyBoid(IRand.pt(-300,-300,0,300,300,0), IRand.pt(-10,-10,-20,10,10,-20))

    curl = ICompoundField().target(MyBoid)
    attr = ICompoundField().target(MyBoid)

    for i in xrange(10):
        pt = IRand.pt(-100,-100,-800,100,100,-100)
        curl.add(IPointCurlField(pt, IVec(0,0,-1)).intensity(20))
        attr.add(IAttractor(pt).intensity(20))

    IGravity(0,0,-2)

class MyBoid(IBoidTrajectory):
    def __init__(self, p, v):
        super(MyBoid, self).__init__(p, v)
        self.alignment(0, 0)
        self.cohesion(2, 40)
        self.separation(4, 50)
        self.fric(0.01)

... into something like this (P3D with draw()):

add_library('igeo')

def setup():
    size(1000,600,P3D)

    global boids

    boids = [] #appending MyBoid object to a list
    for i in xrange(25):
        b = MyBoid(IRand.pt(-300,-300,0,300,300,0), IRand.pt(-10,-10,-20,10,10,-20))
        boids.append(b)

    curl = ICompoundField().target(boids) #???? or something equivalent
    attr = ICompoundField().target(boids) #???? or something equivalent

    for i in xrange(10):
        pt = IRand.pt(-100,-100,-800,100,100,-100)
        curl.add(IPointCurlField(pt, IVec(0,0,-1)).intensity(20))
        attr.add(IAttractor(pt).intensity(20))

    IGravity(0,0,-2)

def draw():
    background(255)

    for b in boids:
        b.update() #???? or something equivalent
        point(b.pos().x(), b.pos().y(), b.pos().z()) 

class MyBoid(IBoidTrajectory):
    def __init__(self, p, v):
        super(MyBoid, self).__init__(p, v)
        self.alignment(0, 0)
        self.cohesion(2, 40)
        self.separation(4, 50)
        self.fric(0.01)

Respectfully,

solub