예제 #1
0
 def vectorArrayFromList(cls, vectorList):
     dims = len(vectorList[0])
     if dims == 2:
         vectorArray = osg.Vec2Array(len(vectorList))
     elif dims == 3:
         vectorArray = osg.Vec3Array(len(vectorList))
     elif dims == 4:
         vectorArray = osg.Vec4Array(len(vectorList))
     else:
         raise ValueError, gettext('Vector arrays can only be created with vectors of 2, 3 or 4 dimensions.')
     arrayPointer = pointer(c_float.from_address(int(vectorArray.getDataPointer()))) # pylint: disable=E1101
     vectorSize = vectorArray.getDataSize()
     offset = 0
     for vector in vectorList:
         for dim in range(dims):
             arrayPointer[offset + dim] = vector[dim]
         offset += vectorSize
     return vectorArray
예제 #2
0
 def vectorArrayFromList(cls, vectorList):
     dims = len(vectorList[0])
     if dims == 2:
         vectorArray = osg.Vec2Array(len(vectorList))
     elif dims == 3:
         vectorArray = osg.Vec3Array(len(vectorList))
     elif dims == 4:
         vectorArray = osg.Vec4Array(len(vectorList))
     else:
         raise ValueError, gettext('Vector arrays can only be created with vectors of 2, 3 or 4 dimensions.')
     arrayPointer = pointer(c_float.from_address(int(vectorArray.getDataPointer()))) # pylint: disable=E1101
     vectorSize = vectorArray.getDataSize()
     offset = 0
     for vector in vectorList:
         for dim in range(dims):
             arrayPointer[offset + dim] = vector[dim]
         offset += vectorSize
     return vectorArray
예제 #3
0
 def update_at_address(self, address):
     c_float.from_address(address).value = self.value
예제 #4
0
    def __init__(self, data):
        self.data = data
        self.start = cast(c_char_p(self.data), c_void_p).value
        self.header = Header.from_address(self.start)
        vertex_count = c_ushort.from_address(self.start + sizeof(Header))
        self.vertices = Array(
            type=Vertex,
            address=self.start + sizeof(Header) + sizeof(c_ushort),
            amount=vertex_count.value,
        )

        triangle_count = c_ushort.from_address(self.vertices.end)
        self.triangles = Array(
            type=Triangle,
            address=self.vertices.end + sizeof(c_ushort),
            amount=triangle_count.value,
        )

        group_count = c_ushort.from_address(self.triangles.end)
        self.groups = []
        addr = self.triangles.end + sizeof(c_ushort)
        for i in range(group_count.value):
            self.groups.append(Group(addr))
            addr = self.groups[-1].end

        material_count = c_ushort.from_address(addr)
        self.materials = Array(
            type=Material,
            address=addr + sizeof(c_ushort),
            amount=material_count.value,
        )

        addr = self.materials.end

        self.fps = c_float.from_address(addr)
        addr += sizeof(c_float)

        self.current_time = c_float.from_address(addr)
        addr += sizeof(c_float)

        self.frame_count = c_int.from_address(addr)
        addr += sizeof(c_int)

        joint_count = c_ushort.from_address(addr)
        addr += sizeof(c_ushort)

        self.joints = []
        for i in range(joint_count.value):
            joint = Joint(addr)
            self.joints.append(joint)
            addr = joint.end

        sub_version = c_int.from_address(addr)  # should be 1
        addr += sizeof(c_int)

        group_comment_count = c_uint.from_address(addr)
        addr += sizeof(c_uint)
        #fixme implement group comments (count is currently 0)

        material_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement material comments (count is currently 0)

        joint_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement joint comments (count is currently 0)

        model_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement model comments (count is currently 0)

        sub_version = c_int.from_address(addr).value
        addr += sizeof(c_int)

        if sub_version == 1:
            extra_type = VertexExtra1
        elif sub_version == 2:
            raise NotImplemented()

        self.vertex_extras = Array(
            type=extra_type,
            address=addr,
            amount=vertex_count.value,
        )
        addr = self.vertex_extras.end

        assert addr - self.start == len(data)
예제 #5
0
 def update_at_address(self, address):
     c_float.from_address(address + 0).value = self.value.x
     c_float.from_address(address + 4).value = self.value.y
     c_float.from_address(address + 8).value = self.value.z
예제 #6
0
    def __init__(self, data):
        self.data = data
        self.start = cast(c_char_p(self.data), c_void_p).value
        self.header = Header.from_address(self.start)
        vertex_count = c_ushort.from_address(self.start + sizeof(Header))
        self.vertices = Array(
            type    = Vertex,
            address = self.start + sizeof(Header) + sizeof(c_ushort),
            amount  = vertex_count.value,
        )

        triangle_count = c_ushort.from_address(self.vertices.end)
        self.triangles = Array(
            type    = Triangle,
            address = self.vertices.end + sizeof(c_ushort),
            amount  = triangle_count.value,
        )

        group_count = c_ushort.from_address(self.triangles.end)
        self.groups = []
        addr = self.triangles.end+sizeof(c_ushort)
        for i in range(group_count.value):
            self.groups.append(Group(addr))
            addr = self.groups[-1].end

        material_count = c_ushort.from_address(addr)
        self.materials = Array(
            type    = Material,
            address = addr + sizeof(c_ushort),
            amount  = material_count.value,
        )

        addr = self.materials.end

        self.fps = c_float.from_address(addr)
        addr += sizeof(c_float)

        self.current_time = c_float.from_address(addr)
        addr += sizeof(c_float)

        self.frame_count = c_int.from_address(addr)
        addr += sizeof(c_int)

        joint_count = c_ushort.from_address(addr)
        addr += sizeof(c_ushort)

        self.joints = []
        for i in range(joint_count.value):
            joint = Joint(addr)
            self.joints.append(joint)
            addr = joint.end

        sub_version = c_int.from_address(addr) # should be 1
        addr += sizeof(c_int)

        group_comment_count = c_uint.from_address(addr)
        addr += sizeof(c_uint)
        #fixme implement group comments (count is currently 0)

        material_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement material comments (count is currently 0)

        joint_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement joint comments (count is currently 0)

        model_comment_count = c_int.from_address(addr)
        addr += sizeof(c_int)
        #fixme implement model comments (count is currently 0)

        sub_version = c_int.from_address(addr).value
        addr += sizeof(c_int)

        if sub_version == 1:
            extra_type = VertexExtra1
        elif sub_version == 2:
            raise NotImplemented()

        self.vertex_extras = Array(
            type    = extra_type,
            address = addr,
            amount  = vertex_count.value,
        )
        addr = self.vertex_extras.end

        assert addr - self.start == len(data)