Example #1
0
 def UpdateDisplay(self):
     if self.id: sc.doc.Objects.Delete(self.id, True)
     
     
     if len(self.interPts) >= 3:
         r, plane = rg.Plane.FitPlaneToPoints(self.interPts)
         if r == rg.PlaneFitResult.Success:
             us = []
             vs = []
             for eachPt in self.interPts:
                 r, u, v = plane.ClosestParameter(eachPt)
                 us.append(u)
                 vs.append(v)
             
             uInt = rg.Interval(min(us), max(us))
             vInt = rg.Interval(min(vs), max(vs))
             
             planeSurface = rg.PlaneSurface(plane, uInt, vInt)
             self.id = sc.doc.Objects.AddBrep(planeSurface.ToBrep())
     
     
     if False:
         if len(self.belowVertices) > 0 and len(self.belowVertices) < 8:
             self.attr.ObjectColor = color.GradientOfColors(self.system.grad, util.Remap(len(self.belowVertices), 0, 8, 0, 1), 2)            
             
             index = sc.doc.Materials.Add()
             mat = sc.doc.Materials[index]
             mat.DiffuseColor = self.attr.ObjectColor
             mat.CommitChanges()
             self.attr.MaterialIndex = index
             
             xform = rg.Transform.Scale(self.centerPt, util.Remap(len(self.belowVertices), 1, 7, .1, 1))
             box = self.box.Duplicate()
             box.Transform(xform)
             self.id = sc.doc.Objects.AddMesh(box, self.attr)
Example #2
0
 def Update(self, time):
     self.acc *= 0
     futurePos = self.pos + self.vel
     
     self.val = self.system.pn.noise3(util.Remap(self.pos.X, 0, 100, 0, 1), util.Remap(self.pos.Y, 0, 100, 0, 1), time*.02)
     
     f = 1
     repulsion = 1
     if futurePos.X < self.size * f:
         distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(repulsion*distanceModifier,0,0)
     if futurePos.Y < self.size * f:
         distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(0,repulsion*distanceModifier,0)
     if futurePos.Z < self.size * f:
         distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(0,0,repulsion*distanceModifier)
     if futurePos.X > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.X, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(-repulsion*distanceModifier,0,0)
     if futurePos.Y > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.Y, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(0,-repulsion*distanceModifier,0)
     if futurePos.Z > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.Z, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(0,0,-repulsion*distanceModifier)
     
     self.vel += self.acc
     self.pos += self.vel
     
     self.pos = rg.Point3d(self.pos.X, self.pos.Y, util.Remap(self.val, -1, 1, 5, 55))
     
     
     for id in self.ids:
         sc.doc.Objects.Delete(id, True)
Example #3
0
    def __init__(self, mesh):
        self.attr = rc.DocObjects.ObjectAttributes()
        self.attr.ColorSource = rc.DocObjects.ObjectColorSource.ColorFromObject
        self.grad = color.GetGradient(4)
        self.attr.MaterialSource = rc.DocObjects.ObjectMaterialSource.MaterialFromObject
        self.mesh = mesh.Duplicate()
        self.meshOrig = mesh.Duplicate()
        self.ids = []
        self.vObjects = []
        self.targets = []
        for i in range(len(self.mesh.Vertices)):
            self.targets.append(i)

        for i, v in enumerate(self.mesh.Vertices):
            self.vObjects.append(vObject(self, v, i))

        self.sourceIndex = random.randint(0, len(self.mesh.Vertices))
        self.vObjects[self.sourceIndex].UpdateDisplay()

        while True:
            self.targetIndex = random.randint(0, len(self.mesh.Vertices))
            if self.targetIndex != self.sourceIndex: break
        self.path = None
        self.targets.Remove(self.sourceIndex)

        pn = perlin.SimplexNoise()
        for i, v in enumerate(self.mesh.Vertices):
            val = pn.noise2(util.Remap(v.X, 10, 90, 0, 3),
                            util.Remap(v.Y, 0, 50, 0, 3))
            vec = self.meshOrig.Normals[i]
            vec = rg.Vector3d(vec)
            vec *= val * 8
            xform = rg.Transform.Translation(vec)
            v.Transform(xform)
            self.mesh.Vertices[i] = v

        for i, v in enumerate(self.mesh.Vertices):
            val = pn.noise2(util.Remap(v.X, 10, 90, 0, 1),
                            util.Remap(v.Y, 0, 50, 0, 1))
            vec = self.meshOrig.Normals[i]
            vec = rg.Vector3d(vec)
            vec *= val * 20
            xform = rg.Transform.Translation(vec)
            v.Transform(xform)
            self.mesh.Vertices[i] = v
        sc.doc.Objects.AddMesh(self.mesh)

        sphere = rg.Sphere(self.vObjects[self.sourceIndex].vertex, 4)
        sc.doc.Objects.AddSphere(sphere)
