Ejemplo n.º 1
0
 def UpdateDisplay(self):
     for id in self.tempIDs:
         sc.doc.Objects.Delete(id, True)
     
     if self.turned:
         centerPt = self.prevPlane.Origin.Clone()
         centerPt += self.vel
         centerPlane = rg.Plane(centerPt, self.pos, self.prevPlane.Origin)
         circ = rg.Circle(centerPlane, self.size*self.length)
         arc = rg.Arc(circ, math.pi*.5)
         arc = arc.ToNurbsCurve()
         newPlane = self.prevPlane.Clone()
         tempVel = self.prevVel.Clone()
         tempCenter = self.prevPlane.Origin.Clone()
         tempCenter += tempVel
         newPlane.Origin = tempCenter
         circ = rg.Circle(newPlane, self.size)
         circ = circ.ToNurbsCurve()
         sweep = rg.SweepOneRail()
         if arc and circ:
             breps = sweep.PerformSweep(arc, circ)
             for brep in breps:
                 sc.doc.Objects.AddBrep(brep, self.attr)
     else:
         geo = self.system.straightSec.geo.Duplicate()
         xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, self.prevPlane)
         geo.Transform(xform)
         sc.doc.Objects.AddBrep(geo, self.attr)
     
     for id in self.ids:
         sc.doc.Objects.Delete(id, True)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def Update(self, time):
        for id in self.ids:
            sc.doc.Objects.Delete(id, True)

        safety = 0
        masterSafety = 0

        while True:
            safety += 1
            masterSafety += 1
            if masterSafety > 100:
                self.alive = False
                print "MASTER SAFETY"
                break
            if safety > 20:
                print "SAFETY"
                self.majorBrep.Faces.RemoveAt(self.majorBrep.Faces.Count - 1)
                self.planes.pop(-1)
                self.breps.pop(-1)
                safety = 0
                continue

            #closestD = None
            angle = math.radians(random.randint(0, 3) * 90)
            currPlane = self.planes[-1].Clone()

            case = random.randint(1, 2)
            if case == 0:
                #Straight
                geo = self.straightSec.geo.Duplicate()
                endPlane = self.straightSec.planeEnds[0].Clone()
                #currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)
            if case == 1:
                #Angle
                geo = self.angleSec.geo.Duplicate()
                endPlane = self.angleSec.planeEnds[0].Clone()
                currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)
            if case == 2:
                #U Turn
                geo = self.uTurnSec.geo.Duplicate()
                endPlane = self.uTurnSec.planeEnds[0].Clone()
                currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)

            geo.Transform(xform)
            endPlane.Transform(xform)
            #print rs.Distance(endPlane.Origin, self.origin)

            #Test for intersection
            finished = False
            results = rg.Intersect.Intersection.BrepBrep(
                geo, self.system.boundary, sc.doc.ModelAbsoluteTolerance)
            if len(results[1]) == 0:
                #It is not intersecting the boundary
                results = rg.Intersect.Intersection.BrepBrep(
                    geo, self.majorBrep, sc.doc.ModelAbsoluteTolerance)
                if len(results[1]) == 0:
                    hittingAnother = False
                    for otherParticle in self.system.particles:
                        if otherParticle is self:
                            continue
                        #It is not intersecting itself
                        results = rg.Intersect.Intersection.BrepBrep(
                            geo, otherParticle.majorBrep,
                            sc.doc.ModelAbsoluteTolerance)
                        if len(results[1]) > 0:
                            #Not intersecting other brep
                            hittingAnother = True
                    if hittingAnother == False:
                        if len(self.breps) > 0:
                            self.majorBrep.Append(self.breps[-1])
                        self.breps.append(geo)

                        self.planes.append(endPlane)
                        finished = True
            if finished:
                #Not intersecting, can leave loop
                break

        if self.id:
            sc.doc.Objects.Delete(self.id, True)
        self.id = sc.doc.Objects.AddBrep(self.majorBrep, self.attr)
