Ejemplo n.º 1
0
    def test_sharpEdgeAdjacentsHasSameSmoothingGroups(self):
        # Arrange
        bm = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0), (+1, -1, 0), (+1, +1, 0), (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)))
        bm.edges.ensure_lookup_table()
        bm.edges[0].smooth = False
        obj = utils.create_object(bm)

        # Act
        bpy.ops.xray_export.object(
            objects=obj.name, directory=self.outpath(),
            texture_name_from_image_path=False,
            export_motions=False,
        )

        # Assert
        self.assertOutputFiles({
            obj.name + '.object',
        })
        self.assertReportsContains(
            'WARNING',
            re.compile('Maya-SG incompatible: sharp edge adjacents has same smoothing group')
        )
Ejemplo n.º 2
0
    def _create_dm_objects(self, create_uv=True, create_material=True):
        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), create_uv)

        objs = []
        for i in range(3):
            obj = utils.create_object(bmesh, create_material)
            obj.name = 'tdm%d' % (i + 1)
            objs.append(obj)
            bpy_texture = bpy.data.textures.new('test_texture', 'IMAGE')
            bpy_image = bpy.data.images.new('test_image.dds', 0, 0)
            bpy_image.source = 'FILE'
            bpy_image.filepath = 'test_image.dds'
            if bpy.app.version >= (2, 80, 0):
                obj.data.materials[0].use_nodes = True
                node_tree = obj.data.materials[0].node_tree
                texture_node = node_tree.nodes.new('ShaderNodeTexImage')
                texture_node.image = bpy_image
                texture_node.location.x -= 500
                princ_shader = node_tree.nodes['Principled BSDF']
                node_tree.links.new(texture_node.outputs['Color'],
                                    princ_shader.inputs['Base Color'])
            else:
                bpy_texture.image = bpy_image
                texture_slot = obj.data.materials[0].texture_slots.add()
                texture_slot.texture = bpy_texture
        return objs
Ejemplo n.º 3
0
def _prepare_animation():
    arm = bpy.data.armatures.new('test')
    obj = bpy.data.objects.new('test', arm)
    utils.link_object(obj)
    utils.set_active_object(obj)
    bpy.ops.object.mode_set(mode='EDIT')
    try:
        bone = arm.edit_bones.new('bone')
        bone.head.z = 0.5
        cbone = arm.edit_bones.new('cbone')
        cbone.parent = bone
        cbone.head.z = 0.5
    finally:
        bpy.ops.object.mode_set(mode='OBJECT')

    pbone = obj.pose.bones['bone']
    pbone.keyframe_insert('location', frame=1, group='bone')
    pbone.location = (1, 2, 3)
    pbone.keyframe_insert('location', frame=5, group='bone')

    motion = obj.xray.motions_collection.add()
    motion.name = bpy.data.actions[0].name

    bmesh = utils.create_bmesh((
        (0, 0, 0),
        (-1, -1, 0), (+1, -1, 0), (+1, +1, 0), (-1, +1, 0),
    ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), True)
    obj_me = utils.create_object(bmesh, True)
    group = obj_me.vertex_groups.new(name='bone')
    group.add(range(len(obj_me.data.vertices)), 1, 'REPLACE')
    obj_me.parent = obj
    obj_me.xray.isroot = False

    return obj