Example #4
0
 def __init__(self):
     self.attr = util.BasicAttr()
     
     self.headID = r'941e5133-6d8f-4a2a-853f-f4d3588c3b95'
     self.mesh = rs.coercemesh(self.headID)
     
     self.pn = perlin.SimplexNoise()
     pt = rg.Point3d(10,60,80)
     vec = rg.Vector3d(0,-10, 10)
     plane = rg.Plane(pt, vec)
     xint = rg.Interval(0, 80)
     yint = rg.Interval(0, 80)
     xcount = 10
     ycount = 10
     #self.mesh = rg.Mesh.CreateFromPlane(plane, xint, yint, xcount, ycount)
     #self.meshOrig = self.mesh.Duplicate()
     
     if False:
         for i, v in enumerate(self.mesh.Vertices):
             val = self.pn.noise2(util.Remap(v.X, 10, 90, 0, 3), util.Remap(v.Y, 0, 50, 0, 3))
             vec = self.meshOrig.Normals[i]
             vec = rg.Vector3d(vec)
             vec *= val * 20
             xform = rg.Transform.Translation(vec)
             v.Transform(xform)
             self.mesh.Vertices[i] = v
         
         for i, v in enumerate(self.mesh.Vertices):
             val = self.pn.noise3(util.Remap(v.X, 10, 90, 0, 1), util.Remap(v.Y, 0, 50, 0, 1), 0)
             vec = self.meshOrig.Normals[i]
             vec = rg.Vector3d(vec)
             vec *= val * 30
             xform = rg.Transform.Translation(vec)
             v.Transform(xform)
             self.mesh.Vertices[i] = v
         
         
         
         for i, v in enumerate(self.mesh.Vertices):
             rand = geo.RandomVector3d(4)
             
             self.mesh.Vertices[i] += rg.Vector3f(rand.X, rand.Y, rand.Z)
         
     self.vObjects = []
     for i, v in enumerate(self.mesh.Vertices):
         self.vObjects.append(vObject(self, v, i))
         
     self.meshID = None
Example #5
0
    def Update(self, time):
        for id in self.ids:
            if id:
                sc.doc.Objects.Delete(id, True)
        self.time = time
        #################################
        attr = self.attr.Duplicate()
        grad = color.GetGradient(2)
        col1 = color.GradientOfColors(grad, util.Remap(self.time, 0, 150, 0,
                                                       1))
        attr.ObjectColor = col1

        attr.ObjectColor = col1
        index = sc.doc.Materials.Add()
        self.mat = sc.doc.Materials[index]
        self.mat.DiffuseColor = attr.ObjectColor
        self.mat.CommitChanges()
        attr.MaterialIndex = index

        safety = 0
        while True:
            safety += 1
            if safety > 20:
                print "Safety"
                break
            newParticle = Particle(self, rg.Point3d(50, 50, 80), attr)
            if newParticle.hit == False:
                self.particles.append(newParticle)
                break

        for particle in self.particles:
            particle.Update()
Example #6
0
    def UpdateDisplay(self):
        for pipeID in self.pipeIDs:
            sc.doc.Objects.Delete(pipeID, True)

        tempHistory = []
        for i, each in enumerate(self.history):
            tempVal = util.Remap(i, 0, 19, 0, 1)
            val = (math.cos(tempVal * 3) + 1.01) / 2
            mp = rg.AreaMassProperties.Compute(each)
            if i == 0:
                val = .01
            xform = rg.Transform.Scale(mp.Centroid, val)
            temp = each.Duplicate()
            #temp.Transform(xform)
            tempHistory.append(temp)

        if len(tempHistory) > 3:
            breps = rg.Brep.CreateFromLoft(tempHistory, rg.Point3d.Unset,
                                           rg.Point3d.Unset,
                                           rg.LoftType.Normal, False)
            if len(breps) > 0:
                self.pipe = breps[0]
                self.pipe = self.pipe.CapPlanarHoles(
                    sc.doc.ModelAbsoluteTolerance)
                self.pipeIDs.append(
                    sc.doc.Objects.AddBrep(self.pipe, self.attr))

        for id in self.ids:
            sc.doc.Objects.Delete(id, True)
Example #7
0
 def UpdateDisplay(self):
     self.attr.ObjectColor = color.GradientOfColors(self.grad, util.Remap(self.acc.Length, 0, .25, 0, 1))
     index = sc.doc.Materials.Add()
     self.mat = sc.doc.Materials[index]
     self.mat.DiffuseColor = self.attr.ObjectColor
     self.mat.CommitChanges()
     self.attr.MaterialIndex = index
