Esempio n. 1
0
    def import_bhkcapsule_shape(self, bhk_shape):
        """Import a BhkCapsule block as a simple cylinder collision object"""
        NifLog.debug(f"Importing {bhk_shape.__class__.__name__}")

        radius = bhk_shape.radius * self.HAVOK_SCALE
        p_1 = bhk_shape.first_point
        p_2 = bhk_shape.second_point
        length = (p_1 - p_2).norm() * self.HAVOK_SCALE
        first_point = p_1 * self.HAVOK_SCALE
        second_point = p_2 * self.HAVOK_SCALE
        minx = miny = -radius
        maxx = maxy = +radius
        minz = -radius - length / 2
        maxz = length / 2 + radius

        # create blender object
        b_obj = Object.box_from_extents("capsule", minx, maxx, miny, maxy,
                                        minz, maxz)
        # here, these are not encoded as a direction so we must first calculate the direction
        b_obj.matrix_local = self.center_origin_to_matrix(
            (first_point + second_point) / 2, first_point - second_point)
        self.set_b_collider(b_obj,
                            bounds_type="CAPSULE",
                            display_type="CAPSULE",
                            radius=radius,
                            n_obj=bhk_shape)
        return [b_obj]
Esempio n. 2
0
    def import_bhksphere_shape(self, bhk_shape):
        """Import a BhkSphere block as a simple sphere collision object"""
        NifLog.debug(f"Importing {bhk_shape.__class__.__name__}")

        r = bhk_shape.radius * self.HAVOK_SCALE
        b_obj = Object.box_from_extents("sphere", -r, r, -r, r, -r, r)
        self.set_b_collider(b_obj, display_type="SPHERE", bounds_type='SPHERE', radius=r, n_obj=bhk_shape)
        return [b_obj]
Esempio n. 3
0
 def import_boxbv(self, box):
     offset = box.center
     # ignore for now, seems to be a unity 3x3 matrix
     axes = box.axis
     x, y, z = box.extent
     b_obj = Object.box_from_extents("box", -x, x, -y, y, -z, z)
     b_obj.location = (offset.x, offset.y, offset.z)
     self.set_b_collider(b_obj, radius=(x + y + z) / 3)
     return [b_obj]
Esempio n. 4
0
 def import_spherebv(self, sphere):
     r = sphere.radius
     c = sphere.center
     b_obj = Object.box_from_extents("sphere", -r, r, -r, r, -r, r)
     b_obj.location = (c.x, c.y, c.z)
     self.set_b_collider(b_obj,
                         bounds_type="SPHERE",
                         display_type='SPHERE',
                         radius=r)
     return [b_obj]
Esempio n. 5
0
    def import_bounding_box(self, n_block):
        """Import a NiNode's bounding box or attached BSBound extra data."""
        if not n_block or not isinstance(n_block, NifFormat.NiNode):
            return []
        # we have a ninode with bounding box
        if n_block.has_bounding_box:
            b_name = 'Bounding Box'

            # Ninode's bbox behaves like a seperate mesh.
            # bounding_box center(n_block.bounding_box.translation) is relative to the bound_box
            n_bl_trans = n_block.translation
            n_bbox = n_block.bounding_box
            n_b_trans = n_bbox.translation
            minx = n_b_trans.x - n_bl_trans.x - n_bbox.radius.x
            miny = n_b_trans.y - n_bl_trans.y - n_bbox.radius.y
            minz = n_b_trans.z - n_bl_trans.z - n_bbox.radius.z
            maxx = n_b_trans.x - n_bl_trans.x + n_bbox.radius.x
            maxy = n_b_trans.y - n_bl_trans.y + n_bbox.radius.y
            maxz = n_b_trans.z - n_bl_trans.z + n_bbox.radius.z
            bbox_center = n_b_trans.as_list()

        # we may still have a BSBound extra data attached to this node
        else:
            for n_extra in n_block.get_extra_datas():
                # TODO [extra][data] Move to property processor
                if isinstance(n_extra, NifFormat.BSBound):
                    b_name = 'BSBound'
                    center = n_extra.center
                    dims = n_extra.dimensions
                    minx = -dims.x
                    miny = -dims.y
                    minz = -dims.z
                    maxx = +dims.x
                    maxy = +dims.y
                    maxz = +dims.z
                    bbox_center = center.as_list()
                    break
            # none was found
            else:
                return []

        # create blender object
        b_obj = Object.box_from_extents(b_name, minx, maxx, miny, maxy, minz,
                                        maxz)
        # probably only on NiNodes with BB
        if hasattr(n_block, "flags"):
            b_obj.niftools.flags = n_block.flags
        b_obj.location = bbox_center
        self.set_b_collider(b_obj, radius=max(maxx, maxy, maxz))
        return [
            b_obj,
        ]
Esempio n. 6
0
    def import_bhkbox_shape(self, bhk_shape):
        """Import a BhkBox block as a simple Box collision object"""
        NifLog.debug(f"Importing {bhk_shape.__class__.__name__}")

        # create box
        r = bhk_shape.radius * self.HAVOK_SCALE
        dims = bhk_shape.dimensions
        minx = -dims.x * self.HAVOK_SCALE
        maxx = +dims.x * self.HAVOK_SCALE
        miny = -dims.y * self.HAVOK_SCALE
        maxy = +dims.y * self.HAVOK_SCALE
        minz = -dims.z * self.HAVOK_SCALE
        maxz = +dims.z * self.HAVOK_SCALE

        # create blender object
        b_obj = Object.box_from_extents("box", minx, maxx, miny, maxy, minz, maxz)
        self.set_b_collider(b_obj, radius=r, n_obj=bhk_shape)
        return [b_obj]
Esempio n. 7
0
    def import_capsulebv(self, capsule):
        offset = capsule.center
        # always a normalized vector
        direction = capsule.origin
        # nb properly named in newer nif.xmls
        extent = capsule.unknown_float_1
        radius = capsule.unknown_float_2

        # positions of the box verts
        minx = miny = -radius
        maxx = maxy = +radius
        minz = -(extent + 2 * radius) / 2
        maxz = +(extent + 2 * radius) / 2

        # create blender object
        b_obj = Object.box_from_extents("capsule", minx, maxx, miny, maxy,
                                        minz, maxz)
        # apply transform in local space
        b_obj.matrix_local = self.center_origin_to_matrix(offset, direction)
        self.set_b_collider(b_obj,
                            bounds_type="CAPSULE",
                            display_type="CAPSULE",
                            radius=radius)
        return [b_obj]