Add experimental libdust3d for windows [skip ci]

master
huxingyi 2020-07-24 14:42:40 +09:30
parent db1c34a78c
commit b3e4955433
8 changed files with 450 additions and 7 deletions

View File

@ -51,11 +51,21 @@ build: false
test_script:
- set PATH=%PATH%;%QTDIR%\bin
- if "%PLATFORM%" == "x64"
qmake "BOOST_INCLUDEDIR=C:\Libraries\boost_1_66_0" "CGAL_DIR=%APPVEYOR_BUILD_FOLDER%\thirdparty\cgal\CGAL-4.13"
- if "%PLATFORM%" == "x86"
qmake "BOOST_INCLUDEDIR=C:\Libraries\boost_1_66_0" "CGAL_DIR=%APPVEYOR_BUILD_FOLDER%\CGAL-4.13"
- nmake -f Makefile.Release
- cd lib
- if "%PLATFORM%" == "x64"
qmake "BOOST_INCLUDEDIR=C:\Libraries\boost_1_66_0" "CGAL_DIR=%APPVEYOR_BUILD_FOLDER%\thirdparty\cgal\CGAL-4.13"
- if "%PLATFORM%" == "x86"
qmake "BOOST_INCLUDEDIR=C:\Libraries\boost_1_66_0" "CGAL_DIR=%APPVEYOR_BUILD_FOLDER%\CGAL-4.13"
- nmake -f Makefile.Release
- cd %APPVEYOR_BUILD_FOLDER%
after_test:
# Check deps by Dependency Walker
@ -73,6 +83,8 @@ after_test:
- if "%TAG%" == "unstable"
7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\release\dust3d.pdb
- 7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\release\dust3d.exe
- 7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\lib\release\libdust3d.dll
- 7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\lib\release\libdust3d.lib
- if "%TAG%" == "unstable"
7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\thirdparty\instant-meshes\build\RelWithDebInfo\instant-meshes.pdb
- 7z a %RELEASE_FILENAME% %APPVEYOR_BUILD_FOLDER%\thirdparty\instant-meshes\build\RelWithDebInfo\instant-meshes.dll

View File

