Ejemplo n.º 1
0
    def __init__(self, system, size, plane):
        self.system = system
        self.ang = 0
        self.plane = plane
        self.geo = None
        self.size = size
        self.age = 0
        self.length = size * 1.5

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

        col = color.GetRandomNamedColor()
        r = util.Remap(self.plane.Origin.X, 0, 100, 100, 255)
        g = util.Remap(self.plane.Origin.Y, 0, 100, 100, 255)
        b = util.Remap(self.plane.Origin.Z, 0, 100, 100, 255)
        col = drawing.Color.FromArgb(r, g, b)
        self.attr.ObjectColor = col
        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.id = None
        offset = 0.1

        loop = True
        safety = 0
        while loop:
            safety += 1
            if safety > 20:
                print "SAFETY"
                self.system.deadPlanes.append(plane)
                return

            box = rg.Box(
                self.plane,
                rg.Interval(-self.size / 2 + offset, self.size / 2 - offset),
                rg.Interval(-self.size / 2 + offset, self.size / 2 - offset),
                rg.Interval(offset, self.size - offset))
            testGeo = box.ToBrep()

            loop = False
            results = rg.Intersect.Intersection.BrepBrep(
                testGeo, self.system.boundary, sc.doc.ModelAbsoluteTolerance)
            if len(results[1]) > 0:
                print "HIT BOUNDARY"
                #self.system.deadPlanes.append(plane)
                return
            for eachGeo in self.system.breps:
                results = rg.Intersect.Intersection.BrepBrep(
                    testGeo, eachGeo, sc.doc.ModelAbsoluteTolerance)
                if len(results[1]) > 0:
                    loop = True

        self.geo = testGeo
        self.system.breps.append(self.geo)
        #self.system.deadPlanes.append(plane)

        #Create Planes for other boxes
        if False:
            #Center Plane
            centerPlane = plane.Clone()
            vec = centerPlane.Normal
            vec *= self.size / 2
            xform = rg.Transform.Translation(vec)
            centerPlane.Transform(xform)

            #Top plane
            vec = centerPlane.Normal
            vec *= self.size / 2
            xform = rg.Transform.Translation(vec)
            topPlane = centerPlane.Clone()
            topPlane.Transform(xform)
            self.system.nextRoundPlanes.append(topPlane)

            #Xplane+
            vec = centerPlane.XAxis
            vec *= self.size / 2
            xform = rg.Transform.Translation(vec)
            pt = centerPlane.Origin
            pt.Transform(xform)
            xPlanePlus = rg.Plane(pt, centerPlane.YAxis, centerPlane.ZAxis)
            self.system.nextRoundPlanes.append(xPlanePlus)
Ejemplo n.º 2
0
    def __init__(self, system, size, pos=None):
        self.system = system
        self.planeStart = rg.Plane.WorldXY
        self.geo = None
        self.cylinderGeo = None
        self.angleGeo = None
        self.uTurnGeo = None
        self.geoID = None
        self.size = size
        self.length = size * 1.5

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

        col = color.GetRandomNamedColor()
        self.attr.ObjectColor = col
        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.id = None

        if pos:
            #Initialize
            plane = rg.Plane(pos, rg.Vector3d(0, 0, 1))
            offset = 0.1
            box = rg.Box(
                plane,
                rg.Interval(-self.size / 2 + offset, self.size / 2 - offset),
                rg.Interval(-self.size / 2 + offset, self.size / 2 - offset),
                rg.Interval(offset, self.size - offset))
            self.geo = box.ToBrep()
            self.system.breps.append(self.geo)
            self.system.deadPlanes.append(plane)
        else:
            loop = True
            safety = 0
            while loop:
                safety += 1
                if safety > 20:
                    print "SAFETY"
                    self.system.deadPlanes.append(plane)
                    return

                plane = random.choice(self.system.openPlanes)
                plane.Rotate(math.radians(random.uniform(0, 4) * 90),
                             plane.Normal)
                offset = 0.1
                box = rg.Box(
                    plane,
                    rg.Interval(-self.size / 2 + offset,
                                self.size / 2 - offset),
                    rg.Interval(-self.size / 2 + offset,
                                self.size / 2 - offset),
                    rg.Interval(offset, self.size - offset))
                testGeo = box.ToBrep()

                loop = False
                results = rg.Intersect.Intersection.BrepBrep(
                    testGeo, self.system.boundary,
                    sc.doc.ModelAbsoluteTolerance)
                if len(results[1]) > 0:
                    print "HIT BOUNDARY"
                    self.system.deadPlanes.append(plane)
                    return
                for eachGeo in self.system.breps:
                    results = rg.Intersect.Intersection.BrepBrep(
                        testGeo, eachGeo, sc.doc.ModelAbsoluteTolerance)
                    if len(results[1]) > 0:
                        loop = True

            self.geo = testGeo
            self.system.breps.append(self.geo)
            self.system.deadPlanes.append(plane)

        #Center Plane
        centerPlane = plane.Clone()
        vec = centerPlane.Normal
        vec *= self.size / 2
        xform = rg.Transform.Translation(vec)
        centerPlane.Transform(xform)

        #Top plane
        vec = centerPlane.Normal
        vec *= self.size / 2
        xform = rg.Transform.Translation(vec)
        topPlane = centerPlane.Clone()
        topPlane.Transform(xform)
        self.system.nextRoundPlanes.append(topPlane)

        #Xplane+
        vec = centerPlane.XAxis
        vec *= self.size / 2
        xform = rg.Transform.Translation(vec)
        pt = centerPlane.Origin
        pt.Transform(xform)
        xPlanePlus = rg.Plane(pt, centerPlane.YAxis, centerPlane.ZAxis)
        self.system.nextRoundPlanes.append(xPlanePlus)