satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

[Rejected] Assimp #139

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

For model loading https://github.com/satoshinm/NetCraft/issues/26 entities

satoshinm commented 7 years ago

This builds on my system (native-build), but assimp had warnings about unaligned pointer access in 3.3.1 https://github.com/assimp/assimp/issues/1057 so I went with latest dev although it has warnings too:

deps/assimp/code/MDLLoader.cpp:419:55: warning: taking address of packed member 'time' of class or structure 'Assimp::MDL::GroupFrame' may result in an unaligned
deps/assimp/code/MDLMaterialLoader.cpp:672:43: warning: taking address of packed member 'Power' of class or structure 'Assimp::MDL::Material_MDL7' may result in an
deps/assimp/code/ObjExporter.cpp:90:3: warning: field 'endl' will be initialized after field 'vp' [-Wreorder]
deps/assimp/code/BlenderDNA.h:256:39: warning: inline function 'Assimp::Blender::Structure::Convert<Assimp::Blender::Scene>' is not defined [-Wundefined-inline]
deps/assimp/code/LogAux.h:90:41: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:69:40: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:69:40: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:69:40: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:76:41: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:76:41: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:76:41: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::IFCImporter>::log_prefix' required here, but no definition is
deps/assimp/include/assimp/vector2.inl:123:15: warning: taking address of packed member 'x' of class or structure 'aiVector2t<float>' may result in an unaligned
deps/assimp/code/LogAux.h:69:40: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::FBXImporter>::log_prefix' required here, but no definition is
deps/assimp/code/LogAux.h:69:40: warning: instantiation of variable 'Assimp::LogFunctions<Assimp::FBXImporter>::log_prefix' required here, but no definition is
deps/assimp/code/FBXBinaryTokenizer.cpp:449:19: warning: unused variable 'padding_0' [-Wunused-variable]
deps/assimp/code/FBXBinaryTokenizer.cpp:450:19: warning: unused variable 'padding_1' [-Wunused-variable]
deps/assimp/code/FBXBinaryTokenizer.cpp:164:10: warning: unused function 'ReadDoubleWord' [-Wunused-function]
deps/assimp/code/SIBImporter.cpp:92:16: warning: unused function 'makePair' [-Wunused-function]
deps/assimp/code/glTFAsset.h:233:76: warning: adding 'glTF::ComponentType' to a string does not append to the string [-Wstring-plus-int]
deps/assimp/code/glTFAsset.h:616:13: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
deps/assimp/code/glTFAsset.h:623:13: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
deps/assimp/code/glTFAsset.h:233:76: warning: adding 'glTF::ComponentType' to a string does not append to the string [-Wstring-plus-int]
deps/assimp/code/glTFAsset.h:616:13: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
deps/assimp/code/glTFAsset.h:623:13: warning: anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]
deps/assimp/code/MMDPmxParser.cpp:189:25: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:190:33: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:209:16: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:226:21: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:227:29: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:501:22: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:502:30: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:503:25: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
deps/assimp/code/MMDPmxParser.cpp:504:33: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]
satoshinm commented 7 years ago

Assimp is way too big even compiled:

native-build $ ls -lh deps/assimp/code/libassimp.a
-rw-r--r--  1 admin  staff   501M May 18 22:58 deps/assimp/code/libassimp.a

consider disabling all but a few importers, or is there a lighter weight model importer? https://en.wikipedia.org/wiki/Wavefront_.obj_file is very lightweight, https://en.wikipedia.org/wiki/STL_(file_format) support would be nice, but perhaps start simple... but the tutorial https://learnopengl.com/#!Model-Loading/Assimp uses assimp

satoshinm commented 7 years ago

Weird failure when compiling under emscripten, undeclared malloc/free, added include cstdlib to fix:

[ 93%] Building CXX object deps/assimp/code/CMakeFiles/assimp.dir/D3MFOpcPackage.cpp.o
/Users/admin/games/wasm/NetCraft/deps/assimp/code/D3MFOpcPackage.cpp:221:16: error: use of undeclared identifier 'malloc'
    m_Buffer = malloc(m_Size);
               ^
/Users/admin/games/wasm/NetCraft/deps/assimp/code/D3MFOpcPackage.cpp:225:5: error: use of undeclared identifier 'free'
    free(m_Buffer);
    ^
2 errors generated.
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting
satoshinm commented 7 years ago

release-build-js (but not debug build js) fails with a mysterious error trying to check the size of off64_t, on CircleCI and locally:

