def test_write_read(self): expected = RGBA(r=244, g=123, b=33, a=99) io_stream = io.BytesIO() expected.write(io_stream) io_stream = io.BytesIO(io_stream.getvalue()) self.assertEqual(expected, RGBA.read(io_stream))
def read(io_stream): return VertexMaterialInfo(attributes=read_long(io_stream), ambient=RGBA.read(io_stream), diffuse=RGBA.read(io_stream), specular=RGBA.read(io_stream), emissive=RGBA.read(io_stream), shininess=read_float(io_stream), opacity=read_float(io_stream), translucency=read_float(io_stream))
def read(context, io_stream): type = read_long(io_stream) read_long(io_stream) # num available chars name = read_string(io_stream) result = ShaderMaterialProperty(type=type, name=name) if result.type == 1: read_long(io_stream) # num available chars result.value = read_string(io_stream) elif result.type == 2: result.value = read_float(io_stream) elif result.type == 3: result.value = read_vector2(io_stream) elif result.type == 4: result.value = read_vector(io_stream) elif result.type == 5: result.value = RGBA.read_f(io_stream) elif result.type == 6: result.value = read_long(io_stream) elif result.type == 7: result.value = read_ubyte(io_stream) else: message = "WARNING: unknown property type in shader material: %s" % result.type print(message) context.report({'ERROR'}, message) return result
def read(io_stream): ver = Version.read(io_stream) flags = read_ulong(io_stream) return Box(version=ver, box_type=(flags & 0b11), collision_types=(flags & 0xFF0), name_=read_long_fixed_string(io_stream), color=RGBA.read(io_stream), center=read_vector(io_stream), extend=read_vector(io_stream))
class VertexMaterialInfo(Struct): attributes = 0 ambient = RGBA() # alpha is only padding in this and below diffuse = RGBA() specular = RGBA() emissive = RGBA() shininess = 0.0 opacity = 0.0 translucency = 0.0 @staticmethod def read(io_stream): return VertexMaterialInfo(attributes=read_long(io_stream), ambient=RGBA.read(io_stream), diffuse=RGBA.read(io_stream), specular=RGBA.read(io_stream), emissive=RGBA.read(io_stream), shininess=read_float(io_stream), opacity=read_float(io_stream), translucency=read_float(io_stream)) @staticmethod def size(include_head=True): return const_size(32, include_head) def write(self, io_stream): write_chunk_head(W3D_CHUNK_VERTEX_MATERIAL_INFO, io_stream, self.size(False)) write_long(self.attributes, io_stream) self.ambient.write(io_stream) self.diffuse.write(io_stream) self.specular.write(io_stream) self.emissive.write(io_stream) write_float(self.shininess, io_stream) write_float(self.opacity, io_stream) write_float(self.translucency, io_stream)
class Box(Struct): version = Version() box_type = 0 collision_types = 0 name_ = "" color = RGBA() center = Vector((0.0, 0.0, 0.0)) extend = Vector((0.0, 0.0, 0.0)) def name(self): if '.' in self.name_: return self.name_.split('.')[1] return self.name_ @staticmethod def read(io_stream): ver = Version.read(io_stream) flags = read_ulong(io_stream) return Box(version=ver, box_type=(flags & 0b11), collision_types=(flags & 0xFF0), name_=read_long_fixed_string(io_stream), color=RGBA.read(io_stream), center=read_vector(io_stream), extend=read_vector(io_stream)) @staticmethod def size(): return 68 def write(self, io_stream): write_chunk_head(W3D_CHUNK_BOX, io_stream, self.size()) self.version.write(io_stream) write_ulong((self.collision_types & 0xFF) | (self.box_type & 0b11), io_stream) write_long_fixed_string(self.name_, io_stream) self.color.write(io_stream) write_vector(self.center, io_stream) write_vector(self.extend, io_stream)
def test_to_string(self): rgba = RGBA(r=244, g=123, b=33, a=99) expected = "RGBA(r:244, g:123, b:33, a:99)" self.assertEqual(expected, str(rgba))
def test_eq_false(self): rgba = RGBA(r=2, g=3, b=0, a=0) self.assertNotEqual(rgba, "test") self.assertNotEqual(rgba, 1)
def test_eq_true(self): rgba = RGBA(r=244, g=222, b=1, a=0) self.assertEqual(rgba, rgba)
def get_rgba(a=0): return RGBA(r=3, g=200, b=44, a=a)