diff options
Diffstat (limited to 'libdimension-python')
-rw-r--r-- | libdimension-python/dimension.pxd | 41 | ||||
-rw-r--r-- | libdimension-python/dimension.pyx | 38 |
2 files changed, 31 insertions, 48 deletions
diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index 33f2300..f5a723c 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -33,8 +33,6 @@ cdef extern from "../libdimension/dimension.h": ctypedef void dmnsn_callback_fn(void *ptr) - void DMNSN_INCREF(void *) - void dmnsn_die_on_warnings(bint always_die) double dmnsn_epsilon @@ -318,28 +316,23 @@ cdef extern from "../libdimension/dimension.h": dmnsn_matrix trans dmnsn_matrix intrinsic_trans - dmnsn_object *dmnsn_new_object() - void dmnsn_delete_object(dmnsn_object *object) - - dmnsn_object *dmnsn_new_flat_triangle(dmnsn_vector a, - dmnsn_vector b, - dmnsn_vector c) - dmnsn_object *dmnsn_new_triangle(dmnsn_vector a, - dmnsn_vector b, - dmnsn_vector c, - dmnsn_vector na, - dmnsn_vector nb, - dmnsn_vector nc) - dmnsn_object *dmnsn_new_plane(dmnsn_vector normal) - dmnsn_object *dmnsn_new_sphere() - dmnsn_object *dmnsn_new_cube() - dmnsn_object *dmnsn_new_cone(double r1, double r2, bint open) - dmnsn_object *dmnsn_new_torus(double major, double minor) - - dmnsn_object *dmnsn_new_csg_union(dmnsn_array *objects) - dmnsn_object *dmnsn_new_csg_intersection(dmnsn_object *A, dmnsn_object *B) - dmnsn_object *dmnsn_new_csg_difference(dmnsn_object *A, dmnsn_object *B) - dmnsn_object *dmnsn_new_csg_merge(dmnsn_object *A, dmnsn_object *B) + dmnsn_object *dmnsn_new_object(dmnsn_pool *pool) + + dmnsn_object *dmnsn_new_flat_triangle(dmnsn_pool *pool, dmnsn_vector a, dmnsn_vector b, dmnsn_vector c) + dmnsn_object *dmnsn_new_triangle( + dmnsn_pool *pool, + dmnsn_vector a, dmnsn_vector b, dmnsn_vector c, + dmnsn_vector na, dmnsn_vector nb, dmnsn_vector nc) + dmnsn_object *dmnsn_new_plane(dmnsn_pool *pool, dmnsn_vector normal) + dmnsn_object *dmnsn_new_sphere(dmnsn_pool *pool) + dmnsn_object *dmnsn_new_cube(dmnsn_pool *pool) + dmnsn_object *dmnsn_new_cone(dmnsn_pool *pool, double r1, double r2, bint open) + dmnsn_object *dmnsn_new_torus(dmnsn_pool *pool, double major, double minor) + + dmnsn_object *dmnsn_new_csg_union(dmnsn_pool *pool, dmnsn_array *objects) + dmnsn_object *dmnsn_new_csg_intersection(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B) + dmnsn_object *dmnsn_new_csg_difference(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B) + dmnsn_object *dmnsn_new_csg_merge(dmnsn_pool *pool, dmnsn_object *A, dmnsn_object *B) ########## # Lights # diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 2ab683d..d8bbb3a 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -1080,9 +1080,6 @@ cdef class Object(_Transformable): if interior is not None: self.interior = interior - def __dealloc__(self): - dmnsn_delete_object(self._object) - property texture: """The object's Texture.""" def __get__(self): @@ -1132,10 +1129,11 @@ cdef class Triangle(Object): a_normal = cross(b - a, c - a) b_normal = a_normal c_normal = a_normal - self._object = dmnsn_new_triangle(Vector(a)._v, Vector(b)._v, Vector(c)._v, - Vector(a_normal)._v, - Vector(b_normal)._v, - Vector(c_normal)._v) + self._object = dmnsn_new_triangle( + _get_pool(), + Vector(a)._v, Vector(b)._v, Vector(c)._v, + Vector(a_normal)._v, Vector(b_normal)._v, Vector(c_normal)._v + ) Object.__init__(self, *args, **kwargs) cdef class Plane(Object): @@ -1151,7 +1149,7 @@ cdef class Plane(Object): Additionally, Plane() accepts any arguments that Object() accepts. """ - self._object = dmnsn_new_plane(Vector(normal)._v) + self._object = dmnsn_new_plane(_get_pool(), Vector(normal)._v) Object.__init__(self, *args, **kwargs) self._intrinsic_transform(translate(distance*Vector(normal))) @@ -1168,7 +1166,7 @@ cdef class Sphere(Object): Additionally, Sphere() accepts any arguments that Object() accepts. """ - self._object = dmnsn_new_sphere() + self._object = dmnsn_new_sphere(_get_pool()) Object.__init__(self, *args, **kwargs) cdef Matrix trans = translate(Vector(center)) @@ -1187,7 +1185,7 @@ cdef class Box(Object): Additionally, Box() accepts any arguments that Object() accepts. """ - self._object = dmnsn_new_cube() + self._object = dmnsn_new_cube(_get_pool()) Object.__init__(self, *args, **kwargs) min = Vector(min) @@ -1212,7 +1210,7 @@ cdef class Cone(Object): Additionally, Cone() accepts any arguments that Object() accepts. """ - self._object = dmnsn_new_cone(bottom_radius, top_radius, open) + self._object = dmnsn_new_cone(_get_pool(), bottom_radius, top_radius, open) Object.__init__(self, *args, **kwargs) # Lift the cone to start at the origin, then scale, rotate, and translate @@ -1261,7 +1259,7 @@ cdef class Torus(Object): Additionally, Torus() accepts any arguments that Object() accepts. """ - self._object = dmnsn_new_torus(major_radius, minor_radius) + self._object = dmnsn_new_torus(_get_pool(), major_radius, minor_radius) Object.__init__(self, *args, **kwargs) cdef class Union(Object): @@ -1284,10 +1282,9 @@ cdef class Union(Object): try: for obj in objects: o = (<Object?>obj)._object - DMNSN_INCREF(o) dmnsn_array_push(array, &o) - self._object = dmnsn_new_csg_union(array) + self._object = dmnsn_new_csg_union(_get_pool(), array) finally: dmnsn_delete_array(array) @@ -1312,11 +1309,9 @@ cdef class Intersection(Object): for obj in objects: if self._object == NULL: self._object = (<Object?>obj)._object - DMNSN_INCREF(self._object) else: o = (<Object?>obj)._object - DMNSN_INCREF(o) - self._object = dmnsn_new_csg_intersection(self._object, o) + self._object = dmnsn_new_csg_intersection(_get_pool(), self._object, o) Object.__init__(self, *args, **kwargs) @@ -1339,11 +1334,9 @@ cdef class Difference(Object): for obj in objects: if self._object == NULL: self._object = (<Object?>obj)._object - DMNSN_INCREF(self._object) else: o = (<Object?>obj)._object - DMNSN_INCREF(o) - self._object = dmnsn_new_csg_difference(self._object, o) + self._object = dmnsn_new_csg_difference(_get_pool(), self._object, o) Object.__init__(self, *args, **kwargs) @@ -1366,11 +1359,9 @@ cdef class Merge(Object): for obj in objects: if self._object == NULL: self._object = (<Object?>obj)._object - DMNSN_INCREF(self._object) else: o = (<Object?>obj)._object - DMNSN_INCREF(o) - self._object = dmnsn_new_csg_merge(self._object, o) + self._object = dmnsn_new_csg_merge(_get_pool(), self._object, o) Object.__init__(self, *args, **kwargs) @@ -1479,7 +1470,6 @@ cdef class Scene: cdef dmnsn_object *o for obj in objects: o = (<Object?>obj)._object - DMNSN_INCREF(o) dmnsn_array_push(self._scene.objects, &o) cdef dmnsn_light *l |