Skip to content

Commit 829b571

Browse files
committed
Use flatbuffers for model meta data
- Add flatbuffers dependency. - Update codes using meta data.
1 parent a8aaf56 commit 829b571

File tree

11 files changed

+319
-81
lines changed

11 files changed

+319
-81
lines changed

CMakeLists.txt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,39 @@ find_package(FreeType REQUIRED)
5151
if(FREETYPE_FOUND)
5252
message(STATUS "freetype include path: ${FREETYPE_INCLUDE_DIRS}")
5353
endif()
54+
55+
# find flatbuffers
56+
if(NOT TARGET flatbuffers)
57+
find_package(flatbuffers REQUIRED)
58+
endif()
59+
# ==================================================================================================
60+
61+
# ==================================================================================================
62+
function(render_pipeline_generate_schema_headers)
63+
# generate schema headers
64+
if(NOT FlatBuffers_flatc)
65+
message(FATAL_ERROR "Cannot find flatc program.")
66+
endif()
67+
68+
file(GLOB flatc_input_files "${PROJECT_SOURCE_DIR}/resources/data/schema/*.fbs")
69+
foreach(input_file ${flatc_input_files})
70+
execute_process(
71+
COMMAND ${FlatBuffers_flatc} -c --scoped-enums "${input_file}"
72+
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/rpcore/schema"
73+
RESULT_VARIABLE flatc_result
74+
)
75+
if(NOT (${flatc_result} EQUAL "0"))
76+
message(SEND_ERROR "flatc returns error for a file '${input_file}'")
77+
endif()
78+
endforeach()
79+
80+
message(STATUS "Render Pipeline: Schema header files are generated.")
81+
endfunction()
5482
# ==================================================================================================
5583

5684
# === target =======================================================================================
85+
render_pipeline_generate_schema_headers()
86+
5787
include("${PROJECT_SOURCE_DIR}/files.cmake")
5888
add_library(${PROJECT_NAME} SHARED ${render_pipeline_sources} ${render_pipeline_headers})
5989

@@ -85,7 +115,7 @@ target_link_libraries(${PROJECT_NAME}
85115

86116
PRIVATE $<$<NOT:$<BOOL:${Boost_USE_STATIC_LIBS}>>:Boost::dynamic_linking>
87117
Boost::filesystem
88-
${FREETYPE_LIBRARIES} yaml-cpp spdlog::spdlog
118+
${FREETYPE_LIBRARIES} yaml-cpp spdlog::spdlog flatbuffers
89119
)
90120

