diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-06-01 17:00:37 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-06-01 17:00:37 -0400 |
commit | d0825a136ff65b36069ff8b078b9fd97adeed0df (patch) | |
tree | ca47a0bfb495d8795e3fba7c7315215a5d7f5513 /solid.py | |
parent | b0f5fa8f463136ee8fb5401b3aa76d1b087997d2 (diff) | |
download | chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.tar.gz chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.tar.bz2 chroma-d0825a136ff65b36069ff8b078b9fd97adeed0df.zip |
first step towards moving to a new mesh/solid/geometry structure
Diffstat (limited to 'solid.py')
-rw-r--r-- | solid.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/solid.py b/solid.py new file mode 100644 index 0000000..fe22463 --- /dev/null +++ b/solid.py @@ -0,0 +1,58 @@ +import numpy as np + +class Solid(object): + def __init__(self, id, mesh, rotation=np.identity(3), displacement=(0,0,0), + material1=None, material2=None, surface1=None, surface2=None, + color=None): + self.id = id + self.mesh = mesh + + if rotation.shape != (3,3): + raise ValueError('shape mismatch') + + self.rotation = rotation + + displacement = np.asarray(displacement) + + if displacement.shape != (3,): + raise ValueError('shape mismatch') + + self.displacement = displacement + + if np.iterable(material1): + if len(material1) != len(mesh): + raise ValueError('shape mismatch') + self.material1 = np.array(material1, dtype=np.object) + else: + self.material1 = np.tile(material1, len(self.mesh)) + + if np.iterable(material2): + if len(material2) != len(mesh): + raise ValueError('shape mismatch') + self.material2 = np.array(material2, dtype=np.object) + else: + self.material2 = np.tile(material2, len(self.mesh)) + + if np.iterable(surface1): + if len(surface1) != len(mesh): + raise ValueError('shape mismatch') + self.surface1 = np.array(surface1, dtype=np.object) + else: + self.surface1 = np.tile(surface1, len(self.mesh)) + + if np.iterable(surface2): + if len(surface2) != len(mesh): + raise ValueError('shape mismatch') + self.surface2 = np.array(surface2, dtype=np.object) + else: + self.surface2 = np.tile(surface2, len(self.mesh)) + + if np.iterable(color): + if len(color) != len(mesh): + raise ValueError('shape mismatch') + self.color = np.array(color, dtype=np.uint32) + else: + self.color = np.tile(color, len(self.mesh)) + + def build(self): + return np.inner(self.mesh.build(), self.rotation) + self.displacement |