From a33e5e8e76e7864cc7d91a65c2fc7ebbaf8d3463 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:39:38 +0100 Subject: [PATCH 1/3] add the test of cube --- .github/workflows/test.yml | 20 +++++++ cube/header.h | 5 ++ cube/model.inc.c | 68 ++++++++++++++++++++++++ test/test_cube_export.py | 103 +++++++++++++++++++++++++++++++++++++ test/test_cube_import.py | 83 ++++++++++++++++++++++++++++++ 5 files changed, 279 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 cube/header.h create mode 100644 cube/model.inc.c create mode 100644 test/test_cube_export.py create mode 100644 test/test_cube_import.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..106b29d1a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Linux test + +on: + push: + branches: [ "*" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: | + sudo apt install blender + - name: Build + run: | + blender -b --python test\test_cube_export.py + blender -b --python test\test_cube_import.py \ No newline at end of file diff --git a/cube/header.h b/cube/header.h new file mode 100644 index 000000000..041222d9f --- /dev/null +++ b/cube/header.h @@ -0,0 +1,5 @@ +extern Lights1 cube_f3dlite_material_lights; +extern Vtx cube_Cube_mesh_vtx_0[24]; +extern Gfx cube_Cube_mesh_tri_0[]; +extern Gfx mat_cube_f3dlite_material[]; +extern Gfx cube_Cube_mesh[]; diff --git a/cube/model.inc.c b/cube/model.inc.c new file mode 100644 index 000000000..c2ee21896 --- /dev/null +++ b/cube/model.inc.c @@ -0,0 +1,68 @@ +Lights1 cube_f3dlite_material_lights = gdSPDefLights1( + 0x7F, 0x7F, 0x7F, + 0xFF, 0xFF, 0xFF, 0x49, 0x49, 0x49); + +Vtx cube_Cube_mesh_vtx_0[24] = { + {{ {-50, -50, 50}, 0, {368, 1008}, {129, 0, 0, 255} }}, + {{ {-50, 50, 50}, 0, {624, 1008}, {129, 0, 0, 255} }}, + {{ {-50, 50, -50}, 0, {624, 752}, {129, 0, 0, 255} }}, + {{ {-50, -50, -50}, 0, {368, 752}, {129, 0, 0, 255} }}, + {{ {-50, -50, -50}, 0, {368, 752}, {0, 0, 129, 255} }}, + {{ {-50, 50, -50}, 0, {624, 752}, {0, 0, 129, 255} }}, + {{ {50, 50, -50}, 0, {624, 496}, {0, 0, 129, 255} }}, + {{ {50, -50, -50}, 0, {368, 496}, {0, 0, 129, 255} }}, + {{ {50, -50, -50}, 0, {368, 496}, {127, 0, 0, 255} }}, + {{ {50, 50, -50}, 0, {624, 496}, {127, 0, 0, 255} }}, + {{ {50, 50, 50}, 0, {624, 240}, {127, 0, 0, 255} }}, + {{ {50, -50, 50}, 0, {368, 240}, {127, 0, 0, 255} }}, + {{ {50, -50, 50}, 0, {368, 240}, {0, 0, 127, 255} }}, + {{ {50, 50, 50}, 0, {624, 240}, {0, 0, 127, 255} }}, + {{ {-50, 50, 50}, 0, {624, -16}, {0, 0, 127, 255} }}, + {{ {-50, -50, 50}, 0, {368, -16}, {0, 0, 127, 255} }}, + {{ {-50, -50, -50}, 0, {112, 496}, {0, 129, 0, 255} }}, + {{ {50, -50, -50}, 0, {368, 496}, {0, 129, 0, 255} }}, + {{ {50, -50, 50}, 0, {368, 240}, {0, 129, 0, 255} }}, + {{ {-50, -50, 50}, 0, {112, 240}, {0, 129, 0, 255} }}, + {{ {50, 50, -50}, 0, {624, 496}, {0, 127, 0, 255} }}, + {{ {-50, 50, -50}, 0, {880, 496}, {0, 127, 0, 255} }}, + {{ {-50, 50, 50}, 0, {880, 240}, {0, 127, 0, 255} }}, + {{ {50, 50, 50}, 0, {624, 240}, {0, 127, 0, 255} }}, +}; + +Gfx cube_Cube_mesh_tri_0[] = { + gsSPVertex(cube_Cube_mesh_vtx_0 + 0, 16, 0), + gsSP1Triangle(0, 1, 2, 0), + gsSP1Triangle(0, 2, 3, 0), + gsSP1Triangle(4, 5, 6, 0), + gsSP1Triangle(4, 6, 7, 0), + gsSP1Triangle(8, 9, 10, 0), + gsSP1Triangle(8, 10, 11, 0), + gsSP1Triangle(12, 13, 14, 0), + gsSP1Triangle(12, 14, 15, 0), + gsSPVertex(cube_Cube_mesh_vtx_0 + 16, 8, 0), + gsSP1Triangle(0, 1, 2, 0), + gsSP1Triangle(0, 2, 3, 0), + gsSP1Triangle(4, 5, 6, 0), + gsSP1Triangle(4, 6, 7, 0), + gsSPEndDisplayList(), +}; + +Gfx mat_cube_f3dlite_material[] = { + gsDPPipeSync(), + gsDPSetCombineLERP(0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT, 0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT), + gsSPTexture(65535, 65535, 0, 0, 1), + gsSPSetLights1(cube_f3dlite_material_lights), + gsSPEndDisplayList(), +}; + +Gfx cube_Cube_mesh[] = { + gsSPDisplayList(mat_cube_f3dlite_material), + gsSPDisplayList(cube_Cube_mesh_tri_0), + gsDPPipeSync(), + gsSPSetGeometryMode(G_LIGHTING), + gsSPClearGeometryMode(G_TEXTURE_GEN), + gsDPSetCombineLERP(0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT, 0, 0, 0, SHADE, 0, 0, 0, ENVIRONMENT), + gsSPTexture(65535, 65535, 0, 0, 0), + gsSPEndDisplayList(), +}; + diff --git a/test/test_cube_export.py b/test/test_cube_export.py new file mode 100644 index 000000000..70cda10b6 --- /dev/null +++ b/test/test_cube_export.py @@ -0,0 +1,103 @@ +import math +import bpy +from os.path import dirname, abspath +import sys +import mathutils + +sys.path.append(dirname(dirname(dirname(abspath(__file__))))) +from fast64 import register + +sys.path.append(dirname(dirname(abspath(__file__)))) +from fast64_internal.utility import PluginError, applyRotation +from fast64_internal.f3d.f3d_gbi import DLFormat +from fast64_internal.f3d.f3d_material import createF3DMat, getDefaultMaterialPreset +from fast64_internal.f3d.f3d_writer import exportF3DtoC, getWriteMethodFromEnum + +register() + +def purge_orphans(): + if bpy.app.version >= (3, 0, 0): + bpy.ops.outliner.orphans_purge( + do_local_ids=True, do_linked_ids=True, do_recursive=True + ) + else: + # call purge_orphans() recursively until there are no more orphan data blocks to purge + result = bpy.ops.outliner.orphans_purge() + if result.pop() != "CANCELLED": + purge_orphans() + + +def clean_scene(): + """ + Removing all of the objects, collection, materials, particles, + textures, images, curves, meshes, actions, nodes, and worlds from the scene + """ + if bpy.context.active_object and bpy.context.active_object.mode == "EDIT": + bpy.ops.object.editmode_toggle() + + for obj in bpy.data.objects: + obj.hide_set(False) + obj.hide_select = False + obj.hide_viewport = False + + bpy.ops.object.select_all(action="SELECT") + bpy.ops.object.delete() + + collection_names = [col.name for col in bpy.data.collections] + for name in collection_names: + bpy.data.collections.remove(bpy.data.collections[name]) + + # in the case when you modify the world shader + world_names = [world.name for world in bpy.data.worlds] + for name in world_names: + bpy.data.worlds.remove(bpy.data.worlds[name]) + # create a new world data block + bpy.ops.world.new() + bpy.context.scene.world = bpy.data.worlds["World"] + + purge_orphans() + +clean_scene() + +bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0)) + +bpy.ops.object.select_all(action="SELECT") + +if bpy.context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + +allObjs = bpy.context.selected_objects +if len(allObjs) == 0: + raise PluginError("No objects selected.") +obj = bpy.context.selected_objects[0] +if obj.type != "MESH": + raise PluginError("Object is not a mesh.") + +preset = getDefaultMaterialPreset("Shaded Solid") +createF3DMat(obj, preset) + +scaleValue = bpy.context.scene.blenderF3DScale +finalTransform = mathutils.Matrix.Diagonal(mathutils.Vector((scaleValue, scaleValue, scaleValue))).to_4x4() +applyRotation([obj], math.radians(90), "X") + +exportPath = bpy.path.abspath(bpy.context.scene.DLExportPath) +dlFormat = DLFormat.Static if bpy.context.scene.DLExportisStatic else DLFormat.Dynamic +texDir = bpy.context.scene.DLTexDir +savePNG = bpy.context.scene.saveTextures +separateTexDef = bpy.context.scene.DLSeparateTextureDef +DLName = "cube" +matWriteMethod = getWriteMethodFromEnum(bpy.context.scene.matWriteMethod) + +exportF3DtoC( + exportPath, + obj, + dlFormat, + finalTransform, + texDir, + savePNG, + separateTexDef, + DLName, + matWriteMethod, +) + +applyRotation([obj], math.radians(-90), "X") \ No newline at end of file diff --git a/test/test_cube_import.py b/test/test_cube_import.py new file mode 100644 index 000000000..d0a2140a4 --- /dev/null +++ b/test/test_cube_import.py @@ -0,0 +1,83 @@ +import math +import bpy +from os.path import dirname, abspath +import sys + +sys.path.append(dirname(dirname(dirname(abspath(__file__))))) +from fast64 import register + +sys.path.append(dirname(dirname(abspath(__file__)))) +from fast64_internal.f3d.f3d_gbi import get_F3D_GBI +from fast64_internal.f3d.f3d_material import createF3DMat +from fast64_internal.f3d.f3d_parser import F3DContext, getImportData, importMeshC + +register() + +def purge_orphans(): + if bpy.app.version >= (3, 0, 0): + bpy.ops.outliner.orphans_purge( + do_local_ids=True, do_linked_ids=True, do_recursive=True + ) + else: + # call purge_orphans() recursively until there are no more orphan data blocks to purge + result = bpy.ops.outliner.orphans_purge() + if result.pop() != "CANCELLED": + purge_orphans() + + +def clean_scene(): + """ + Removing all of the objects, collection, materials, particles, + textures, images, curves, meshes, actions, nodes, and worlds from the scene + """ + if bpy.context.active_object and bpy.context.active_object.mode == "EDIT": + bpy.ops.object.editmode_toggle() + + for obj in bpy.data.objects: + obj.hide_set(False) + obj.hide_select = False + obj.hide_viewport = False + + bpy.ops.object.select_all(action="SELECT") + bpy.ops.object.delete() + + collection_names = [col.name for col in bpy.data.collections] + for name in collection_names: + bpy.data.collections.remove(bpy.data.collections[name]) + + # in the case when you modify the world shader + world_names = [world.name for world in bpy.data.worlds] + for name in world_names: + bpy.data.worlds.remove(bpy.data.worlds[name]) + # create a new world data block + bpy.ops.world.new() + bpy.context.scene.world = bpy.data.worlds["World"] + + purge_orphans() + +clean_scene() + +obj = None +if bpy.context.mode != "OBJECT": + bpy.ops.object.mode_set(mode="OBJECT") + +name = "cube_Cube_mesh" +importPath = "./cube/model.inc.c" +basePath = bpy.path.abspath(bpy.context.scene.DLImportBasePath) +scaleValue = bpy.context.scene.blenderF3DScale + +removeDoubles = bpy.context.scene.DLRemoveDoubles +importNormals = bpy.context.scene.DLImportNormals +drawLayer = bpy.context.scene.DLImportDrawLayer + +data = getImportData([importPath]) + +importMeshC( + data, + name, + scaleValue, + removeDoubles, + importNormals, + drawLayer, + F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)), +) \ No newline at end of file From 54a05c97c98a859b6bec7e9f946c5e9df2b1d663 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:42:42 +0100 Subject: [PATCH 2/3] format with black --- test/test_cube_export.py | 8 ++++---- test/test_cube_import.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/test_cube_export.py b/test/test_cube_export.py index 70cda10b6..3b04770b1 100644 --- a/test/test_cube_export.py +++ b/test/test_cube_export.py @@ -15,11 +15,10 @@ register() + def purge_orphans(): if bpy.app.version >= (3, 0, 0): - bpy.ops.outliner.orphans_purge( - do_local_ids=True, do_linked_ids=True, do_recursive=True - ) + bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True) else: # call purge_orphans() recursively until there are no more orphan data blocks to purge result = bpy.ops.outliner.orphans_purge() @@ -57,6 +56,7 @@ def clean_scene(): purge_orphans() + clean_scene() bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0)) @@ -100,4 +100,4 @@ def clean_scene(): matWriteMethod, ) -applyRotation([obj], math.radians(-90), "X") \ No newline at end of file +applyRotation([obj], math.radians(-90), "X") diff --git a/test/test_cube_import.py b/test/test_cube_import.py index d0a2140a4..d73f027e8 100644 --- a/test/test_cube_import.py +++ b/test/test_cube_import.py @@ -13,11 +13,10 @@ register() + def purge_orphans(): if bpy.app.version >= (3, 0, 0): - bpy.ops.outliner.orphans_purge( - do_local_ids=True, do_linked_ids=True, do_recursive=True - ) + bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True) else: # call purge_orphans() recursively until there are no more orphan data blocks to purge result = bpy.ops.outliner.orphans_purge() @@ -55,6 +54,7 @@ def clean_scene(): purge_orphans() + clean_scene() obj = None @@ -80,4 +80,4 @@ def clean_scene(): importNormals, drawLayer, F3DContext(get_F3D_GBI(), basePath, createF3DMat(None)), -) \ No newline at end of file +) From aae8c3ffe35dda7e8912679c4644d3ac608f8c12 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Fri, 18 Apr 2025 15:57:29 +0200 Subject: [PATCH 3/3] Update test.yml --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 106b29d1a..6f5e32f0f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: push: branches: [ "*" ] pull_request: - branches: [ "master" ] + branches: [ "*" ] jobs: build: @@ -17,4 +17,4 @@ jobs: - name: Build run: | blender -b --python test\test_cube_export.py - blender -b --python test\test_cube_import.py \ No newline at end of file + blender -b --python test\test_cube_import.py