Example #8
0
    def Update(self):
        self.vel += self.acc
        futurePos = self.pos + self.vel

        if futurePos.X < self.radius:
            self.vel.X *= -1
        if futurePos.Y < self.radius:
            self.vel.Y *= -1
        if futurePos.Z < self.radius:
            self.vel.Z *= -1
            #Friction
            self.vel *= .7
        if futurePos.X > 100 - self.radius:
            self.vel.X *= -1
        if futurePos.Y > 100 - self.radius:
            self.vel.Y *= -1
        if futurePos.Z > 100 - self.radius:
            self.vel.Z *= -1

        self.zSize = rg.Interval(
            0,
            util.Remap(self.vel.Length, 2, 5, self.radius * .125,
                       self.radius * 4))
        self.pos += self.vel
        #self.plane.Origin = self.pos
        self.plane = rg.Plane(self.pos, self.vel)
        self.box = rg.Box(self.plane, self.xSize, self.ySize, self.zSize)
        #self.sphere = rg.Sphere(self.pos, self.radius)

        sc.doc.Objects.Delete(self.boxID, True)
        self.boxID = sc.doc.Objects.AddBox(self.box, self.attr)
Example #9
0
    def MeshWindow(self):
        #sc.doc.Objects.AddMesh(self.meshDisplay)

        toDelete = []
        for i in range(self.meshDisplay.Faces.Count):
            toDelete.append(i)
            #z = self.meshDisplay.Vertices[self.meshDisplay.Faces[i].A].Z
            t = math.sin(util.Remap(self.time, 0, 150, 0, 1) * 15)

            offset = util.Remap(t, -1, 1, 0.3, .00)
            #offset = .1
            i0 = self.meshDisplay.Faces[i].A
            i1 = self.meshDisplay.Faces[i].B
            i2 = self.meshDisplay.Faces[i].C

            #n0 = self.mesh.Normals[i0]
            #n1 = self.mesh.Normals[i1]
            #n2 = self.mesh.Normals[i2]

            v0 = rg.Point3d(self.meshDisplay.Vertices[i0])
            v1 = rg.Point3d(self.meshDisplay.Vertices[i1])
            v2 = rg.Point3d(self.meshDisplay.Vertices[i2])

            c0 = self.meshDisplay.PointAt(i, offset, 1 - offset * 2, offset, 0)
            c1 = self.meshDisplay.PointAt(i, offset, offset, 1 - offset * 2, 0)
            c2 = self.meshDisplay.PointAt(i, 1 - offset * 2, offset, offset, 0)

            #cn = (n0+n1+n2)/3
            #ni = mesh.Normals.Add(cn)

            #c = rg.Point3d((v0.X+v1.X+v2.X)/3, (v0.Y+v1.Y+v2.Y)/3, (v0.Z+v1.Z+v2.Z)/3)
            c0i = self.meshDisplay.Vertices.Add(c0)
            c1i = self.meshDisplay.Vertices.Add(c1)
            c2i = self.meshDisplay.Vertices.Add(c2)

            self.meshDisplay.Faces.AddFace(i0, i1, c0i, c2i)
            self.meshDisplay.Faces.AddFace(i1, i2, c1i, c0i)
            self.meshDisplay.Faces.AddFace(i2, i0, c2i, c1i)
            #mesh.Faces.AddFace(i1, i2, ci)
            #mesh.Faces.AddFace(i2, i0, ci)

        self.meshDisplay.Faces.DeleteFaces(toDelete)
        self.meshDisplay.Normals.ComputeNormals()
        self.meshDisplay.Compact()
        self.meshDisplay.RebuildNormals()
Example #10
0
 def Update2(self, time):
     self.prevPlane = self.plane
     
     self.attr.ObjectColor = color.GradientOfColors(self.grad, util.Remap(time, 0, 150, 0, 1))
     index = sc.doc.Materials.Add()
     self.mat = sc.doc.Materials[index]
     self.mat.DiffuseColor = self.attr.ObjectColor
     self.mat.CommitChanges()
     self.attr.MaterialIndex = index
     
     safety = 0
     while True:
         safety += 1
         case = random.randint(1,2)
         #case = 2
         if case == 0:
             #Straight
             geo = self.system.straightSec.geo.Duplicate()
             endPlane = self.system.straightSec.planeEnd.Clone()
             xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, self.prevPlane)
         if case == 1:
             #Angle
             geo = self.system.angleSec.geo.Duplicate()
             endPlane = self.system.angleSec.planeEnd.Clone()
             self.prevPlane.Rotate(math.radians(random.uniform(0,360)), self.prevPlane.Normal, self.prevPlane.Origin)
             xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, self.prevPlane)
         if case == 2:
             #U Turn
             geo = self.system.uTurnSec.geo.Duplicate()
             endPlane = self.system.uTurnSec.planeEnd.Clone()
             #rotForm = rg.Transform.Rotation(rg.Point3d(0,0,0))
             #self.prevPlane.Transform(rotForm)
             self.prevPlane.Rotate(math.radians(random.uniform(0,360)), self.prevPlane.Normal, self.prevPlane.Origin)
             
             xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, self.prevPlane)
         
         
         geo.Transform(xform)
         finished = False
         results = rg.Intersect.Intersection.BrepBrep(geo, self.system.boundary, sc.doc.ModelAbsoluteTolerance)
         if safety > 20:
             print "SAFETY"
             self.alive = False
             break
         if len(results[1]) == 0:
             #results = rg.Intersect.Intersection.BrepBrep(geo, self.majorBrep, sc.doc.ModelAbsoluteTolerance)
             #if len(results[1]) == 0:
             #    self.majorBrep.Append(geo)
             #    finished = True
             #if finished:
             break
     
     endPlane.Transform(xform)
     if self.alive:
         sc.doc.Objects.AddBrep(geo, self.attr)
     
     self.plane = endPlane