Ejemplo n.º 4
0
    def _create_details_objects(self,
                                version,
                                create_uv=True,
                                create_material=True):
        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), create_uv)

        root_object = bpy.data.objects.new('Details', None)
        bpy.ops.object.select_all(action='DESELECT')
        utils.link_object(root_object)
        if bpy.app.version >= (2, 80, 0):
            root_object.select_set(True)
        else:
            root_object.select = True
        root_object.xray.is_details = True
        data = root_object.xray.detail

        self._create_details_images(data, version)
        self._create_details_slots_objects(data)

        meshes_object = bpy.data.objects.new('DM Meshes', None)
        utils.link_object(meshes_object)
        meshes_object.parent = root_object

        data.slots.meshes_object = meshes_object.name

        objs = []
        for i in range(3):
            obj = utils.create_object(bmesh, create_material)
            obj.name = 'tdm%d' % (i + 1)
            obj.parent = meshes_object
            obj.xray.is_details = True
            obj.xray.detail.model.index = i
            objs.append(obj)
            bpy_texture = bpy.data.textures.new('test_texture', 'IMAGE')
            bpy_image = bpy.data.images.new('test_image.dds', 0, 0)
            bpy_image.source = 'FILE'
            bpy_image.filepath = 'test_image.dds'
            if bpy.app.version >= (2, 80, 0):
                obj.data.materials[0].use_nodes = True
                node_tree = obj.data.materials[0].node_tree
                texture_node = node_tree.nodes.new('ShaderNodeTexImage')
                texture_node.image = bpy_image
                texture_node.location.x -= 500
                princ_shader = node_tree.nodes['Principled BSDF']
                node_tree.links.new(texture_node.outputs['Color'],
                                    princ_shader.inputs['Base Color'])
            else:
                bpy_texture.image = bpy_image
                texture_slot = obj.data.materials[0].texture_slots.add()
                texture_slot.texture = bpy_texture
        return objs
Ejemplo n.º 5
0
    def _create_objects(self):
        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0), (+1, -1, 0), (+1, +1, 0), (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)))

        objs = []
        for i in range(3):
            obj = utils.create_object(bmesh)
            obj.name = 'tobj%d' % (i + 1)
            objs.append(obj)
        objs[1].xray.export_path = 'a/b'
        return objs
Ejemplo n.º 6
0
    def test_import_sg_maya(self):
        # Arrange
        arm = bpy.data.armatures.new('test')
        obj = bpy.data.objects.new('test', arm)
        utils.link_object(obj)
        utils.set_active_object(obj)
        bpy.ops.object.mode_set(mode='EDIT')
        try:
            bone = arm.edit_bones.new('non-exp')
            bone.head.z = 0.5
            bone = arm.edit_bones.new('exp')
            bone.head.z = 0.5
        finally:
            bpy.ops.object.mode_set(mode='OBJECT')
        arm.bones['non-exp'].xray.exportable = False

        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), True)
        obj_me = utils.create_object(bmesh, True)
        obj_me.parent = obj
        obj_me.xray.isroot = False
        group = obj_me.vertex_groups.new(name='exp')
        group.add(range(len(obj_me.data.vertices)), 1, 'REPLACE')

        # Act
        bpy.ops.xray_export.object(
            objects=obj.name,
            directory=self.outpath(),
            texture_name_from_image_path=False,
            export_motions=False,
        )

        # Assert
        bpy.ops.xray_import.object(
            directory=self.outpath(),
            files=[{
                'name': 'test.object'
            }],
        )

        obj_arm = bpy.data.objects[-1]
        self.assertEqual(obj_arm.type, 'ARMATURE')
        self.assertEqual(obj_arm.xray.isroot, True)

        imp_arm = bpy.data.armatures[1]
        self.assertEqual(len(imp_arm.bones), 1)
    def _create_details_objects(self,
                                version,
                                create_uv=True,
                                create_material=True):
        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), create_uv)

        root_object = bpy.data.objects.new('Details', None)
        bpy.ops.object.select_all(action='DESELECT')
        root_object.select = True
        bpy.context.scene.objects.link(root_object)
        root_object.xray.is_details = True
        data = root_object.xray.detail

        self._create_details_images(data, version)
        self._create_details_slots_objects(data)

        meshes_object = bpy.data.objects.new('DM Meshes', None)
        bpy.context.scene.objects.link(meshes_object)
        meshes_object.parent = root_object

        data.slots.meshes_object = meshes_object.name

        objs = []
        for i in range(3):
            obj = utils.create_object(bmesh, create_material)
            obj.name = 'tdm%d' % (i + 1)
            obj.parent = meshes_object
            obj.xray.is_details = True
            obj.xray.detail.model.index = i
            objs.append(obj)
            bpy_texture = bpy.data.textures.new('test_texture', 'IMAGE')
            bpy_image = bpy.data.images.new('test_image.dds', 0, 0)
            bpy_image.source = 'FILE'
            bpy_image.filepath = 'test_image.dds'
            texture_slot = obj.data.materials[0].texture_slots.add()
            texture_slot.texture = bpy_texture
        return objs