-- Check size of off64_t
CMake Error at /usr/local/Cellar/cmake/3.7.2/share/cmake/Modules/CheckTypeSize.cmake:114 (try_compile):
  Cannot copy output executable

    ''

  to destination specified by COPY_FILE:

    '/Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CheckTypeSize/OFF64_T.bin'

  Unable to find the executable at any of:

    /Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CMakeTmp/cmTC_d14fb.html
    /Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CMakeTmp/Debug/cmTC_d14fb.html
    /Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CMakeTmp/Debug/cmTC_d14fb.app/cmTC_d14fb.html
    /Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CMakeTmp/Development/cmTC_d14fb.html

Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.7.2/share/cmake/Modules/CheckTypeSize.cmake:239 (__check_type_size_impl)
  deps/assimp/contrib/zlib/CMakeLists.txt:50 (check_type_size)

-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Checking for module 'minizip'
--   No package 'minizip' found
-- Could NOT find rt (missing:  RT_LIBRARY) 
INFO RT-extension not found. glTF import/export will be built without Open3DGC-compression.
-- Enabled formats: AMF 3DS AC ASE ASSBIN ASSXML B3D BVH COLLADA DXF CSM HMP IRRMESH IRR LWO LWS MD2 MD3 MD5 MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SIB SMD STL TERRAGEN 3D X X3D GLTF 3MF MMD
-- Disabled formats:
-- Configuring incomplete, errors occurred!
See also "/Users/admin/games/wasm/NetCraft/release-build-js/CMakeFiles/CMakeOutput.log".
make: *** [cmake_check_build_system] Error 1
release-build-js $

It's adding its own targets:

build $ make
[ 10%] Built target craft
[ 17%] Built target zlibstatic
[ 17%] Built target IrrXML
[ 17%] Linking CXX shared library libassimp.so
[100%] Built target assimp
build $ 

This project might be too heavyweight for a web-based/emscripten-targeting app

build $ file ./deps/assimp/code/libassimp.so.3.3.1
./deps/assimp/code/libassimp.so.3.3.1: LLVM IR bitcode
build $ ls -lh ./deps/assimp/code/libassimp.so.3.3.1
-rw-r--r--  1 admin  staff   104M May 18 23:26 ./deps/assimp/code/libassimp.so.3.3.1
satoshinm commented 7 years ago

Saving the CMakeLists diff here since this could be useful to make some of the other changes:

NetCraft $ git diff master CMakeLists.txt 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6230786..ec932ca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,8 +28,8 @@ else ()
         deps/tinycthread/tinycthread.c)
 endif ()

-add_definitions(-std=c99 -O3)
-add_definitions(-DLODEPNG_NO_COMPILE_ZLIB)
+set_source_files_properties(*.c PROPERTIES COMPILE_FLAGS "-std=c99 -O3")
+set_source_files_properties(deps/lodepng/lodepng.c PROPERTIES COMPILE_FLAGS -DLODEPNG_NO_COMPILE_ZLIB)

 if ($ENV{CIRCLECI})
     add_definitions(-DBUILD_NUM="$ENV{CIRCLE_BUILD_NUM}")
@@ -76,6 +76,13 @@ include_directories(deps/miniz)
 include_directories(deps/noise)
 include_directories(deps/tinycthread)

+set(ASSIMP_BUILD_TESTS OFF)
+set(ASSIMP_BUILD_ASSIMP_TOOLS OFF)
+add_definitions(-DASSIMP_BUILD_BOOST_WORKAROUND)
+add_definitions(-DASSIMP_BUILD_NO_OWN_ZLIB)
+add_subdirectory(deps/assimp)
+include_directories(deps/assimp)
+
 if(MINGW OR MSVC)
     set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH}
         "C:/Program Files/CURL/lib" "C:/Program Files (x86)/CURL/lib")

Advice from https://www.reddit.com/r/computergraphics/comments/50jkuv/is_there_a_pure_c_alternative_to_assimp/

Assimp wasn't really made to be used in production. Instead you should build a standalone app that uses assimp to convert assets into your own format. Then you can use your own parser in your C app.

...

I've tried to find an alternative too, but so far, I haven't found anything. My current solution is just to use simple formats like 3ds, and obj, then write the parsers to handle them myself (the 3ds parser in my current parser: https://github.com/charles-l/sanegl/blob/master/sgl_mesh_loader.c). Definitely would be interested if there are any minimal alternatives to assimp that I don't know of, though.

....

Honestly assimp is very large and handles a large variety of formats. I can't imagine an embedded platform where you'd need to be able to read these many kinds of models (or even read models at all).

SaneGL: https://github.com/charles-l/sanegl - has a todo for OBJ and STL, but their code https://github.com/charles-l/sanegl/blob/master/sgl_mesh_loader.c supports 3DS Autodesk 3ds Max, a popular compact binary format. Long story short, ought to pick one useful relatively common model format, then if needed convert other models from it. Maybe binary STL? Start simple with OBJ?