Пример #1
0
 def evalColorAtPoint(self, point):
     if self.material:
         lights = []
         norm = bdgmath.Vector3(0, 0, 1)
         toViewer = bdgmath.Vector3(1, -1, 1)
         return self.material.evalColor(point, lights, norm, toViewer)
     else:
         if point.z() < self.center.z():
             return self.color2
         return self.color1
Пример #2
0
    def mutatePoint(self, point):
        r = -self.rzRad

        nz = point.z()
        nx = point.x() * math.cos(r) - point.y() * math.sin(r)
        ny = point.x() * math.sin(r) + point.y() * math.cos(r)

        return bdgmath.Vector3(nx, ny, nz)
Пример #3
0
def calcNormal(scene, probePoint):
    step = 0.0001

    x, y, z = probePoint.components
    xp = bdgmath.Vector3(x + step, y, z)
    xm = bdgmath.Vector3(x - step, y, z)
    yp = bdgmath.Vector3(x, y + step, z)
    ym = bdgmath.Vector3(x, y - step, z)
    zp = bdgmath.Vector3(x, y, z + step)
    zm = bdgmath.Vector3(x, y, z - step)

    dxp = distToScene(scene, xp)
    dxm = distToScene(scene, xm)
    dyp = distToScene(scene, yp)
    dym = distToScene(scene, ym)
    dzp = distToScene(scene, zp)
    dzm = distToScene(scene, zm)

    if dxp[0] and dxm[0]:
        xg = dxp[0] - dxm[0]
    else:
        xg = 0
    if dyp[0] and dym[0]:
        yg = dyp[0] - dym[0]
    else:
        yg = 0
    if dzp[0] and dzm[0]:
        zg = dzp[0] - dzm[0]
    else:
        zg = 0

    n = bdgmath.Vector3(xg, yg, zg)
    return n.makeUnit()
Пример #4
0
    def renderScene(self, scene, width, height, filename):
        img = Image.new("RGB", (width, height))
        
        leftX = self.pos.x() - self.viewWidth
        rightX = self.pos.x() + self.viewWidth

        self.aspectRatio = width / height

        viewHeight = self.viewWidth / self.aspectRatio
        
        topZ = self.pos.z() + viewHeight
        bottomZ = self.pos.z() - viewHeight

        # xStep goes left to right
        xStep = (rightX - leftX) / (width - 1)

        # zStep goes DOWN
        zStep = (bottomZ - topZ) / (height - 1)

        sy = self.pos.y() + self.viewDistance

        rayQueue = queue.Queue(maxsize = 0)
        imgLock = threading.Lock()
        
        num_threads = multiprocessing.cpu_count()
        print (f"using {num_threads} threads")

        start_time = time.time()
        
        for i in range(num_threads):
            worker = threading.Thread(target = rayWorker, args = (rayQueue,))
            worker.setDaemon(True)
            worker.start()
        
        for px in range(0, width):
            #print ("x: %d(/%d)" % (px, width))
            sx = leftX + xStep * px
            for py in range(0, height):
                sz = topZ + zStep * py

                screenPos = bdgmath.Vector3(sx, sy, sz)
                
                r = bdgmath.Ray(self.pos, screenPos)

                rayQueue.put((px, py, r, scene, img, imgLock))

            #img.save(filename)
        print("all tasks sent")
        rayQueue.join()
        print("all tasks completed")
        img.save(filename)
        print("elapsed time:", time.time() - start_time)
Пример #5
0
    def mutations(self, point):
        px = (point.x() +
              0.5 * self.xPeriod) % self.xPeriod - 0.5 * self.xPeriod
        py = (point.y() +
              0.5 * self.yPeriod) % self.yPeriod - 0.5 * self.yPeriod

        if px < 0:
            xOpts = [px, px + self.xPeriod]
        else:
            xOpts = [px - self.xPeriod, px]

        if py < 0:
            yOpts = [py, py + self.yPeriod]
        else:
            yOpts = [py - self.yPeriod, py]

        return [
            bdgmath.Vector3(xOpt, yOpt, point.z()) for xOpt in xOpts
            for yOpt in yOpts
        ]