@ -54,11 +54,11 @@ win32 {
}
win32 {
RC_FILE = dust3d.rc
RC_FILE = $${SOURCE_ROOT}dust3d.rc
}
macx {
ICON = dust3d.icns
ICON = $${SOURCE_ROOT}dust3d.icns
RESOURCE_FILES.files = $$ICON
RESOURCE_FILES.path = Contents/Resources
@ -551,16 +551,16 @@ INCLUDEPATH += thirdparty/instant-meshes/instant-meshes-dust3d/ext/rply
INCLUDEPATH += thirdparty/instant-meshes/instant-meshes-dust3d/ext/half
unix {
SOURCES += thirdparty/instant-meshes/instant-meshes-api.cpp
LIBS += -Lthirdparty/instant-meshes/build -linstant-meshes
LIBS += -Lthirdparty/instant-meshes/build/ext_build/tbb -ltbb_static
LIBS += -L$${SOURCE_ROOT}thirdparty/instant-meshes/build -linstant-meshes
LIBS += -L$${SOURCE_ROOT}thirdparty/instant-meshes/build/ext_build/tbb -ltbb_static
unix:!macx {
LIBS += -ldl
}
}
win32 {
DEFINES += _USE_MATH_DEFINES
LIBS += -Lthirdparty/instant-meshes/build/RelWithDebInfo -linstant-meshes
LIBS += -Lthirdparty/instant-meshes/build/ext_build/tbb/RelWithDebInfo -ltbb
LIBS += -L$${SOURCE_ROOT}thirdparty/instant-meshes/build/RelWithDebInfo -linstant-meshes
LIBS += -L$${SOURCE_ROOT}thirdparty/instant-meshes/build/ext_build/tbb/RelWithDebInfo -ltbb
}
INCLUDEPATH += thirdparty/bullet3/src
@ -913,4 +913,4 @@ INCLUDEPATH += $$CGAL_BUILDINCLUDEDIR
LIBS += -L$$CGAL_LIBDIR -l$$CGAL_LIBNAME
target.path = ./
INSTALLS += target
INSTALLS += target

48
include/dust3d.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef DUST3D_H
#define DUST3D_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# ifdef DUST3D_EXPORTING
# define DUST3D_DLL __declspec(dllexport)
# else
# define DUST3D_DLL __declspec(dllimport)
# endif
#else
# define DUST3D_DLL
#endif
# define DUST3D_API __stdcall
#define DUST3D_OK 0
#define DUST3D_ERROR 1
#define DUST3D_UNSUPPORTED 2
typedef struct _dust3d dust3d;
DUST3D_DLL void DUST3D_API dust3dInitialize(int argc, char *argv[]);
DUST3D_DLL dust3d * DUST3D_API dust3dOpenFromMemory(const char *documentType, const char *buffer, int size);
DUST3D_DLL dust3d * DUST3D_API dust3dOpen(const char *fileName);
DUST3D_DLL void DUST3D_API dust3dSetUserData(dust3d *ds3, void *userData);
DUST3D_DLL void * DUST3D_API dust3dGetUserData(dust3d *ds3);
DUST3D_DLL int DUST3D_API dust3dGenerateMesh(dust3d *ds3);
DUST3D_DLL int DUST3D_API dust3dGetMeshVertexCount(dust3d *ds3);
DUST3D_DLL int DUST3D_API dust3dGetMeshTriangleCount(dust3d *ds3);
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleIndices(dust3d *ds3, int *indices);
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleColors(dust3d *ds3, unsigned int *colors);
DUST3D_DLL void DUST3D_API dust3dGetMeshVertexPosition(dust3d *ds3, int vertexIndex, float *x, float *y, float *z);
DUST3D_DLL void DUST3D_API dust3dGetMeshVertexSource(dust3d *ds3, int vertexIndex, unsigned char partId[16], unsigned char nodeId[16]);
DUST3D_DLL int DUST3D_API dust3dGetMeshTriangleAndQuadCount(dust3d *ds3);
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleAndQuadIndices(dust3d *ds3, int *indices);
DUST3D_DLL void DUST3D_API dust3dClose(dust3d *ds3);
DUST3D_DLL int DUST3D_API dust3dError(dust3d *ds3);
DUST3D_DLL const char * DUST3D_API dust3dVersion(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(nodes2mesh)
link_directories(
../../release
)
add_executable(nodes2mesh
nodes2mesh.cpp
)
target_include_directories(nodes2mesh PUBLIC
../../../include
)
target_link_libraries(nodes2mesh PUBLIC
libdust3d
)

View File

@ -0,0 +1,71 @@
#include <iostream>
#include <stdio.h>
#include <dust3d.h>
int main(int argc, char *argv[])
{
dust3dInitialize(argc, argv);
printf("dust3d version:%s\n", dust3dVersion());
dust3d *ds3 = dust3dOpen("screwdriver.xml");
if (ds3) {
int error = dust3dGenerateMesh(ds3);
printf("error: %d\n", error);
{
FILE *fp = nullptr;
fopen_s(&fp, "test-triangles.obj", "wb");
int vertexCount = dust3dGetMeshVertexCount(ds3);
for (int i = 0; i < vertexCount; ++i) {
float x, y, z;
dust3dGetMeshVertexPosition(ds3, i, &x, &y, &z);
fprintf(fp, "v %f %f %f\n", x, y, z);
}
int triangleCount = dust3dGetMeshTriangleCount(ds3);
if (triangleCount > 0) {
int *triangleIndices = new int[triangleCount * 3];
dust3dGetMeshTriangleIndices(ds3, triangleIndices);
for (int i = 0, offset = 0; i < triangleCount; ++i, offset += 3) {
fprintf(fp, "f %d %d %d\n",
1 + triangleIndices[offset],
1 + triangleIndices[offset + 1],
1 + triangleIndices[offset + 2]);
}
delete[] triangleIndices;
}
fclose(fp);
}
{
FILE *fp = nullptr;
fopen_s(&fp, "test-triangleandquads.obj", "wb");
int vertexCount = dust3dGetMeshVertexCount(ds3);
for (int i = 0; i < vertexCount; ++i) {
float x, y, z;
dust3dGetMeshVertexPosition(ds3, i, &x, &y, &z);
fprintf(fp, "v %f %f %f\n", x, y, z);
}
int triangleAndQuadCount = dust3dGetMeshTriangleAndQuadCount(ds3);
if (triangleAndQuadCount > 0) {
int *faceIndices = new int[triangleAndQuadCount * 4];
dust3dGetMeshTriangleAndQuadIndices(ds3, faceIndices);
for (int i = 0, offset = 0; i < triangleAndQuadCount; ++i, offset += 4) {
if (-1 == faceIndices[offset + 3]) {
fprintf(fp, "f %d %d %d\n",
1 + faceIndices[offset],
1 + faceIndices[offset + 1],
1 + faceIndices[offset + 2]);
} else {
fprintf(fp, "f %d %d %d %d\n",
1 + faceIndices[offset],
1 + faceIndices[offset + 1],
1 + faceIndices[offset + 2],
1 + faceIndices[offset + 3]);
}
}
delete[] faceIndices;
}
fclose(fp);
}
dust3dClose(ds3);
}
}

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<canvas originX="0.570297" originY="0.726733" originZ="1.4901" rigType="None">
<nodes>
<node id="{052ad752-3cd9-42e9-9720-7098ac98a07d}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0792079" x="0.572277" y="0.819802" z="1.4901"/>
<node id="{0b521029-80d5-4932-8b79-b7b9766e52c1}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0316832" x="0.566337" y="0.409901" z="1.4901"/>
<node id="{0f2c99fa-2a99-48dd-b33e-11b40fd6946a}" partId="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" radius="0.0158416" x="0.568317" y="0.372277" z="1.49208"/>
<node id="{18fec39f-81fd-4f9f-8bb6-30976409acc5}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0356436" x="0.568317" y="0.459406" z="1.4901"/>
<node id="{1a37586b-fc7e-409d-b920-89e34dc9685a}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0514851" x="0.570297" y="0.592079" z="1.4901"/>
<node id="{3d6e5996-ed1b-482e-98f1-d9791366f8be}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0752475" x="0.572277" y="0.69703" z="1.4901"/>
<node id="{3fcd81ca-9dde-49b8-bf30-0c2b6d2c4919}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0316832" x="0.568317" y="0.368317" z="1.4901"/>
<node id="{494bd174-4d1d-4da1-96e1-5e72e2cec0c5}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0712871" x="0.572277" y="0.920792" z="1.4901"/>
<node id="{6491631c-8e24-46b1-9805-68c39b7ad0ae}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0475248" x="0.570297" y="0.560396" z="1.4901"/>
<node id="{6caa6fb6-3851-47c8-96e7-c8c8c4f04797}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0514851" x="0.572277" y="0.950495" z="1.4901"/>
<node id="{81c2f46e-972a-42fd-ad60-68731a6dd724}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0277228" x="0.568317" y="0.358416" z="1.4901"/>
<node id="{88359e0b-f6e6-4dcc-8e2c-64ab90d2c13c}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0633663" x="0.568317" y="0.617822" z="1.4901"/>
<node id="{8ee7981c-e086-4584-ba51-d043451c8049}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0633663" x="0.572277" y="0.934653" z="1.4901"/>
<node id="{93038295-8e0a-42a5-9b09-fc3d56871090}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0475248" x="0.568317" y="0.449505" z="1.4901"/>
<node id="{a338c5af-30ea-4655-819b-157a6511d2dd}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.039604" x="0.572277" y="0.968317" z="1.4901"/>
<node id="{b06b7467-5f7e-4bce-9fda-9d6db5eed483}" partId="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" radius="0.005" x="0.574257" y="0.019802" z="1.49208"/>
<node id="{b12a3622-f4b9-4daa-9e91-32fbf7905479}" partId="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" radius="0.0158416" x="0.572277" y="0.0475248" z="1.49208"/>
<node id="{c9f71ed2-e65a-40fe-b4c9-07790bb5a9f7}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.039604" x="0.566337" y="0.417822" z="1.4901"/>
<node id="{cc81b557-08d8-4764-9a6b-3cadde0e8acc}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" radius="0.0514851" x="0.568317" y="0.431683" z="1.4901"/>
</nodes>
<edges>
<edge from="{6491631c-8e24-46b1-9805-68c39b7ad0ae}" id="{09f95e2e-7617-460c-a3d4-1340424473f4}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{18fec39f-81fd-4f9f-8bb6-30976409acc5}"/>
<edge from="{93038295-8e0a-42a5-9b09-fc3d56871090}" id="{0a222641-a65c-4ff6-91a4-46334fd80c27}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{cc81b557-08d8-4764-9a6b-3cadde0e8acc}"/>
<edge from="{494bd174-4d1d-4da1-96e1-5e72e2cec0c5}" id="{0e2f91cf-8c90-485d-977e-ee1e03bb0abe}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{052ad752-3cd9-42e9-9720-7098ac98a07d}"/>
<edge from="{c9f71ed2-e65a-40fe-b4c9-07790bb5a9f7}" id="{40591e34-2eb4-4ff5-bf37-0ac9ee0c551a}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{0b521029-80d5-4932-8b79-b7b9766e52c1}"/>
<edge from="{b12a3622-f4b9-4daa-9e91-32fbf7905479}" id="{4efedfed-e768-4d61-8195-aa61d201ef5a}" partId="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" to="{b06b7467-5f7e-4bce-9fda-9d6db5eed483}"/>
<edge from="{052ad752-3cd9-42e9-9720-7098ac98a07d}" id="{5d36913f-a47b-4f53-9846-c0bebdc4c700}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{3d6e5996-ed1b-482e-98f1-d9791366f8be}"/>
<edge from="{88359e0b-f6e6-4dcc-8e2c-64ab90d2c13c}" id="{5fd69e09-e673-4597-8434-8f0bb2ecf13f}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{1a37586b-fc7e-409d-b920-89e34dc9685a}"/>
<edge from="{3d6e5996-ed1b-482e-98f1-d9791366f8be}" id="{60751dc5-1e08-45d8-acbe-3847c8219d84}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{88359e0b-f6e6-4dcc-8e2c-64ab90d2c13c}"/>
<edge from="{0b521029-80d5-4932-8b79-b7b9766e52c1}" id="{6795f064-1346-4523-a6cd-b9d537302ba4}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{3fcd81ca-9dde-49b8-bf30-0c2b6d2c4919}"/>
<edge from="{8ee7981c-e086-4584-ba51-d043451c8049}" id="{9aaa5ec4-a5d8-4f6f-9582-5272ec192b69}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{494bd174-4d1d-4da1-96e1-5e72e2cec0c5}"/>
<edge from="{a338c5af-30ea-4655-819b-157a6511d2dd}" id="{aa395747-4370-493b-bf75-771315b85ffb}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{6caa6fb6-3851-47c8-96e7-c8c8c4f04797}"/>
<edge from="{6caa6fb6-3851-47c8-96e7-c8c8c4f04797}" id="{abf608c4-442e-4ae8-a560-977b7545895c}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{8ee7981c-e086-4584-ba51-d043451c8049}"/>
<edge from="{0f2c99fa-2a99-48dd-b33e-11b40fd6946a}" id="{ca71f17b-27e5-48f7-9325-419c49eef871}" partId="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" to="{b12a3622-f4b9-4daa-9e91-32fbf7905479}"/>
<edge from="{cc81b557-08d8-4764-9a6b-3cadde0e8acc}" id="{cfc312da-88aa-40a9-a55b-56e6fdb47f8b}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{c9f71ed2-e65a-40fe-b4c9-07790bb5a9f7}"/>
<edge from="{18fec39f-81fd-4f9f-8bb6-30976409acc5}" id="{d740dabe-0b3e-4846-89c5-ae5cd16204c5}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{93038295-8e0a-42a5-9b09-fc3d56871090}"/>
<edge from="{1a37586b-fc7e-409d-b920-89e34dc9685a}" id="{e8181c7a-924f-4906-b8b4-2155dd08032f}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{6491631c-8e24-46b1-9805-68c39b7ad0ae}"/>
<edge from="{3fcd81ca-9dde-49b8-bf30-0c2b6d2c4919}" id="{fc2a3bc9-f167-4659-a49b-ca8e34714b0a}" partId="{a75c642c-b138-46ee-9c3c-71365e0043ba}" to="{81c2f46e-972a-42fd-ad60-68731a6dd724}"/>
</edges>
<parts>
<part chamfered="false" color="#fffefed2" disabled="false" id="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" locked="false" rounded="true" subdived="true" visible="true" xMirrored="false"/>
<part chamfered="false" color="#ff1e1a10" disabled="false" id="{a75c642c-b138-46ee-9c3c-71365e0043ba}" locked="false" rounded="false" subdived="true" visible="true" xMirrored="false"/>
</parts>
<components>
<component combineMode="Normal" expanded="false" id="{ef4f4c35-fbb2-4035-9ecd-8c2a5fde1162}" linkData="{a75c642c-b138-46ee-9c3c-71365e0043ba}" linkDataType="partId"/>
<component combineMode="Normal" expanded="false" id="{259c56ab-b3aa-4535-9809-661867fc9962}" linkData="{65fa859c-ced6-40ce-8e92-b4ce81f891dd}" linkDataType="partId"/>
</components>
</canvas>

22
lib/libdust3d.pro Normal file
View File

@ -0,0 +1,22 @@
TEMPLATE = lib
VPATH += ../
SOURCE_ROOT = ../
CONFIG += skip_target_version_ext
include(../dust3d.pro)
DEFINES += DUST3D_EXPORTING
INCLUDEPATH += include
SOURCES += src/libdust3d.cpp
HEADERS += include/dust3d.h
for(path, INCLUDEPATH) {
PREFIXED_INCLUDEPATH += "../$$path"
}
INCLUDEPATH += $$PREFIXED_INCLUDEPATH

220
src/libdust3d.cpp Normal file
View File

@ -0,0 +1,220 @@
#include <string>
#include <fstream>
#include <streambuf>
#include <sstream>
#include <QVector3D>
#include <QString>
#include <QCoreApplication>
#include "dust3d.h"
#include "meshgenerator.h"
#include "snapshot.h"
#include "snapshotxml.h"
#include "model.h"
#include "version.h"
struct _dust3d
{
void *userData = nullptr;
GeneratedCacheContext *cacheContext = nullptr;
Model *resultMesh = nullptr;
Snapshot *snapshot = nullptr;
Outcome *outcome = nullptr;
int error = DUST3D_ERROR;
};
DUST3D_DLL int DUST3D_API dust3dError(dust3d *ds3)
{
return ds3->error;
}
DUST3D_DLL void DUST3D_API dust3dClose(dust3d *ds3)
{
delete ds3->resultMesh;
ds3->resultMesh = nullptr;
delete ds3->cacheContext;
ds3->cacheContext = nullptr;
delete ds3->snapshot;
ds3->snapshot = nullptr;
delete ds3->outcome;
ds3->outcome = nullptr;
delete ds3;
}
DUST3D_DLL void DUST3D_API dust3dInitialize(int argc, char *argv[])
{
if (nullptr == QCoreApplication::instance())
new QCoreApplication(argc, argv);
}
DUST3D_DLL dust3d * DUST3D_API dust3dOpenFromMemory(const char *documentType, const char *buffer, int size)
{
dust3d *ds3 = new dust3d;
ds3->error = DUST3D_ERROR;
delete ds3->outcome;
ds3->outcome = new Outcome;
if (0 == strcmp(documentType, "xml")) {
QByteArray data(buffer, size);
QXmlStreamReader stream(data);
delete ds3->snapshot;
ds3->snapshot = new Snapshot;
loadSkeletonFromXmlStream(ds3->snapshot, stream);
ds3->error = DUST3D_OK;
} else {
ds3->error = DUST3D_UNSUPPORTED;
}
return ds3;
}
DUST3D_DLL dust3d * DUST3D_API dust3dOpen(const char *fileName)
{
std::string name = fileName;
auto dotIndex = name.rfind('.');
if (std::string::npos == dotIndex)
return nullptr;
std::string extension = name.substr(dotIndex + 1);
std::ifstream is(name, std::ifstream::binary);
if (!is)
return nullptr;
is.seekg (0, is.end);
int length = is.tellg();
is.seekg (0, is.beg);
char *buffer = new char[length + 1];
is.read(buffer, length);
is.close();
buffer[length] = '\0';
dust3d *ds3 = dust3dOpenFromMemory(extension.c_str(), buffer, length);
delete[] buffer;
return ds3;
}
DUST3D_DLL void DUST3D_API dust3dSetUserData(dust3d *ds3, void *userData)
{
ds3->userData = userData;
}
DUST3D_DLL void * DUST3D_API dust3dGetUserData(dust3d *ds3)
{
return ds3->userData;
}
DUST3D_DLL const char * DUST3D_API dust3dVersion(void)
{
return APP_NAME " " APP_HUMAN_VER;
}
DUST3D_DLL int DUST3D_API dust3dGenerateMesh(dust3d *ds3)
{
ds3->error = DUST3D_ERROR;
if (nullptr == ds3->snapshot)
return ds3->error;
if (nullptr == ds3->cacheContext)
ds3->cacheContext = new GeneratedCacheContext();
Snapshot *snapshot = ds3->snapshot;
ds3->snapshot = nullptr;
MeshGenerator *meshGenerator = new MeshGenerator(snapshot);
meshGenerator->setGeneratedCacheContext(ds3->cacheContext);
meshGenerator->generate();
delete ds3->outcome;
ds3->outcome = meshGenerator->takeOutcome();
if (nullptr == ds3->outcome)
ds3->outcome = new Outcome;
if (meshGenerator->isSuccessful())
ds3->error = DUST3D_OK;
delete meshGenerator;
return ds3->error;
}
DUST3D_DLL int DUST3D_API dust3dGetMeshVertexCount(dust3d *ds3)
{
return (int)ds3->outcome->vertices.size();
}
DUST3D_DLL int DUST3D_API dust3dGetMeshTriangleCount(dust3d *ds3)
{
return (int)ds3->outcome->triangles.size();
}
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleIndices(dust3d *ds3, int *indices)
{
for (const auto &it: ds3->outcome->triangles) {
*(indices++) = (int)it[0];
*(indices++) = (int)it[1];
*(indices++) = (int)it[2];
}
}
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleColors(dust3d *ds3, unsigned int *colors)
{
for (const auto &it: ds3->outcome->triangleColors) {
*(colors++) = ((unsigned int)it.red() << 16) | ((unsigned int)it.green() << 8) | ((unsigned int)it.blue() << 0);
}
}
DUST3D_DLL void DUST3D_API dust3dGetMeshVertexPosition(dust3d *ds3, int vertexIndex, float *x, float *y, float *z)
{
if (vertexIndex >= 0 && vertexIndex < ds3->outcome->vertices.size()) {
const auto &v = ds3->outcome->vertices[vertexIndex];
*x = v.x();
*y = v.y();
*z = v.z();
}
}
DUST3D_DLL void DUST3D_API dust3dGetMeshVertexSource(dust3d *ds3, int vertexIndex, unsigned char partId[16], unsigned char nodeId[16])
{
if (vertexIndex >= 0 && vertexIndex < ds3->outcome->vertices.size()) {
const auto &source = ds3->outcome->vertexSourceNodes[vertexIndex];
auto sourcePartUuid = source.first.toByteArray(QUuid::Id128);
memcpy(partId, sourcePartUuid.constData(), sizeof(partId));
auto sourceNodeUuid = source.second.toByteArray(QUuid::Id128);
memcpy(partId, sourceNodeUuid.constData(), sizeof(nodeId));
}
}
DUST3D_DLL int DUST3D_API dust3dGetMeshTriangleAndQuadCount(dust3d *ds3)
{
return (int)ds3->outcome->triangleAndQuads.size();
}
DUST3D_DLL void DUST3D_API dust3dGetMeshTriangleAndQuadIndices(dust3d *ds3, int *indices)
{
for (const auto &it: ds3->outcome->triangleAndQuads) {
*(indices++) = (int)it[0];
*(indices++) = (int)it[1];
*(indices++) = (int)it[2];
if (it.size() > 3)
*(indices++) = (int)it[3];
else
*(indices++) = (int)-1;
}
}