Example #11
0
    def UpdateDisplay(self):
        if self.id: sc.doc.Objects.Delete(self.id, True)
        if len(self.belowVertices) > 0 and len(self.belowVertices) < 8:
            self.attr.ObjectColor = color.GradientOfColors(
                self.system.grad,
                util.Remap(len(self.belowVertices), 0, 8, 0, 1), 2)

            index = sc.doc.Materials.Add()
            mat = sc.doc.Materials[index]
            mat.DiffuseColor = self.attr.ObjectColor
            mat.CommitChanges()
            self.attr.MaterialIndex = index

            xform = rg.Transform.Scale(
                self.centerPt, util.Remap(len(self.belowVertices), 1, 7, .1,
                                          1))
            box = self.box.Duplicate()
            box.Transform(xform)
            self.id = sc.doc.Objects.AddMesh(box, self.attr)
Example #12
0
 def UpdateDisplay(self):
     sphere = rg.Sphere(self.system.mesh.Vertices[self.index], .8)
     
     self.attr.ObjectColor = color.GradientOfColors(self.system.grad, util.Remap(self.d, 0, 30, 0, 1), 3)
     index = sc.doc.Materials.Add()
     mat = sc.doc.Materials[index]
     mat.DiffuseColor = self.attr.ObjectColor
     mat.CommitChanges()
     self.attr.MaterialIndex = index
     
     self.system.ids.append(sc.doc.Objects.AddSphere(sphere, self.attr))
Example #13
0
    def __init__(self):
        self.headID = r'941e5133-6d8f-4a2a-853f-f4d3588c3b95'
        self.head = rs.coercemesh(self.headID)
        bb = self.head.GetBoundingBox(rg.Plane.WorldXY)
        yscale = 1 / bb.Max.Y
        zscale = 1 / bb.Max.Z
        xform = rg.Transform.Scale(rg.Plane.WorldXY, 1, yscale, 1)
        self.head.Transform(xform)

        self.pn = perlin.SimplexNoise()
        pt = rg.Point3d(10, 60, 80)
        vec = rg.Vector3d(0, -10, 10)
        plane = rg.Plane(pt, vec)
        xint = rg.Interval(0, 80)
        yint = rg.Interval(0, 80)
        xcount = 10
        ycount = 10
        self.mesh = rg.Mesh.CreateFromPlane(plane, xint, yint, xcount, ycount)
        self.meshOrig = self.mesh.Duplicate()

        for i, v in enumerate(self.mesh.Vertices):
            val = self.pn.noise2(util.Remap(v.X, 10, 90, 0, 3),
                                 util.Remap(v.Y, 0, 50, 0, 3))
            vec = self.meshOrig.Normals[i]
            vec = rg.Vector3d(vec)
            vec *= val * 8
            xform = rg.Transform.Translation(vec)
            v.Transform(xform)
            self.mesh.Vertices[i] = v

        for i, v in enumerate(self.mesh.Vertices):
            val = self.pn.noise3(util.Remap(v.X, 10, 90, 0, 1),
                                 util.Remap(v.Y, 0, 50, 0, 1), 0)
            vec = self.meshOrig.Normals[i]
            vec = rg.Vector3d(vec)
            vec *= val * 20
            xform = rg.Transform.Translation(vec)
            v.Transform(xform)
            self.mesh.Vertices[i] = v
        self.meshID = None
        self.headsID = None
Example #14
0
    def Update(self, time):
        self.acc *= 0
        futurePos = self.pos + self.vel

        f = 1
        repulsion = 1
        if futurePos.X < self.size * f:
            distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(repulsion * distanceModifier, 0, 0)
        if futurePos.Y < self.size * f:
            distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, repulsion * distanceModifier, 0)
        if futurePos.Z < self.size * f:
            distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, 0, repulsion * distanceModifier)
        if futurePos.X > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.X, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(-repulsion * distanceModifier, 0, 0)
        if futurePos.Y > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Y, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, -repulsion * distanceModifier, 0)
        if futurePos.Z > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Z, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, 0, -repulsion * distanceModifier)

        self.vel += self.acc
        self.pos += self.vel