Пример #6
0
    def signedDistance(self, point):
        px, py, pz = point.components

        px = abs(px)
        py = abs(py)
        pz = abs(pz)

        qx = px - self.cx
        qy = py - self.cy
        qz = pz - self.cz

        dx = max(0, qx)
        dy = max(0, qy)
        dz = max(0, qz)

        dVec = bdgmath.Vector3(dx, dy, dz)
        outsideDist = dVec.mag()

        insideDist = min(max(qx, qy, qz), 0)
        return outsideDist + insideDist
Пример #7
0
 def mutatePoint(self, point):
     px = (point.x() +
           0.5 * self.xPeriod) % self.xPeriod - 0.5 * self.xPeriod
     py = (point.y() +
           0.5 * self.yPeriod) % self.yPeriod - 0.5 * self.yPeriod
     return bdgmath.Vector3(px, py, point.z())
Пример #8
0
import scene

import plane
import sphere
import cylinder
import donut
import box
import repeated2d
import transform
import light
import material
import csg
import roundedge


cam = camera.FreeCamera(bdgmath.Vector3(5, -8, 6),
                        bdgmath.Vector3(0, 0, 0.75))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

disk = roundedge.RoundEdge(0.1, cylinder.CappedCylinder(0.8, 3.8))

translatedDisk = transform.Translate3d(bdgmath.Vector3(0, 0, 1.5), disk)
#scene.addObject(translatedDisk)
Пример #9
0
import scene

import plane
import sphere
import cylinder
import donut
import box
import repeated2d
import transform
import light

#cam = camera.YCamera(0, -5, 3)
#cam.setViewDistance(2)
#cam.setViewWidth(2)

cam = camera.FreeCamera(bdgmath.Vector3(10, -8, 6), bdgmath.Vector3(0, 0, 5))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 1, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

scene.addObject(plane.ZPlane(0))
#scene.addObject(plane.ZPlane(-2))
#scene.addObject(sphere.Sphere(bdgmath.Vector3(-0.1, 0, 2.5), 2.5))

s2 = sphere.Sphere(bdgmath.Vector3(3.5, 2, 2), 2)
s2.color1 = (40, 200, 40)
#s2.color2 = (0, 250, 0)
s2.color2 = (40, 200, 40)
#scene.addObject(s2)
Пример #10
0
import camera
import scene

import plane
import sphere
import cylinder
import donut
import box
import repeated2d
import transform
import light
import material
import csg

cam = camera.FreeCamera(bdgmath.Vector3(8, -12, 8), bdgmath.Vector3(0, 0, 5))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

cube = box.Box(bdgmath.Vector3(5, 5, 5))
cube.color = (1.0, 0.75, 0.25)

negSphere = sphere.Sphere(bdgmath.Vector3(2.5, -2.5, 2.5), 4.5)
Пример #11
0
import bdgmath

import camera
import scene

import plane
import sphere
import cylinder
import donut
import box
import repeated2d
import transform
import light
import material

cam = camera.FreeCamera(bdgmath.Vector3(3, -7, 10), bdgmath.Vector3(0, 0, 4))

scene = scene.Scene()

scene.addLight(light.DirectionalLight(bdgmath.Vector3(-1, 0.5, -4), 0.8))
scene.addLight(light.AmbientLight(0.2))

floor = plane.ZPlane(0)
floor.squareSize = 2
scene.addObject(floor)

s = sphere.Sphere(bdgmath.Vector3(0, 0, 4), 2)
s.material = material.Reflect(
    (0.4, 0.4, 0.4),  # base color
    0.5,  # kR the amount of reflected light to use
    0.3,  # kD the amount of diffuse light to use
Пример #12
0
 def __init__(self, x, y, z):
     self.pos = bdgmath.Vector3(x, y, z)
     self.viewDistance = 1
     self.aspectRatio = 1
     self.viewWidth = 1
Пример #13
0
 def __init__(self, pos, target):
     self.pos = pos
     self.target = target
     self.up = bdgmath.Vector3(0, 0, 1)
     self.viewDistance = 1
     self.viewWidth = 1