summaryrefslogtreecommitdiffstats
path: root/dimension/tests
diff options
context:
space:
mode:
Diffstat (limited to 'dimension/tests')
-rw-r--r--dimension/tests/Makefile.am3
-rw-r--r--dimension/tests/cube.dmnsn14
-rw-r--r--dimension/tests/teapot.dmnsn230
3 files changed, 239 insertions, 8 deletions
diff --git a/dimension/tests/Makefile.am b/dimension/tests/Makefile.am
index 684b2aa..a6c0f15 100644
--- a/dimension/tests/Makefile.am
+++ b/dimension/tests/Makefile.am
@@ -18,7 +18,8 @@
###########################################################################
TESTS = demo.dmnsn \
- cube.dmnsn
+ cube.dmnsn \
+ teapot.dmnsn
TEST_EXTENSIONS = .dmnsn
DMNSN_LOG_COMPILER = $(top_srcdir)/dimension/dimension
AM_DMNSN_LOG_FLAGS = --strict -v
diff --git a/dimension/tests/cube.dmnsn b/dimension/tests/cube.dmnsn
index 5f74219..65387ab 100644
--- a/dimension/tests/cube.dmnsn
+++ b/dimension/tests/cube.dmnsn
@@ -42,20 +42,19 @@ objects.append(
)
)
-class ShinySphere(Sphere):
+class ShinySphere(Teapot):
def __init__(self, x, y, z, size):
size -= 1
dx = sin(2*pi*x/size)
dy = sin(2*pi*y/size)
dz = sin(2*pi*z/size)
- Sphere.__init__(
+ center = (5*Vector(x, y, z)/size
+ + Vector(dy + dz, dx + dz, dx + dy)/4
+ - Vector(2.5, 2.5, 2.5))
+ radius = 2/size
+ Teapot.__init__(
self,
- center = 5*Vector(x, y, z)/size
- + Vector(dy + dz, dx + dz, dx + dy)/4
- - Vector(2.5, 2.5, 2.5),
- radius = 2/size,
-
texture = Texture(
pigment = sRGB(x/size, y/size, z/size),
finish = Ambient(sRGB(0.25))
@@ -63,6 +62,7 @@ class ShinySphere(Sphere):
+ Reflection(0, 0.25)
)
)
+ self.scale(radius/2).translate(center)
size = 10
for x in range(size):
diff --git a/dimension/tests/teapot.dmnsn b/dimension/tests/teapot.dmnsn
new file mode 100644
index 0000000..bcc012a
--- /dev/null
+++ b/dimension/tests/teapot.dmnsn
@@ -0,0 +1,230 @@
+verticies = [
+ Vector( 0.2000, 0.0000, 2.70000), Vector( 0.2000, -0.1120, 2.70000),
+ Vector( 0.1120, -0.2000, 2.70000), Vector( 0.0000, -0.2000, 2.70000),
+ Vector( 1.3375, 0.0000, 2.53125), Vector( 1.3375, -0.7490, 2.53125),
+ Vector( 0.7490, -1.3375, 2.53125), Vector( 0.0000, -1.3375, 2.53125),
+ Vector( 1.4375, 0.0000, 2.53125), Vector( 1.4375, -0.8050, 2.53125),
+ Vector( 0.8050, -1.4375, 2.53125), Vector( 0.0000, -1.4375, 2.53125),
+ Vector( 1.5000, 0.0000, 2.40000), Vector( 1.5000, -0.8400, 2.40000),
+ Vector( 0.8400, -1.5000, 2.40000), Vector( 0.0000, -1.5000, 2.40000),
+ Vector( 1.7500, 0.0000, 1.87500), Vector( 1.7500, -0.9800, 1.87500),
+ Vector( 0.9800, -1.7500, 1.87500), Vector( 0.0000, -1.7500, 1.87500),
+ Vector( 2.0000, 0.0000, 1.35000), Vector( 2.0000, -1.1200, 1.35000),
+ Vector( 1.1200, -2.0000, 1.35000), Vector( 0.0000, -2.0000, 1.35000),
+ Vector( 2.0000, 0.0000, 0.90000), Vector( 2.0000, -1.1200, 0.90000),
+ Vector( 1.1200, -2.0000, 0.90000), Vector( 0.0000, -2.0000, 0.90000),
+ Vector(-2.0000, 0.0000, 0.90000), Vector( 2.0000, 0.0000, 0.45000),
+ Vector( 2.0000, -1.1200, 0.45000), Vector( 1.1200, -2.0000, 0.45000),
+ Vector( 0.0000, -2.0000, 0.45000), Vector( 1.5000, 0.0000, 0.22500),
+ Vector( 1.5000, -0.8400, 0.22500), Vector( 0.8400, -1.5000, 0.22500),
+ Vector( 0.0000, -1.5000, 0.22500), Vector( 1.5000, 0.0000, 0.15000),
+ Vector( 1.5000, -0.8400, 0.15000), Vector( 0.8400, -1.5000, 0.15000),
+ Vector( 0.0000, -1.5000, 0.15000), Vector(-1.6000, 0.0000, 2.02500),
+ Vector(-1.6000, -0.3000, 2.02500), Vector(-1.5000, -0.3000, 2.25000),
+ Vector(-1.5000, 0.0000, 2.25000), Vector(-2.3000, 0.0000, 2.02500),
+ Vector(-2.3000, -0.3000, 2.02500), Vector(-2.5000, -0.3000, 2.25000),
+ Vector(-2.5000, 0.0000, 2.25000), Vector(-2.7000, 0.0000, 2.02500),
+ Vector(-2.7000, -0.3000, 2.02500), Vector(-3.0000, -0.3000, 2.25000),
+ Vector(-3.0000, 0.0000, 2.25000), Vector(-2.7000, 0.0000, 1.80000),
+ Vector(-2.7000, -0.3000, 1.80000), Vector(-3.0000, -0.3000, 1.80000),
+ Vector(-3.0000, 0.0000, 1.80000), Vector(-2.7000, 0.0000, 1.57500),
+ Vector(-2.7000, -0.3000, 1.57500), Vector(-3.0000, -0.3000, 1.35000),
+ Vector(-3.0000, 0.0000, 1.35000), Vector(-2.5000, 0.0000, 1.12500),
+ Vector(-2.5000, -0.3000, 1.12500), Vector(-2.6500, -0.3000, 0.93750),
+ Vector(-2.6500, 0.0000, 0.93750), Vector(-2.0000, -0.3000, 0.90000),
+ Vector(-1.9000, -0.3000, 0.60000), Vector(-1.9000, 0.0000, 0.60000),
+ Vector( 1.7000, 0.0000, 1.42500), Vector( 1.7000, -0.6600, 1.42500),
+ Vector( 1.7000, -0.6600, 0.60000), Vector( 1.7000, 0.0000, 0.60000),
+ Vector( 2.6000, 0.0000, 1.42500), Vector( 2.6000, -0.6600, 1.42500),
+ Vector( 3.1000, -0.6600, 0.82500), Vector( 3.1000, 0.0000, 0.82500),
+ Vector( 2.3000, 0.0000, 2.10000), Vector( 2.3000, -0.2500, 2.10000),
+ Vector( 2.4000, -0.2500, 2.02500), Vector( 2.4000, 0.0000, 2.02500),
+ Vector( 2.7000, 0.0000, 2.40000), Vector( 2.7000, -0.2500, 2.40000),
+ Vector( 3.3000, -0.2500, 2.40000), Vector( 3.3000, 0.0000, 2.40000),
+ Vector( 2.8000, 0.0000, 2.47500), Vector( 2.8000, -0.2500, 2.47500),
+ Vector( 3.5250, -0.2500, 2.49375), Vector( 3.5250, 0.0000, 2.49375),
+ Vector( 2.9000, 0.0000, 2.47500), Vector( 2.9000, -0.1500, 2.47500),
+ Vector( 3.4500, -0.1500, 2.51250), Vector( 3.4500, 0.0000, 2.51250),
+ Vector( 2.8000, 0.0000, 2.40000), Vector( 2.8000, -0.1500, 2.40000),
+ Vector( 3.2000, -0.1500, 2.40000), Vector( 3.2000, 0.0000, 2.40000),
+ Vector( 0.0000, 0.0000, 3.15000), Vector( 0.8000, 0.0000, 3.15000),
+ Vector( 0.8000, -0.4500, 3.15000), Vector( 0.4500, -0.8000, 3.15000),
+ Vector( 0.0000, -0.8000, 3.15000), Vector( 0.0000, 0.0000, 2.85000),
+ Vector( 1.4000, 0.0000, 2.40000), Vector( 1.4000, -0.7840, 2.40000),
+ Vector( 0.7840, -1.4000, 2.40000), Vector( 0.0000, -1.4000, 2.40000),
+ Vector( 0.4000, 0.0000, 2.55000), Vector( 0.4000, -0.2240, 2.55000),
+ Vector( 0.2240, -0.4000, 2.55000), Vector( 0.0000, -0.4000, 2.55000),
+ Vector( 1.3000, 0.0000, 2.55000), Vector( 1.3000, -0.7280, 2.55000),
+ Vector( 0.7280, -1.3000, 2.55000), Vector( 0.0000, -1.3000, 2.55000),
+ Vector( 1.3000, 0.0000, 2.40000), Vector( 1.3000, -0.7280, 2.40000),
+ Vector( 0.7280, -1.3000, 2.40000), Vector( 0.0000, -1.3000, 2.40000),
+ Vector( 0.0000, 0.0000, 0.00000), Vector( 1.4250, -0.7980, 0.00000),
+ Vector( 1.5000, 0.0000, 0.07500), Vector( 1.4250, 0.0000, 0.00000),
+ Vector( 0.7980, -1.4250, 0.00000), Vector( 0.0000, -1.5000, 0.07500),
+ Vector( 0.0000, -1.4250, 0.00000), Vector( 1.5000, -0.8400, 0.07500),
+ Vector( 0.8400, -1.5000, 0.07500)
+]
+
+#print("static const dmnsn_vector dmnsn_teapot_verticies[%d] = {" % \
+# len(verticies))
+#for i in range(len(verticies)):
+# v = verticies[i]
+# v = Vector(v.x, v.z - 1.575, v.y)
+# print(" { .x = %+.5f, .y = %+.5f, .z = %+.5f }," % (v.x, v.y, v.z))
+#print("};")
+
+ntriangles = 0
+
+B = [
+ lambda x: (1 - x)*(1 -x)*(1 - x),
+ lambda x: 3*x*(1 - x)*(1 - x),
+ lambda x: 3*x*x*(1 - x),
+ lambda x: x*x*x,
+]
+Bprime = [
+ lambda x: -3*(1-x)*(1-x),
+ lambda x: 3*(1-x)*(1-x) - 6*x*(1-x),
+ lambda x: 6*x*(1-x) - 3*x*x,
+ lambda x: 3*x*x,
+]
+
+class _BicubicPatch(Union):
+ def __init__(self, indicies):
+ if len(indicies) != 16:
+ raise ValueError("expected 16 control points")
+
+ self.control_points = []
+ for i in indicies:
+ self.control_points.append(verticies[i])
+
+ resolution = 8
+ triangles = []
+ global ntriangles
+ for i in range(resolution):
+ for j in range(resolution):
+ a = self._eval(i/resolution, j/resolution)
+ an = self._eval_normal(i/resolution, j/resolution)
+ b = self._eval((i + 1)/resolution, j/resolution)
+ bn = self._eval_normal((i + 1)/resolution, j/resolution)
+ c = self._eval((i + 1)/resolution, (j + 1)/resolution)
+ cn = self._eval_normal((i + 1)/resolution, (j + 1)/resolution)
+ d = self._eval(i/resolution, (j + 1)/resolution)
+ dn = self._eval_normal(i/resolution, (j + 1)/resolution)
+ triangles.append(Triangle(a, b, c, an, bn, cn))
+ triangles.append(Triangle(c, d, a, cn, dn, an))
+ ntriangles += 2
+ if ntriangles%1000000 == 0:
+ print(ntriangles)
+
+ Union.__init__(self, triangles)
+
+ def _eval(self, u, v):
+ r = Vector(0)
+ for i in range(4):
+ for j in range(4):
+ r += self.control_points[4*j + i]*B[i](u)*B[j](v)
+ return r
+
+ def _eval_normal(self, u, v):
+ ru = Vector(0)
+ for i in range(4):
+ for j in range(4):
+ ru += self.control_points[4*j + i]*Bprime[i](u)*B[j](v)
+
+ rv = Vector(0)
+ for i in range(4):
+ for j in range(4):
+ rv += self.control_points[4*j + i]*B[i](u)*Bprime[j](v)
+
+ return cross(ru, rv)
+
+class _Teapot(Union):
+ def __init__(self, *args, **kwargs):
+ patches = [
+ self.reflectY(),
+ self.reflectY().scale(1, -1, 1),
+ ]
+ Union.__init__(self, patches, *args, **kwargs)
+ self.rotate(-90*X).translate(-1.575*Y)
+
+ @classmethod
+ def rim(cls):
+ return _BicubicPatch([
+ 102, 103, 104, 105, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+ ])
+
+ @classmethod
+ def body(cls):
+ body1 = _BicubicPatch([
+ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
+ ])
+ body2 = _BicubicPatch([
+ 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
+ ])
+ return Union([body1, body2])
+
+ @classmethod
+ def lid(cls):
+ lid1 = _BicubicPatch([
+ 96, 96, 96, 96, 97, 98, 99, 100, 101, 101, 101, 101, 0, 1, 2, 3
+ ])
+ lid2 = _BicubicPatch([
+ 0, 1, 2, 3, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117
+ ])
+ return Union([lid1, lid2])
+
+ @classmethod
+ def bottom(cls):
+ return _BicubicPatch([
+ 118, 118, 118, 118, 124, 122, 119, 121, 123, 126, 125, 120, 40, 39, 38, 37
+ ])
+
+ @classmethod
+ def reflectXY(cls):
+ return Union([
+ cls.rim(),
+ cls.body(),
+ cls.lid(),
+ cls.bottom(),
+ ])
+
+ @classmethod
+ def handle(cls):
+ handle1 = _BicubicPatch([
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56
+ ])
+ handle2 = _BicubicPatch([
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 65, 66, 67
+ ])
+ return Union([handle1, handle2])
+
+ @classmethod
+ def spout(cls):
+ spout1 = _BicubicPatch([
+ 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83
+ ])
+ spout2 = _BicubicPatch([
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95
+ ])
+ return Union([spout1, spout2])
+
+ @classmethod
+ def reflectY(cls):
+ return Union([
+ cls.reflectXY(),
+ cls.reflectXY().scale(-1, 1, 1),
+ cls.handle(),
+ cls.spout(),
+ ])
+
+camera = PerspectiveCamera(
+ location = -5*Z,
+ look_at = 0,
+)
+
+lights.append(PointLight(location = (-15, 20, -10), color = White))
+
+objects.append(Teapot(pigment = White).rotate(-80*X))
+
+if ntriangles > 0:
+ print(ntriangles)