Example #15
0
    def InitTriangle(self):
        xval = util.Remap(self.pos.X, 0, 100, 0, 1 * 2)
        yval = util.Remap(self.pos.Y, 0, 100, 0, 1 * 2)
        zval = util.Remap(self.pos.Z, 0, 100, 0, 1 * 5)
        val = self.system.pn.noise3(xval + self.system.p.pos.X,
                                    yval + self.system.p.pos.Y,
                                    zval + self.system.p.pos.Z)
        self.size = util.Remap(val, -1, 1, -2, 2)
        if self.size > 0:
            self.pt0 = rg.Point3f(0, self.size, 0)
            self.pt1 = rg.Point3f(-self.size / 2, 0, 0)
            self.pt2 = rg.Point3f(self.size / 2, 0, 0)

            camPos = sc.doc.Views.ActiveView.ActiveViewport.CameraLocation
            vec = camPos - self.pos
            plane = rg.Plane(self.pos, vec)
            testPt = self.pos + rg.Vector3f(0, 0, 1)
            cp = plane.ClosestPoint(testPt)
            yAxis = cp - self.pos
            xprod = rg.Vector3d.CrossProduct(vec, yAxis)
            plane = rg.Plane(self.pos, xprod, yAxis)
            xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, plane)
            #self.xform = rg.Transform.PlaneToPlane(self.prevPlane, plane)
            self.prevPlane = plane.Clone()

            col = color.GradientOfColors(self.grad,
                                         util.Remap(val, -1, 1, -1, 1), 2)

            self.system.mesh.VertexColors.Add(col)
            self.system.mesh.VertexColors.Add(col)
            self.system.mesh.VertexColors.Add(col)

            self.pt0.Transform(xform)
            self.pt1.Transform(xform)
            self.pt2.Transform(xform)
            i0 = self.system.mesh.Vertices.Add(self.pt0)
            i1 = self.system.mesh.Vertices.Add(self.pt1)
            i2 = self.system.mesh.Vertices.Add(self.pt2)
            self.system.mesh.Faces.AddFace(i0, i1, i2)
Example #16
0
    def Update(self, time):
        for id in self.tempIDs:
            sc.doc.Objects.Delete(id, True)

        self.acc *= 0
        futurePos = self.pos + self.vel
        hitBoundary = False
        f = 4
        repulsion = 10
        if futurePos.X < self.size * f:
            distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(repulsion * distanceModifier, 0, 0)
            hitBoundary = True
        if futurePos.Y < self.size * f:
            distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, repulsion * distanceModifier, 0)
            hitBoundary = True
        if futurePos.Z < self.size * f:
            distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, 0, repulsion * distanceModifier)
            hitBoundary = True
        if futurePos.X > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.X, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(-repulsion * distanceModifier, 0, 0)
            hitBoundary = True
        if futurePos.Y > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Y, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, -repulsion * distanceModifier, 0)
            hitBoundary = True
        if futurePos.Z > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Z, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, 0, -repulsion * distanceModifier)
            hitBoundary = True

        self.vel += self.acc

        if hitBoundary == False:
            ran = 1
            self.vel += rg.Vector3d(random.uniform(-ran, ran),
                                    random.uniform(-ran, ran),
                                    random.uniform(-ran, ran))

        self.AvoidNeighborPaths()

        newAmp = util.Constrain(self.vel.Length, 0, self.speed)
        self.vel.Unitize()
        self.vel *= newAmp
        self.pos += self.vel

        if len(self.history) > 10:
            self.history.pop(0)
        if len(self.historyPos) > 10:
            self.historyPos.pop(0)
Example #17
0
 def Update(self, time):
     for id in self.tempIDs:
         sc.doc.Objects.Delete(id, True)
     
     self.acc *= 0
     futurePos = self.pos + self.vel
     hitBoundary = False
     f = 2
     repulsion = 10
     if futurePos.X < self.size * f:
         distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(repulsion*distanceModifier,0,0)
         hitBoundary = True
     if futurePos.Y < self.size * f:
         distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(0,repulsion*distanceModifier,0)
         hitBoundary = True
     if futurePos.Z < self.size * f:
         distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0, repulsion)
         self.acc += rg.Vector3d(0,0,repulsion*distanceModifier)
         hitBoundary = True
     if futurePos.X > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.X, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(-repulsion*distanceModifier,0,0)
         hitBoundary = True
     if futurePos.Y > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.Y, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(0,-repulsion*distanceModifier,0)
         hitBoundary = True
     if futurePos.Z > 100-self.size * f:
         distanceModifier = util.Remap(futurePos.Z, 100-self.size * f, 100, 0, repulsion)
         self.acc += rg.Vector3d(0,0,-repulsion*distanceModifier)
         hitBoundary = True
     
     self.vel += self.acc
     
     if hitBoundary == False:
         ran = 1
         self.vel += rg.Vector3d(random.uniform(-ran, ran), random.uniform(-ran, ran), random.uniform(-ran, ran))
     
     self.AvoidNeighborPaths()
     self.CreateRectangles()
     
     
     newAmp = util.Constrain(self.vel.Length, 0, self.speed)
     self.vel.Unitize()
     self.vel *= newAmp
     self.pos += self.vel
     
     for each in self.history:
         mp = rg.AreaMassProperties.Compute(each)
         xform = rg.Transform.Scale(mp.Centroid, .9)
         each.Transform(xform)
     
     if len(self.history) > 30:
         self.history.pop(0)
     if len(self.historyPos) > 30:
         self.historyPos.pop(0)
