1111#include " UnityEngine/ParticleSystem.hpp"
1212#include " Window/window.hpp"
1313#include " Window/createModuleWindows.hpp"
14+ #include " project.hpp"
1415
1516#include " assimp/shared/assimp/Importer.hpp"
1617#include " assimp/shared/assimp/Exporter.hpp"
2425#include " UnityEngine/Rendering/IndexFormat.hpp"
2526
2627#include " bsml/shared/Helpers/getters.hpp"
28+ #include " bsml/shared/BSML/MainThreadScheduler.hpp"
2729
2830
2931static modloader::ModInfo modInfo{MOD_ID, VERSION, 0 };
@@ -47,103 +49,17 @@ MAKE_HOOK_MATCH(AssimpTestHook, &GlobalNamespace::MainMenuViewController::DidAct
4749 std::string file = " /storage/emulated/0/ModData/com.beatgames.beatsaber/Mods/Flair/testCube.glb" ;
4850 // std::string file = "/storage/emulated/0/ModData/com.beatgames.beatsaber/Mods/Flair/teapot.glb";
4951
50- Assimp::Importer importer;
51-
52- const aiScene* scene = importer.ReadFile (file,
53- aiProcess_Triangulate);
54-
55- if (scene == nullptr ) {
56- PaperLogger.info (" Error!" );
57- PaperLogger.error (" {}" , importer.GetErrorString ());
58- return ;
59- }
60-
61- for (int i = 0 ; i < scene->mNumMeshes ; i++) {
62- aiMesh* mesh = scene->mMeshes [i];
63- PaperLogger.info (" Mesh name: {}" , mesh->mName .C_Str ());
64-
65- UnityEngine::Mesh* unityMesh = UnityEngine::Mesh::New_ctor ();
66- unityMesh->set_name (mesh->mName .C_Str ());
67- unityMesh->Clear ();
68-
69- ArrayW<UnityEngine::Vector3> vertices (mesh->mNumVertices );
70- for (int j = 0 ; j < mesh->mNumVertices ; j++) {
71- aiVector3D& vertex = mesh->mVertices [j];
72- PaperLogger.info (" Vertex {} | X: {}, Y: {}, Z: {}" , j, vertex.x , vertex.y , vertex.z );
73- vertices[j] = UnityEngine::Vector3 (vertex.x , vertex.y , vertex.z );
74- }
75- unityMesh->set_vertices (vertices);
76-
77- ArrayW<int > triangles (mesh->mNumFaces * 3 );
78- for (int j = 0 ; j < mesh->mNumFaces ; j++) {
79- aiFace& face = mesh->mFaces [j];
80- for (int k = 0 ; k < 3 ; k++) {
81- PaperLogger.info (" Face {} Index {}" , j, face.mIndices [k]);
82- triangles[j * 3 + k] = face.mIndices [k];
83- }
84- }
85- unityMesh->set_triangles (triangles);
86-
87- if (mesh->mNormals != nullptr ) {
88- ArrayW<UnityEngine::Vector3> normals (mesh->mNumVertices );
89- for (int j = 0 ; j < mesh->mNumVertices ; j++) {
90- aiVector3D& normal = mesh->mNormals [j];
91- PaperLogger.info (" Normal {} | X: {}, Y: {}, Z: {}" , j, normal.x , normal.y , normal.z );
92- normals[j] = UnityEngine::Vector3 (normal.x , normal.y , normal.z );
93- }
94- unityMesh->set_normals (normals);
95- } else {
96- unityMesh->RecalculateNormals ();
97- }
98-
99- if (mesh->mColors [0 ] != nullptr ) {
100- ArrayW<UnityEngine::Color> colors (mesh->mNumVertices );
101- for (int j = 0 ; j < mesh->mNumVertices ; j++) {
102- aiColor4D& color = mesh->mColors [i][j];
103- PaperLogger.info (" Color {} | R: {}, G: {}, B: {}, A: {}" , j, color.r , color.g , color.b , color.a );
104- colors[j] = UnityEngine::Color (color.r , color.g , color.b , color.a );
105- }
106- unityMesh->set_colors (colors);
107- }
108-
109-
110-
111- UnityEngine::GameObject* testGO = UnityEngine::GameObject::New_ctor (" FlairTest" );
112- testGO->get_transform ()->set_position (UnityEngine::Vector3 (0 , 0.5 , 0.5 ));
113- testGO->get_transform ()->set_localScale (UnityEngine::Vector3 (0.2 , 0.2 , 0.2 ));
114-
115- UnityEngine::MeshFilter* testFilter = testGO->AddComponent <UnityEngine::MeshFilter*>();
116- testFilter->set_sharedMesh (unityMesh);
117-
118- UnityEngine::MeshRenderer* testRenderer = testGO->AddComponent <UnityEngine::MeshRenderer*>();
119- UnityEngine::Shader* shader = UnityEngine::Resources::FindObjectsOfTypeAll<UnityEngine::Shader*>()->FirstOrDefault ([](UnityEngine::Shader* shader){return shader->get_name () == " Standard" ;});
120- UnityEngine::Material* material = UnityEngine::Material::New_ctor (shader);
121- testRenderer->set_sharedMaterial (material);
122-
123-
124-
125- Assimp::Exporter exporter;
126-
127- for (int j = 0 ; j < mesh->mNumVertices ; j++) {
128- aiVector3D& vertex = mesh->mVertices [j];
129- if ( vertex.x == 1 &&
130- vertex.y == 1 &&
131- vertex.z == -1
132- ) {
133- vertex.x = 0 ;
134- vertex.y = 0 ;
135- vertex.z = 0 ;
136- }
137- }
138-
139- exporter.Export (scene, " stl" , " /storage/emulated/0/ModData/com.beatgames.beatsaber/Mods/Flair/testCube.glb" );
140-
141- std::string_view err = exporter.GetErrorString ();
142- if (!err.empty ()) {
143- PaperLogger.info (" Error exporting!" );
144- PaperLogger.error (" {}" , err);
145- }
146- }
52+ Flair::Project project (file);
53+
54+ UnityEngine::GameObject* testGO = UnityEngine::GameObject::New_ctor (" FlairTest" );
55+ testGO->get_transform ()->set_position (UnityEngine::Vector3 (0 , 0.5 , 0.5 ));
56+ testGO->get_transform ()->set_localScale (UnityEngine::Vector3 (0.2 , 0.2 , 0.2 ));
57+
58+ UnityEngine::MeshFilter* testFilter = testGO->AddComponent <UnityEngine::MeshFilter*>();
59+ testFilter->set_sharedMesh (project.meshes [0 ].ptr ());
60+
61+ UnityEngine::MeshRenderer* testRenderer = testGO->AddComponent <UnityEngine::MeshRenderer*>();
62+ testRenderer->set_sharedMaterial (project.materials [0 ].ptr ());
14763
14864
14965
0 commit comments