Ejemplo n.º 4
0
    def Update(self, time):
        for id in self.ids:
            sc.doc.Objects.Delete(id, True)

        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
            if safety > 20:
                print "SAFETY"
                self.majorBrep.Faces.RemoveAt(self.majorBrep.Faces.Count - 1)
                self.planes.pop(-1)
                self.breps.pop(-1)
                safety = 0
                continue

            case = random.randint(0, 1)
            angle = math.radians(random.randint(0, 3) * 90)
            currPlane = self.planes[-1].Clone()

            #case = 2
            if case == 0:
                #Straight
                geo = self.system.straightSec.geo.Duplicate()
                endPlane = self.system.straightSec.planeEnd.Clone()
                #currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)
            if case == 1:
                #Angle
                geo = self.system.angleSec.geo.Duplicate()
                endPlane = self.system.angleSec.planeEnd.Clone()
                currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)
            if case == 2:
                #U Turn
                geo = self.system.uTurnSec.geo.Duplicate()
                endPlane = self.system.uTurnSec.planeEnd.Clone()
                currPlane.Rotate(angle, currPlane.Normal, currPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, currPlane)

            geo.Transform(xform)

            #Test for intersection
            finished = False
            results = rg.Intersect.Intersection.BrepBrep(
                geo, self.system.boundary, sc.doc.ModelAbsoluteTolerance)
            if len(results[1]) == 0:
                #It is not intersecting the boundary
                results = rg.Intersect.Intersection.BrepBrep(
                    geo, self.majorBrep, sc.doc.ModelAbsoluteTolerance)
                if len(results[1]) == 0:
                    for otherParticle in self.system.particles:
                        if otherParticle is self:
                            continue
                        #It is not intersecting itself
                        results = rg.Intersect.Intersection.BrepBrep(
                            geo, self.majorBrep, sc.doc.ModelAbsoluteTolerance)
                        if len(results[1]) == 0:
                            #Not intersecting other brep
                            if len(self.breps) > 0:
                                self.majorBrep.Append(self.breps[-1])
                            self.breps.append(geo)
                            endPlane.Transform(xform)
                            #self.ids.append(sc.doc.Objects.AddPoint(endPlane.Origin, self.attrCol1))
                            #self.ids.append(sc.doc.Objects.AddPoint(currPlane.Origin, self.attrCol2))
                            #self.ids.append(sc.doc.Objects.AddBrep(self.prevBrep, self.attrCol2))
                            self.planes.append(endPlane)
                            finished = True
            if finished:
                #Not intersecting, can leave loop
                break

        if self.id:
            sc.doc.Objects.Delete(self.id, True)
        self.id = sc.doc.Objects.AddBrep(self.majorBrep, self.attr)
Ejemplo n.º 5
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
            if safety > 20:
                print "SAFETY"
                self.majorBrep.Faces.RemoveAt(self.majorBrep.Faces.Count - 1)
                self.plane = self.prevPlane
                self.prevPlane = self.prevPrevPlane
                safety = 0
                break

            case = random.randint(0, 1)
            angle = math.radians(random.randint(0, 4) * 90)
            tempPlane = self.plane.Clone()

            #case = 2
            if case == 0:
                #Straight
                geo = self.system.straightSec.geo.Duplicate()
                endPlane = self.system.straightSec.planeEnd.Clone()
                tempPlane.Rotate(angle, self.prevPlane.Normal,
                                 self.prevPlane.Origin)
                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()
                tempPlane.Rotate(angle, self.prevPlane.Normal,
                                 self.prevPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, tempPlane)
            if case == 2:
                #U Turn
                geo = self.system.uTurnSec.geo.Duplicate()
                endPlane = self.system.uTurnSec.planeEnd.Clone()
                tempPlane.Rotate(angle, self.prevPlane.Normal,
                                 self.prevPlane.Origin)
                xform = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, tempPlane)

            geo.Transform(xform)

            #Test for intersection
            finished = False
            results = rg.Intersect.Intersection.BrepBrep(
                geo, self.system.boundary, sc.doc.ModelAbsoluteTolerance)
            if len(results[1]) == 0:
                #It is not intersecting the boundary
                results = rg.Intersect.Intersection.BrepBrep(
                    geo, self.majorBrep, sc.doc.ModelAbsoluteTolerance)
                if len(results[1]) == 0:
                    #It is not intersecting itself
                    if self.prevBrep:
                        self.majorBrep.Append(self.prevBrep)
                    finished = True
            if finished:
                #Not intersecting, can leave loop
                break

        self.prevBrep = geo
        self.prevPrevPlane = self.prevPlane
        self.prevPlane = tempPlane
        endPlane.Transform(xform)
        self.plane = endPlane

        if self.id:
            sc.doc.Objects.Delete(self.id, True)
        self.id = sc.doc.Objects.AddBrep(self.majorBrep, self.attr)