Example #18
0
 def __init__(self, system, x,y,z, xi, yi, zi):
     self.system = system
     self.pos = rg.Point3f(x,y,z)
     
     self.xi = xi
     self.yi = yi
     self.zi = zi
     
     sum = 0
     for target in self.system.targets:
         sum += target.radius/((target.pos - rg.Point3d(self.pos)).Length)
     self.isoValue = sum
     
     self.attr = self.system.attr.Duplicate()
     self.attr.ObjectColor = color.GradientOfColors(self.system.grad, util.Remap(self.isoValue, .2, .8, 0, 1), 2)
Example #19
0
    def UpdateDisplay(self):
        self.attr.ObjectColor = color.GradientOfColors(
            self.grad, util.Remap(self.acc.Length, 0, .25, 0, 1))
        index = sc.doc.Materials.Add()
        self.mat = sc.doc.Materials[index]
        self.mat.DiffuseColor = self.attr.ObjectColor
        self.mat.CommitChanges()
        self.attr.MaterialIndex = index

        #for id in self.ids:
        #    sc.doc.Objects.Delete(id, True)

        if self.id: sc.doc.Objects.Delete(self.id, True)

        self.id = sc.doc.Objects.AddMesh(self.mesh, self.attr)
Example #20
0
    def MoveVertexAlongNormal(self, i, d):
        vertex = self.mesh.Vertices[i]

        v = rg.Point3d(vertex)
        vec = rg.Vector3d(self.mesh.Normals[i])
        vec.Unitize()

        val = util.Remap(d, 0, 20, math.pi, 0)
        val = 1 - (math.cos(val) + 1) * .5

        vec *= val * 1.5

        v += vec

        self.mesh.Vertices[i] = rg.Point3f(v.X, v.Y, v.Z)
Example #21
0
    def MoveVertexAlongNormal(self, i, d):
        vertex = self.mesh.Vertices[i]

        v = rg.Point3d(vertex)
        vec = rg.Vector3d(self.mesh.Normals[i])
        vec.Unitize()
        val = util.Remap(d, 0, 10, 1, 0)
        val = (math.cos(val * (math.pi * .25)) + 1) * .5
        val *= 5
        #t = util.Remap(d, 0, 10, 5, 0)

        vec *= val
        v += vec

        self.mesh.Vertices[i] = rg.Point3f(v.X, v.Y, v.Z)
Example #22
0
    def Update(self):
        #for id in self.ids:
        #    if id:
        #        sc.doc.Objects.Delete(id, True)
        self.age += 1

        #Previous positions
        self.prevPos = rg.Point3d(self.pos)
        #######################################################
        self.size = util.Remap(self.age, 0, 150, 4, 10)

        futureXform = rg.Transform.Translation(self.vel)
        futureObj = self.brep.Duplicate()
        futureObj.Transform(futureXform)

        closestD = None
        for particle in self.system.particles:
            if particle is self: continue
            pt0, pt1 = BrepProximity(self.brep, particle.brep)
            d = (pt0 - pt1).Length
            if d < closestD or closestD is None:
                closestD = d

        pt0, pt1 = BrepProximity(self.brep, self.system.boundary)
        d = (pt0 - pt1).Length
        if d < closestD or closestD is None:
            closestD = d

        if closestD < self.size * 2:
            # self.vel.Unitize()
            #self.vel *= closestD
            self.vel *= 0
        else:
            self.vel += self.acc

        self.pos += self.vel

        #if self.pos.Z < 5:
        #    hit = True

        #######################################################
        xform = rg.Transform.Translation(self.vel)
        self.brep.Transform(xform)

        xform = rg.Transform.Scale(self.pos, 1.01)
        self.brep.Transform(xform)

        self.ids.append(sc.doc.Objects.AddBrep(self.brep, self.attr))
Example #23
0
 def UpdateDisplay(self):
     self.attr.ObjectColor = color.GradientOfColors(self.grad, util.Remap(self.vel.Length, 3, 7, 0, 1))
     index = sc.doc.Materials.Add()
     self.mat = sc.doc.Materials[index]
     self.mat.DiffuseColor = self.attr.ObjectColor
     self.mat.CommitChanges()
     self.attr.MaterialIndex = index
     
     #if self.id: sc.doc.Objects.Delete(self.id, True)
     for id in self.ids:
         sc.doc.Objects.Delete(id, True)
     
     if self.id is None:
         self.id = sc.doc.Objects.AddMesh(self.mesh, self.attr)
     else:
         self.id = sc.doc.Objects.Transform(self.id, self.xform, True)