Ejemplo n.º 8
0
    def _create_dm_objects(self, create_uv=True, create_material=True):
        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), create_uv)

        objs = []
        for i in range(3):
            obj = utils.create_object(bmesh, create_material)
            obj.name = 'tdm%d' % (i + 1)
            objs.append(obj)
            bpy_texture = bpy.data.textures.new('test_texture', 'IMAGE')
            bpy_image = bpy.data.images.new('test_image.dds', 0, 0)
            bpy_image.source = 'FILE'
            bpy_image.filepath = 'test_image.dds'
            texture_slot = obj.data.materials[0].texture_slots.add()
            texture_slot.texture = bpy_texture
        return objs
    def test_empty_bone_groups(self):
        # Arrange
        arm = bpy.data.armatures.new('tarm')
        obj = bpy.data.objects.new('tobj', arm)
        utils.link_object(obj)
        utils.set_active_object(obj)
        b_exp0, b_non0, b_exp1, b_non1 = ('b-exportable0', 'b-non-exportable0',
                                          'b-exportable1', 'b-non-exportable1')
        bpy.ops.object.mode_set(mode='EDIT')
        try:
            for n in (b_exp0, b_non0, b_exp1, b_non1):
                bone = arm.edit_bones.new(n)
                bone.tail.y = 1
            for n in (b_non0, b_exp1, b_non1):
                bone = arm.edit_bones[n]
                parent = arm.edit_bones[b_exp0]
                bone.parent = parent
        finally:
            bpy.ops.object.mode_set(mode='POSE')
        bg_exp = obj.pose.bone_groups.new(name='bg-only-exportable')
        bg_mix = obj.pose.bone_groups.new(name='bg-mixed')
        bg_non = obj.pose.bone_groups.new(name='bg-only-non-exportable')
        bg_emp = obj.pose.bone_groups.new(name='bg-empty')
        obj.pose.bones[b_exp0].bone_group = bg_exp
        obj.pose.bones[b_non0].bone_group = bg_mix
        obj.pose.bones[b_exp1].bone_group = bg_mix
        obj.pose.bones[b_non0].bone_group = bg_non
        arm.bones[b_non0].xray.exportable = False
        arm.bones[b_non1].xray.exportable = False

        bmesh = utils.create_bmesh((
            (0, 0, 0),
            (-1, -1, 0),
            (+1, -1, 0),
            (+1, +1, 0),
            (-1, +1, 0),
        ), ((0, 1, 2), (0, 2, 3), (0, 3, 4), (0, 4, 1)), True)
        obj_me = utils.create_object(bmesh, True)
        obj_me.parent = obj
        obj_me.xray.isroot = False
        vertex_group = obj_me.vertex_groups.new(name='b-exportable0')
        vertex_group.add(range(len(obj_me.data.vertices)), 1.0, 'REPLACE')

        # Act
        bpy.ops.export_object.xray_objects(
            objects='tobj',
            directory=self.outpath(),
            texture_name_from_image_path=False,
            export_motions=False,
        )

        # Assert
        self.assertReportsNotContains('WARNING')
        self.assertOutputFiles({
            'tobj.object',
        })
        content = self.getFileSafeContent('tobj.object')
        self.assertRegex(content, re.compile(bytes(b_exp0, 'cp1251')))
        self.assertRegex(content, re.compile(bytes(b_exp1, 'cp1251')))
        self.assertNotRegex(content, re.compile(bytes(b_non0, 'cp1251')))
        self.assertNotRegex(content, re.compile(bytes(b_non1, 'cp1251')))
        self.assertRegex(content, re.compile(bytes(bg_exp.name, 'cp1251')))
        self.assertRegex(content, re.compile(bytes(bg_mix.name, 'cp1251')))
        self.assertNotRegex(content, re.compile(bytes(bg_non.name, 'cp1251')))
        self.assertNotRegex(content, re.compile(bytes(bg_emp.name, 'cp1251')))