91121
set_target_properties(${PROJECT_NAME} PROPERTIES

cmake/FindFlatBuffers.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#.rst:
2+
# FindFlatBuffers
3+
# --------------
4+
#
5+
# FindFlatBuffers.cmake
6+
#
7+
# Author: Younguk Kim (bluekyu)
8+
# Date : 2017-07-07
9+
#
10+
# Result Variables
11+
# ^^^^^^^^^^^^^^^^
12+
#
13+
# This module defines the following variables::
14+
#
15+
# FlatBuffers_FOUND - True if FlatBuffers has been found and can be used
16+
#
17+
# and the following imported targets::
18+
#
19+
# flatbuffers - FlatBuffers library
20+
21+
cmake_minimum_required(VERSION 3.6)
22+
23+
find_path(FlatBuffers_INCLUDE_DIR
24+
NAMES "flatbuffers/flatbuffers.h"
25+
PATHS "${FlatBuffers_ROOT}"
26+
PATH_SUFFIXES include
27+
)
28+
29+
find_library(FlatBuffers_LIBRARY
30+
NAMES flatbuffers
31+
PATHS "${FlatBuffers_ROOT}"
32+
PATH_SUFFIXES lib
33+
)
34+
35+
find_program(FlatBuffers_flatc
36+
flatc
37+
PATHS "${FlatBuffers_ROOT}/bin"
38+
)
39+
40+
# Set FlatBuffers_FOUND
41+
include(FindPackageHandleStandardArgs)
42+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(FlatBuffers
43+
FOUND_VAR FlatBuffers_FOUND
44+
REQUIRED_VARS FlatBuffers_LIBRARY FlatBuffers_INCLUDE_DIR
45+
)
46+
47+
if(FlatBuffers_FOUND)
48+
message(STATUS "Found the FlatBuffers library")
49+
50+
if(NOT TARGET flatbuffers)
51+
add_library(flatbuffers UNKNOWN IMPORTED)
52+
set_target_properties(flatbuffers PROPERTIES
53+
INTERFACE_INCLUDE_DIRECTORIES "${FlatBuffers_INCLUDE_DIR}"
54+
IMPORTED_LOCATION "${FlatBuffers_LIBRARY}"
55+
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
56+
)
57+
58+
# Make variables changeable to the advanced user
59+
mark_as_advanced(FlatBuffers_LIBRARY)
60+
endif()
61+
62+
if(FlatBuffers_flatc)
63+
mark_as_advanced(FlatBuffers_flatc)
64+
endif()
65+
66+
# Make variables changeable to the advanced user
67+
mark_as_advanced(FlatBuffers_INCLUDE_DIR)
68+
endif()

render_pipeline/rpcore/util/rpmaterial.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace rpcore {
1010
class RPMaterial
1111
{
1212
public:
13-
enum class ShadingModel: int
13+
enum class ShadingModel: int8_t
1414
{
1515
DEFAULT_MODEL = 0,
1616
EMISSIVE_MODEL,

render_pipeline/rpcore/util/rpmodel.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class RENDER_PIPELINE_DECL RPModel
1919
RPModel(void) = default;
2020
RPModel(NodePath nodepath);
2121

22-
void load_meta_file(const std::string& file_path="");
23-
void load_meta_data(const YAML::Node& yaml_node);
22+
void load_meta_file(const Filename& file_path="");
23+
void load_meta_data(const std::string& json_string);
2424

2525
private:
2626
// function only PImpl
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include "rpmaterial_schema.fbs";
2+
3+
namespace rpcore;
4+
5+
table GeomNodeSchema {
6+
geoms:[GeomSchema];
7+
}
8+
9+
table GeomSchema {
10+
material:RPMaterialSchema;
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace rpcore;
2+
3+
struct LVecBase4Schema
4+
{
5+
x:float;
6+
y:float;
7+
z:float;
8+
w:float;
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
include "panda_node_schema.fbs";
2+
3+
namespace rpcore;
4+
5+
table ModelRootSchema {
6+
root_node:PandaNodeSchema;
7+
}
8+
9+
root_type ModelRootSchema;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include "geom_node_schema.fbs";
2+
3+
namespace rpcore;
4+
5+
enum NodeTypeSchema : ubyte {
6+
PandaNode,
7+
GeomNode,
8+
}
9+
10+
table PandaNodeSchema {
11+
node_type:NodeTypeSchema;
12+
13+
name:string;
14+
material:RPMaterialSchema;
15+
16+
children:[PandaNodeSchema];
17+
18+
// sub-class
19+
geom_node:GeomNodeSchema;
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
include "luse_schema.fbs";
2+
3+
namespace rpcore;
4+
5+
enum ShadingModelSchema: byte {
6+
None=-1,
7+
Default=0,
8+
Emissive,
9+
Clearcoat,
10+
Transparent,
11+
Skin,
12+
Foliage,
13+
}
14+
15+
table RPMaterialSchema {
16+
base_color:LVecBase4Schema;
17+
specular_ior:float;
18+
metallic:float;
19+
roughness:float;
20+
shading_model:ShadingModelSchema = None;
21+
normal_factor:float;
22+
arbitrary0:float;
23+
}

src/rpcore/util/rpgeomnode.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ RPMaterial RPGeomNode::get_material(int geom_index) const
3737
const RenderState* state = geom_node->get_geom_state(geom_index);
3838

3939
if (!state->has_attrib(MaterialAttrib::get_class_type()))
40-
{
41-
RPObject::global_warn("RPGeomNode", fmt::format("Geom {} has no material!", geom_node->get_name()));
4240
return RPMaterial(nullptr);
43-
}
4441

4542
return RPMaterial(DCAST(MaterialAttrib, state->get_attrib(MaterialAttrib::get_class_type()))->get_material());
4643
}

0 commit comments

Comments
 (0)