Example #24
0
    def __init__(self, targets, iv):
        self.numVoxels = 25
        self.voxelSize = 4
        self.grad = color.GetGradient(10)
        self.targets = []
        self.isoValue = iv
        self.mesh = rg.Mesh()
        self.id = None
        self.pts = []
        self.ptsCollection = rc.Collections.Point3dList()

        self.targets = targets

        self.attr = rc.DocObjects.ObjectAttributes()
        self.attr.ColorSource = rc.DocObjects.ObjectColorSource.ColorFromObject
        grad = color.GetGradient(5)
        self.attr.ObjectColor = color.GradientOfColors(
            grad, util.Remap(self.isoValue, .3, .5, 0, 1), 3)
        self.attr.MaterialSource = rc.DocObjects.ObjectMaterialSource.MaterialFromObject
        index = sc.doc.Materials.Add()
        mat = sc.doc.Materials[index]
        mat.DiffuseColor = self.attr.ObjectColor
        mat.CommitChanges()
        self.attr.MaterialIndex = index

        #Setup Vertices
        self.vertices = []
        for x in range(self.numVoxels + 1):
            yRow = []
            for y in range(self.numVoxels + 1):
                zRow = []
                for z in range(self.numVoxels + 1):
                    zRow.append(
                        Vertex(self, x * self.voxelSize, y * self.voxelSize,
                               z * self.voxelSize, x, y, z))
                yRow.append(zRow)
            self.vertices.append(yRow)

        #Setup Voxels
        self.voxels = []
        index = 0
        for x in range(self.numVoxels):
            for y in range(self.numVoxels):
                for z in range(self.numVoxels):
                    self.voxels.append(
                        Voxel(self, x * self.voxelSize, y * self.voxelSize,
                              z * self.voxelSize, x, y, z))
Example #25
0
    def UpdatePosition(self):
        self.vel *= .5

        v = self.pos - self.system.p.pos
        if v.Length < 20:
            val = util.Remap(v.Length, 0, 5, 5, 0)
            self.acc = v
            self.acc.Unitize()
            self.acc *= val
        else:
            self.acc *= .8

        self.vel += self.acc
        #self.vel *= util.Constrain(self.vel.Length, 2)
        self.pos += self.vel

        self.MoveTriangle()
Example #26
0
    def Update(self, time):
        if time == 1:
            sc.doc.Objects.AddSphere(self.sphere, self.attr)
        self.acc *= 0
        futurePos = self.pos + self.vel
        hitBoundary = False
        f = 4
        repulsion = 10
        if futurePos.X < self.size * f:
            distanceModifier = util.Remap(futurePos.X, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(repulsion * distanceModifier, 0, 0)
            hitBoundary = True
        if futurePos.Y < self.size * f:
            distanceModifier = util.Remap(futurePos.Y, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, repulsion * distanceModifier, 0)
            hitBoundary = True
        if futurePos.Z < self.size * f:
            distanceModifier = util.Remap(futurePos.Z, self.size * f, 0, 0,
                                          repulsion)
            self.acc += rg.Vector3d(0, 0, repulsion * distanceModifier)
            hitBoundary = True
        if futurePos.X > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.X, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(-repulsion * distanceModifier, 0, 0)
            hitBoundary = True
        if futurePos.Y > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Y, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, -repulsion * distanceModifier, 0)
            hitBoundary = True
        if futurePos.Z > 100 - self.size * f:
            distanceModifier = util.Remap(futurePos.Z, 100 - self.size * f,
                                          100, 0, repulsion)
            self.acc += rg.Vector3d(0, 0, -repulsion * distanceModifier)
            hitBoundary = True

        self.vel += self.acc

        if hitBoundary == False:
            ran = 1
            self.vel += rg.Vector3d(random.uniform(-ran, ran),
                                    random.uniform(-ran, ran),
                                    random.uniform(-ran, ran))

        newAmp = util.Constrain(self.vel.Length, 0, self.speed)
        self.vel.Unitize()
        self.vel *= newAmp
        self.pos += self.vel

        self.history.append(self.pos)
Example #27
0
    def UpdateDisplay(self):
        if self.id: sc.doc.Objects.Delete(self.id, True)

        if len(self.interPts) >= 3:

            r, plane = rg.Plane.FitPlaneToPoints(self.interPts)
            if r == rg.PlaneFitResult.Success:
                if False:
                    v = plane.RemapToPlaneSpace(self.vertices[0].pos)[1]
                    if v.Z < 0 and self.vertices[
                            0].isoValue < self.system.isoValue:
                        #keep plane
                        pass
                    elif v.Z < 0 and self.vertices[
                            0].isoValue >= self.system.isoValue:
                        #flip plane
                        nRev = plane.Normal
                        nRev.Reverse()
                        plane = rg.Plane(plane.Origin, nRev)
                    elif v.Z >= 0 and self.vertices[
                            0].isoValue < self.system.isoValue:
                        #flip plane
                        nRev = plane.Normal
                        nRev.Reverse()
                        plane = rg.Plane(plane.Origin, nRev)
                    elif v.Z >= 0 and self.vertices[
                            0].isoValue >= self.system.isoValue:
                        #keep plane
                        pass

                mesh = geo.DelaunayMesh(self.interPts, plane)
                self.system.mesh.Append(mesh)

                #self.id = sc.doc.Objects.AddMesh(mesh)

        if False:
            self.attr.ObjectColor = color.GradientOfColors(
                self.system.grad,
                util.Remap(len(self.belowVertices), 0, 8, 0, 1), 2)

            index = sc.doc.Materials.Add()
            mat = sc.doc.Materials[index]
            mat.DiffuseColor = self.attr.ObjectColor
            mat.CommitChanges()
            self.attr.MaterialIndex = index
