mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-07 21:06:25 +00:00
compile & link successful
This commit is contained in:
+63
-7
@@ -54,12 +54,14 @@ OPTION(USE_VLD "Use Visual Leak Detector for debugging memory leaks, MSVC-only."
|
|||||||
OPTION(USE_MMAP "Adds a command line options to parse IFC files from memory mapped files using Boost.Iostreams" OFF)
|
OPTION(USE_MMAP "Adds a command line options to parse IFC files from memory mapped files using Boost.Iostreams" OFF)
|
||||||
OPTION(BUILD_SHARED_LIBS "Build IfcParse and IfcGeom as shared libs (SO/DLL)." OFF)
|
OPTION(BUILD_SHARED_LIBS "Build IfcParse and IfcGeom as shared libs (SO/DLL)." OFF)
|
||||||
OPTION(MSVC_PARALLEL_BUILD "Multi-threaded compilation in Microsoft Visual Studio (/MP)" OFF)
|
OPTION(MSVC_PARALLEL_BUILD "Multi-threaded compilation in Microsoft Visual Studio (/MP)" OFF)
|
||||||
|
OPTION(NO_WARN "Disable all warnings" OFF)
|
||||||
OPTION(WASM_BUILD OFF)
|
OPTION(WASM_BUILD OFF)
|
||||||
if (${HAS_MAX})
|
if (${HAS_MAX})
|
||||||
OPTION(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF)
|
OPTION(BUILD_IFCMAX "Build IfcMax, a 3ds Max plug-in, Windows-only." OFF)
|
||||||
endif()
|
endif()
|
||||||
if (${BUILD_CONVERT})
|
if (${BUILD_CONVERT})
|
||||||
OPTION(GLTF_SUPPORT "Build IfcConvert with glTF support (requires json.hpp)." OFF)
|
OPTION(GLTF_SUPPORT "Build IfcConvert with glTF support (requires json.hpp)." OFF)
|
||||||
|
OPTION(USD_SUPPORT "Build IfcConvert with USD support (requires pixar's USD library)." OFF)
|
||||||
endif()
|
endif()
|
||||||
OPTION(USERSPACE_PYTHON_PREFIX "Installs IfcPython for the current user only instead of system-wide." OFF)
|
OPTION(USERSPACE_PYTHON_PREFIX "Installs IfcPython for the current user only instead of system-wide." OFF)
|
||||||
OPTION(ADD_COMMIT_SHA "Add commit sha and branch in version number, warning results in many rebuilds, requires git" OFF)
|
OPTION(ADD_COMMIT_SHA "Add commit sha and branch in version number, warning results in many rebuilds, requires git" OFF)
|
||||||
@@ -72,6 +74,14 @@ if(MSVC AND MSVC_PARALLEL_BUILD)
|
|||||||
add_definitions("/MP")
|
add_definitions("/MP")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NO_WARN)
|
||||||
|
if(MSVC)
|
||||||
|
add_compile_options("/w")
|
||||||
|
else()
|
||||||
|
add_compile_options("-w")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# QtViewer requires Qt5
|
# QtViewer requires Qt5
|
||||||
OPTION(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer" OFF)
|
OPTION(BUILD_QTVIEWER "Build IfcOpenShell Qt GUI Viewer" OFF)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
@@ -137,11 +147,6 @@ UNIFY_ENVVARS_AND_CACHE(PYTHON_EXECUTABLE)
|
|||||||
UNIFY_ENVVARS_AND_CACHE(HDF5_INCLUDE_DIR)
|
UNIFY_ENVVARS_AND_CACHE(HDF5_INCLUDE_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARY_DIR)
|
UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARY_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARIES)
|
UNIFY_ENVVARS_AND_CACHE(HDF5_LIBRARIES)
|
||||||
endif()
|
|
||||||
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
|
|
||||||
UNIFY_ENVVARS_AND_CACHE(BOOST_LIBRARYDIR)
|
|
||||||
|
|
||||||
if (NOT MINIMAL_BUILD)
|
|
||||||
UNIFY_ENVVARS_AND_CACHE(CGAL_INCLUDE_DIR)
|
UNIFY_ENVVARS_AND_CACHE(CGAL_INCLUDE_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(CGAL_LIBRARY_DIR)
|
UNIFY_ENVVARS_AND_CACHE(CGAL_LIBRARY_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(GMP_INCLUDE_DIR)
|
UNIFY_ENVVARS_AND_CACHE(GMP_INCLUDE_DIR)
|
||||||
@@ -149,6 +154,8 @@ UNIFY_ENVVARS_AND_CACHE(GMP_LIBRARY_DIR)
|
|||||||
UNIFY_ENVVARS_AND_CACHE(MPFR_INCLUDE_DIR)
|
UNIFY_ENVVARS_AND_CACHE(MPFR_INCLUDE_DIR)
|
||||||
UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR)
|
UNIFY_ENVVARS_AND_CACHE(MPFR_LIBRARY_DIR)
|
||||||
endif()
|
endif()
|
||||||
|
UNIFY_ENVVARS_AND_CACHE(BOOST_ROOT)
|
||||||
|
UNIFY_ENVVARS_AND_CACHE(BOOST_LIBRARYDIR)
|
||||||
|
|
||||||
if(WASM_BUILD)
|
if(WASM_BUILD)
|
||||||
# when using the nix/build-all.py build script we should not
|
# when using the nix/build-all.py build script we should not
|
||||||
@@ -170,6 +177,54 @@ add_definitions(-DWITH_GLTF)
|
|||||||
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_GLTF)
|
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_GLTF)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Add USD support to serializers
|
||||||
|
if(NOT MINIMAL_BUILD AND USD_SUPPORT)
|
||||||
|
UNIFY_ENVVARS_AND_CACHE(USD_INCLUDE_DIR)
|
||||||
|
UNIFY_ENVVARS_AND_CACHE(USD_LIBRARY_DIR)
|
||||||
|
|
||||||
|
if("${USD_INCLUDE_DIR}" STREQUAL "")
|
||||||
|
find_path(USD_INCLUDE_DIR pxr.h
|
||||||
|
[PATHS
|
||||||
|
/usr/include/pxr
|
||||||
|
/usr/local/include/pxr
|
||||||
|
]
|
||||||
|
REQUIRED
|
||||||
|
)
|
||||||
|
if(USD_INCLUDE_DIR)
|
||||||
|
message(STATUS "Found USD include files in: ${USD_INCLUDE_DIR}")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unable to find USD include directory, specify USD_INCLUDE_DIR manually.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(USD_INCLUDE_DIR ${USD_INCLUDE_DIR} CACHE FILEPATH "USD header files")
|
||||||
|
message(STATUS "Looking for USD include files in: ${USD_INCLUDE_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(USD_LIBRARIES
|
||||||
|
usd_usd
|
||||||
|
usd_usdGeom
|
||||||
|
usd_usdShade
|
||||||
|
usd_usdLux
|
||||||
|
usd_vt
|
||||||
|
usd_sdf
|
||||||
|
usd_tf
|
||||||
|
usd_gf
|
||||||
|
)
|
||||||
|
|
||||||
|
find_library(USD_LIBRARY
|
||||||
|
NAMES ${USD_LIBRARIES}
|
||||||
|
PATHS ${USD_LIBRARY_DIR})
|
||||||
|
if(USD_LIBRARY)
|
||||||
|
message(STATUS "USD libraries ${USD_LIBRARIES} found in: ${USD_LIBRARY_DIR}")
|
||||||
|
link_directories(${USD_LIBRARY_DIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Unable to find USD libraries in: ${USD_LIBRARY_DIR}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-DWITH_USD)
|
||||||
|
set(SWIG_DEFINES ${SWIG_DEFINES} -DWITH_USD)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Set INSTALL_RPATH for target
|
# Set INSTALL_RPATH for target
|
||||||
MACRO(SET_INSTALL_RPATHS _target _paths)
|
MACRO(SET_INSTALL_RPATHS _target _paths)
|
||||||
SET(${_target}_rpaths "")
|
SET(${_target}_rpaths "")
|
||||||
@@ -633,6 +688,7 @@ ENDIF()
|
|||||||
|
|
||||||
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS}
|
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCC_INCLUDE_DIR} ${OPENCOLLADA_INCLUDE_DIRS}
|
||||||
${Boost_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${HDF5_INCLUDE_DIR}
|
${Boost_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} ${JSON_INCLUDE_DIR} ${HDF5_INCLUDE_DIR}
|
||||||
|
${USD_INCLUDE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
function(files_for_ifc_version IFC_VERSION RESULT_NAME)
|
function(files_for_ifc_version IFC_VERSION RESULT_NAME)
|
||||||
@@ -841,7 +897,7 @@ endforeach()
|
|||||||
add_library(Serializers ${SERIALIZERS_FILES})
|
add_library(Serializers ${SERIALIZERS_FILES})
|
||||||
set_target_properties(Serializers PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS ${CONVERT_PRECISION}" VERSION "0.6.0" SOVERSION "0.6")
|
set_target_properties(Serializers PROPERTIES COMPILE_FLAGS "-DIFC_GEOM_EXPORTS ${CONVERT_PRECISION}" VERSION "0.6.0" SOVERSION "0.6")
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(Serializers ${SERIALIZER_SCHEMA_LIBRARIES} ${OPENCOLLADA_LIBRARIES})
|
TARGET_LINK_LIBRARIES(Serializers ${SERIALIZER_SCHEMA_LIBRARIES} ${OPENCOLLADA_LIBRARIES} ${USD_LIBRARIES})
|
||||||
|
|
||||||
endif(BUILD_CONVERT or BUILD_IFCPYTHON)
|
endif(BUILD_CONVERT or BUILD_IFCPYTHON)
|
||||||
|
|
||||||
@@ -854,7 +910,7 @@ set(IFCCONVERT_FILES ${IFCCONVERT_CPP_FILES} ${IFCCONVERT_H_FILES})
|
|||||||
ADD_EXECUTABLE(IfcConvert ${IFCCONVERT_FILES})
|
ADD_EXECUTABLE(IfcConvert ${IFCCONVERT_FILES})
|
||||||
set_target_properties(IfcConvert PROPERTIES COMPILE_FLAGS "${CONVERT_PRECISION}")
|
set_target_properties(IfcConvert PROPERTIES COMPILE_FLAGS "${CONVERT_PRECISION}")
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(IfcConvert ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES})
|
TARGET_LINK_LIBRARIES(IfcConvert ${IFCOPENSHELL_LIBRARIES} ${OPENCASCADE_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_LIBRARIES} ${USD_LIBRARIES})
|
||||||
|
|
||||||
if ((NOT WIN32) AND BUILD_SHARED_LIBS)
|
if ((NOT WIN32) AND BUILD_SHARED_LIBS)
|
||||||
# Only set RPATHs when building shared libraries (i.e. IfcParse and
|
# Only set RPATHs when building shared libraries (i.e. IfcParse and
|
||||||
|
|||||||
@@ -711,7 +711,8 @@ int main(int argc, char** argv) {
|
|||||||
CACHE = IfcUtil::path::from_utf8(".cache"),
|
CACHE = IfcUtil::path::from_utf8(".cache"),
|
||||||
HDF = IfcUtil::path::from_utf8(".h5"),
|
HDF = IfcUtil::path::from_utf8(".h5"),
|
||||||
XML = IfcUtil::path::from_utf8(".xml"),
|
XML = IfcUtil::path::from_utf8(".xml"),
|
||||||
IFC = IfcUtil::path::from_utf8(".ifc");
|
IFC = IfcUtil::path::from_utf8(".ifc"),
|
||||||
|
USD = IfcUtil::path::from_utf8(".usd");
|
||||||
|
|
||||||
// @todo clean up serializer selection
|
// @todo clean up serializer selection
|
||||||
// @todo detect program options that conflict with the chosen serializer
|
// @todo detect program options that conflict with the chosen serializer
|
||||||
@@ -857,7 +858,7 @@ int main(int argc, char** argv) {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef WITH_USD
|
#ifdef WITH_USD
|
||||||
} else if (output_extension == USD) {
|
} else if (output_extension == USD) {
|
||||||
serializer = boost::make_shared<UsdSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
|
serializer = boost::make_shared<USDSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
|
||||||
#endif
|
#endif
|
||||||
} else if (output_extension == STP) {
|
} else if (output_extension == STP) {
|
||||||
serializer = boost::make_shared<StepSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
|
serializer = boost::make_shared<StepSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
|
||||||
|
|||||||
@@ -2,15 +2,11 @@
|
|||||||
|
|
||||||
#include "USDSerializer.h"
|
#include "USDSerializer.h"
|
||||||
|
|
||||||
#include "../ifcparse/utils.h"
|
#include "pxr/base/tf/token.h"
|
||||||
|
#include "pxr/base/gf/vec3f.h"
|
||||||
#include "pxr/usd/sdf/path.h"
|
#include "pxr/base/gf/rotation.h"
|
||||||
#include "pxr/usd/gf/vec3f.h"
|
|
||||||
#include "pxr/usd/gf/rotation.h"
|
|
||||||
#include "pxr/usd/tf/token.h"
|
|
||||||
#include "pxr/usd/usdGeom/xform.h"
|
#include "pxr/usd/usdGeom/xform.h"
|
||||||
#include "pxr/usd/usdGeom/xformOp.h"
|
#include "pxr/usd/usdGeom/xformOp.h"
|
||||||
#include "pxr/usd/usdGeom/mesh.h"
|
|
||||||
#include "pxr/usd/usdGeom/tokens.h"
|
#include "pxr/usd/usdGeom/tokens.h"
|
||||||
#include "pxr/usd/usdGeom/scope.h"
|
#include "pxr/usd/usdGeom/scope.h"
|
||||||
#include "pxr/usd/usdLux/distantLight.h"
|
#include "pxr/usd/usdLux/distantLight.h"
|
||||||
@@ -20,23 +16,16 @@
|
|||||||
#include "pxr/usd/usdShade/materialBindingAPI.h"
|
#include "pxr/usd/usdShade/materialBindingAPI.h"
|
||||||
#include "pxr/usd/usdShade/connectableAPI.h"
|
#include "pxr/usd/usdShade/connectableAPI.h"
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
USDSerializer::USDSerializer(const std::string& filename, const SerializerSettings& settings)
|
USDSerializer::USDSerializer(const std::string& filename, const SerializerSettings& settings)
|
||||||
: WriteOnlyGeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, filename_(filename)
|
, filename_(filename)
|
||||||
, settings_(settings)
|
|
||||||
{
|
{
|
||||||
// create a new stage
|
// create a new stage
|
||||||
stage_ = pxr::UsdStage::CreateNew(filename + ".usda");
|
stage_ = pxr::UsdStage::CreateNew(filename + ".usda");
|
||||||
if( !settings().get(SerializerSettings::USE_Y_UP) )
|
|
||||||
stage_->SetDefaultPrim(pxr::UsdGeomXform::Define(stage_, pxr::SdfPath("/"), pxr::UsdGeomTokens->z));
|
|
||||||
else
|
|
||||||
stage_->SetDefaultPrim(pxr::UsdGeomXform::Define(stage_, pxr::SdfPath("/"), pxr::UsdGeomTokens->y));
|
|
||||||
// create root xform prim 'World'
|
// create root xform prim 'World'
|
||||||
pxr::UsdGeomXform::Define(stage_, pxr::SdfPath("/World"));
|
pxr::UsdGeomXform::Define(stage_, pxr::SdfPath("/World"));
|
||||||
pxr::UsdGeomScope::Define(stage_, pxr::SdfPath("/Looks"));
|
pxr::UsdGeomScope::Define(stage_, pxr::SdfPath("/Looks"));
|
||||||
@@ -55,7 +44,7 @@ void USDSerializer::createLighting() {
|
|||||||
// set the light's orientation
|
// set the light's orientation
|
||||||
pxr::UsdGeomXform xform(stage_->GetPrimAtPath(pxr::SdfPath(light_path)));
|
pxr::UsdGeomXform xform(stage_->GetPrimAtPath(pxr::SdfPath(light_path)));
|
||||||
pxr::GfVec3f light_direction(0.0f, 0.0f, -1.0f);
|
pxr::GfVec3f light_direction(0.0f, 0.0f, -1.0f);
|
||||||
xform.AddRotateOp(pxr::UsdGeomXformOp::PrecisionFloat, pxr::UsdGeomXformOp::TypeRotateXYZ).Set(pxr::GfRotation(pxr::GfVec3f(0.0f, 1.0f, 0.0f), light_direction).GetQuaternion());
|
//xform.AddRotateOp(pxr::UsdGeomXformOp::PrecisionFloat, pxr::UsdGeomXformOp::TypeRotateXYZ).Set(pxr::GfRotation(pxr::GfVec3f(0.0f, 1.0f, 0.0f), light_direction).GetQuaternion());
|
||||||
// set the light's color
|
// set the light's color
|
||||||
pxr::UsdLuxDistantLight light(stage_->GetPrimAtPath(pxr::SdfPath(light_path)));
|
pxr::UsdLuxDistantLight light(stage_->GetPrimAtPath(pxr::SdfPath(light_path)));
|
||||||
light.CreateIntensityAttr().Set(1000.0f);
|
light.CreateIntensityAttr().Set(1000.0f);
|
||||||
@@ -68,11 +57,11 @@ void USDSerializer::writeMaterial(const pxr::UsdGeomMesh& mesh,const IfcGeom::Ma
|
|||||||
pxr::UsdShadeMaterial::Define(stage_, pxr::SdfPath(ss.str()));
|
pxr::UsdShadeMaterial::Define(stage_, pxr::SdfPath(ss.str()));
|
||||||
pxr::UsdShadeMaterial material(stage_->GetPrimAtPath(pxr::SdfPath(ss.str())));
|
pxr::UsdShadeMaterial material(stage_->GetPrimAtPath(pxr::SdfPath(ss.str())));
|
||||||
pxr::UsdShadeShader shader = pxr::UsdShadeShader::Define(stage_, pxr::SdfPath(ss.str() + "/Shader"));
|
pxr::UsdShadeShader shader = pxr::UsdShadeShader::Define(stage_, pxr::SdfPath(ss.str() + "/Shader"));
|
||||||
shader.CreateIdAttr().Set(TfToken("UsdPreviewSurface"));
|
shader.CreateIdAttr().Set(pxr::TfToken("UsdPreviewSurface"));
|
||||||
|
|
||||||
float rgba[4] { 0.18f, 0.18f, 0.18f, 1.0f };
|
float rgba[4] { 0.18f, 0.18f, 0.18f, 1.0f };
|
||||||
if (style.hasDiffuse())
|
if (style.hasDiffuse())
|
||||||
for (int i = 0; i < 3; ++i) rgba[i] = static_cast<float> style.diffuse()[i];
|
for (int i = 0; i < 3; ++i) rgba[i] = static_cast<float>(style.diffuse()[i]);
|
||||||
shader.CreateInput(pxr::TfToken("diffuseColor"), pxr::SdfValueTypeNames->Color3f).Set(pxr::GfVec3f(rgba[0], rgba[1], rgba[2]));
|
shader.CreateInput(pxr::TfToken("diffuseColor"), pxr::SdfValueTypeNames->Color3f).Set(pxr::GfVec3f(rgba[0], rgba[1], rgba[2]));
|
||||||
|
|
||||||
if(style.hasTransparency())
|
if(style.hasTransparency())
|
||||||
@@ -80,15 +69,15 @@ void USDSerializer::writeMaterial(const pxr::UsdGeomMesh& mesh,const IfcGeom::Ma
|
|||||||
shader.CreateInput(pxr::TfToken("opacity"), pxr::SdfValueTypeNames->Float).Set(rgba[3]);
|
shader.CreateInput(pxr::TfToken("opacity"), pxr::SdfValueTypeNames->Float).Set(rgba[3]);
|
||||||
|
|
||||||
if(style.hasSpecular()) {
|
if(style.hasSpecular()) {
|
||||||
for (int i = 0; i < 3; ++i) rgba[i] = static_cast<float> style.specular()[i];
|
for (int i = 0; i < 3; ++i) rgba[i] = static_cast<float>(style.specular()[i]);
|
||||||
shader.CreateInput(pxr::TfToken("useSpecularWorkflow"), pxr::SdfValueTypeNames->Int).Set(1);
|
shader.CreateInput(pxr::TfToken("useSpecularWorkflow"), pxr::SdfValueTypeNames->Int).Set(1);
|
||||||
} else {
|
} else {
|
||||||
shader.CreateInput(pxr::TfToken("useSpecularWorkflow"), pxr::SdfValueTypeNames->Int).Set(0);
|
shader.CreateInput(pxr::TfToken("useSpecularWorkflow"), pxr::SdfValueTypeNames->Int).Set(0);
|
||||||
}
|
}
|
||||||
shader.CreateInput(pxr::TfToken("specularColor"), pxr::SdfValueTypeNames->Color3f).Set(pxr::GfVec3f(rgba[0], rgba[1], rgba[2]));
|
shader.CreateInput(pxr::TfToken("specularColor"), pxr::SdfValueTypeNames->Color3f).Set(pxr::GfVec3f(rgba[0], rgba[1], rgba[2]));
|
||||||
|
|
||||||
material.CreateSurfaceOutput().ConnectToSource(shader, pxr::TfToken("surface"));
|
//material.CreateSurfaceOutput().ConnectToSource(shader, pxr::TfToken("surface"));
|
||||||
pxr::UsdShadeMaterialBindingAPI(mesh).Bind(material);
|
//pxr::UsdShadeMaterialBindingAPI(mesh).Bind(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool USDSerializer::ready() {
|
bool USDSerializer::ready() {
|
||||||
@@ -102,23 +91,25 @@ void USDSerializer::writeHeader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
|
||||||
if ( o->geometry().material_ids().empty() )
|
const IfcGeom::Representation::Triangulation& mesh = o->geometry();
|
||||||
|
if ( mesh.material_ids().empty() || mesh.verts().empty() || mesh.faces().empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std:sstringstream ss("/World/");
|
std::stringstream ss("/World/");
|
||||||
ss << o->geometry().id();
|
ss << mesh.id();
|
||||||
pxr::UsdGeomMesh::Define(stage_, pxr::SdfPath(ss.str()));
|
pxr::UsdGeomMesh usd_mesh = pxr::UsdGeomMesh::Define(stage_, pxr::SdfPath(ss.str()));
|
||||||
const IfcGeom::Representation::Triangulation& mesh = o->geometry();
|
|
||||||
const std::vector<double>& m = o->transformation().matrix().data();
|
const std::vector<double>& m = o->transformation().matrix().data();
|
||||||
|
|
||||||
const int vcount = (int)mesh.verts().size() / 3;
|
const int vcount = (int) mesh.verts().size() / 3;
|
||||||
|
pxr::VtVec3dArray points;
|
||||||
for ( std::vector<double>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) {
|
for ( std::vector<double>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) {
|
||||||
const double x = *(it++);
|
points.push_back(pxr::GfVec3d(*(it++), *(it++), *(it++)));
|
||||||
const double y = *(it++);
|
}
|
||||||
const double z = *(it++);
|
usd_mesh.CreatePointsAttr().Set(points);
|
||||||
|
usd_mesh.CreateFaceVertexIndicesAttr().Set(usd_utils::toVtArray(mesh.faces()));
|
||||||
|
const int fcount = (int) mesh.faces().size() / 3;
|
||||||
}
|
usd_mesh.CreateFaceVertexCountsAttr().Set(pxr::VtArray<int>(fcount, 3));
|
||||||
|
usd_mesh.CreateNormalsAttr().Set(usd_utils::toVtArray(mesh.normals()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,27 @@
|
|||||||
|
|
||||||
#include "../serializers/serializers_api.h"
|
#include "../serializers/serializers_api.h"
|
||||||
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
#include "../ifcparse/utils.h"
|
||||||
|
|
||||||
|
// undefine opencascade Handle macro, because it conflicts with USD
|
||||||
|
#undef Handle
|
||||||
|
|
||||||
#include "pxr/pxr.h"
|
#include "pxr/pxr.h"
|
||||||
#include "pxr/usd/usd/stage.h"
|
#include "pxr/usd/usd/stage.h"
|
||||||
|
#include "pxr/base/vt/array.h"
|
||||||
|
#include "pxr/usd/usdGeom/mesh.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace usd_utils {
|
||||||
|
template<typename T>
|
||||||
|
pxr::VtArray<T> toVtArray(const std::vector<T>& vec) {
|
||||||
|
auto array = pxr::VtArray<T>(vec.size());
|
||||||
|
for (size_t i = 0; i < vec.size(); ++i)
|
||||||
|
array[i] = vec[i];
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SERIALIZERS_API USDSerializer : public WriteOnlyGeometrySerializer {
|
class SERIALIZERS_API USDSerializer : public WriteOnlyGeometrySerializer {
|
||||||
private:
|
private:
|
||||||
@@ -35,7 +52,7 @@ private:
|
|||||||
bool ready_ = false;
|
bool ready_ = false;
|
||||||
pxr::UsdStageRefPtr stage_;
|
pxr::UsdStageRefPtr stage_;
|
||||||
|
|
||||||
int writeMaterial(const IfcGeom::Material&);
|
void writeMaterial(const pxr::UsdGeomMesh&, const IfcGeom::Material&);
|
||||||
void createLighting();
|
void createLighting();
|
||||||
public:
|
public:
|
||||||
USDSerializer(const std::string&, const SerializerSettings&);
|
USDSerializer(const std::string&, const SerializerSettings&);
|
||||||
|
|||||||
Reference in New Issue
Block a user