Example #28
0
    def AssignNeighbors(self):
        for coneID in self.coneIDs:
            if coneID:
                sc.doc.Objects.Delete(coneID, True)
        closestObj = None
        distance = 30
        closestObjs = []
        largestSize = None
        distances = []
        for eachOther in self.system.particles:
            if eachOther is self: continue
            d = rs.Distance(eachOther.pos, self.pos)
            if d < distance:
                closestObjs.append(eachOther)
                if d > largestSize or largestSize is None:
                    largestSize = d
        if largestSize:
            big = util.Remap(largestSize, 0, 30, 4, 0)
        else:
            big = 2
        for closestObj in closestObjs:
            #closestObj = eachOther

            norm = closestObj.pos - self.pos
            plane = rg.Plane(self.pos, norm)
            otherPlane = plane.Clone()
            otherPlane.Origin = closestObj.pos

            #size = util.Remap(d, 0, largestSize, 4, 0)

            crv0 = rg.Circle(plane, big)
            crv1 = rg.Circle(otherPlane, big)
            crv0 = crv0.ToNurbsCurve()
            crv1 = crv1.ToNurbsCurve()
            loft = rg.Brep.CreateFromLoft([crv0, crv1], self.pos,
                                          closestObj.pos, rg.LoftType.Straight,
                                          False)

            self.coneIDs.append(sc.doc.Objects.AddBrep(loft[0], self.attr))

        for id in self.ids:
            sc.doc.Objects.Delete(id, True)
        self.sphere = rg.Sphere(self.pos, big)
        self.ids.append(sc.doc.Objects.AddSphere(self.sphere, self.attr))
Example #29
0
    def __init__(self):
        self.particles = []
        self.boundary = rg.Box(rg.Plane.WorldXY, rg.Interval(-25, 125),
                               rg.Interval(-25, 125), rg.Interval(0, 100))
        self.boundary = self.boundary.ToBrep()

        self.time = 0
        self.ids = []

        self.attr = rc.DocObjects.ObjectAttributes()
        self.attr.ColorSource = rc.DocObjects.ObjectColorSource.ColorFromObject
        self.attr.MaterialSource = rc.DocObjects.ObjectMaterialSource.MaterialFromObject

        grad = color.GetGradient(1)
        self.attr.ObjectColor = color.GradientOfColors(grad, 0)
        self.attr.ObjectColor = drawing.Color.White
        index = sc.doc.Materials.Add()
        self.mat = sc.doc.Materials[index]
        self.mat.DiffuseColor = self.attr.ObjectColor
        self.mat.CommitChanges()
        self.attr.MaterialIndex = index

        self.attr = rc.DocObjects.ObjectAttributes()
        self.attr.ColorSource = rc.DocObjects.ObjectColorSource.ColorFromObject
        self.attr.MaterialSource = rc.DocObjects.ObjectMaterialSource.MaterialFromObject

        attr = self.attr.Duplicate()
        grad = color.GetGradient(0)
        col1 = color.GradientOfColors(grad, util.Remap(self.time, 0, 150, 0,
                                                       1))

        attr.ObjectColor = col1
        index = sc.doc.Materials.Add()
        self.mat = sc.doc.Materials[index]
        self.mat.DiffuseColor = attr.ObjectColor
        self.mat.CommitChanges()
        attr.MaterialIndex = index

        self.particles = []

        #for i in range(2):
        self.particles.append(Particle(self, rg.Point3d(25, 50, 80), attr))
        self.particles.append(Particle(self, rg.Point3d(75, 50, 80), attr))
Example #30
0
    def UpdateDisplay(self):
        for id in self.ids:
            sc.doc.Objects.Delete(id, True)

        for i, pt in enumerate(self.path):
            sphere = rg.Sphere(pt, .8)
            self.attr.ObjectColor = color.GradientOfColors(
                self.grad, util.Remap(i, 0, len(self.path), 0, 1), 3)
            index = sc.doc.Materials.Add()
            mat = sc.doc.Materials[index]
            mat.DiffuseColor = self.attr.ObjectColor
            mat.CommitChanges()
            self.attr.MaterialIndex = index

            self.ids.append(sc.doc.Objects.AddSphere(sphere, self.attr))

        self.ids.append(sc.doc.Objects.AddMesh(self.mesh))
        self.vObjects[self.sourceIndex].UpdateDisplay()
        self.vObjects[self.targetIndex].UpdateDisplay()