Skip to content

Commit

Permalink
Initialcommit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy1997 committed Sep 4, 2023
0 parents commit cc35889
Show file tree
Hide file tree
Showing 64 changed files with 3,179 additions and 0 deletions.
156 changes: 156 additions & 0 deletions DracoNet/DracoNet.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{bdd3abab-c1b2-4cd2-88b8-609fcde93547}</ProjectGuid>
<RootNamespace>DracoNet</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\Revit2GLTF</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\Revit2GLTF</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>E:\draco;E:\draco\src;E:\draco\build;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>E:\draco\build\Debug\draco.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>E:\draco;E:\draco\src;E:\draco\build;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>E:\draco\build\Release\draco.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="dracoEncoder.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dracoEncoder.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
27 changes: 27 additions & 0 deletions DracoNet/DracoNet.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dracoEncoder.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dracoEncoder.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions DracoNet/DracoNet.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
153 changes: 153 additions & 0 deletions DracoNet/dracoEncoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Copyright 2016 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "dracoEncoder.h"
char* dracoEncoder(float* positions, float* uvs, float* normals, int* indexs,
int num_obj_faces, int num_positions, int num_tex_coords, int num_normals,
DracoEncoderOptions options, int* length) {
int pos_att_id_ = -1;
int tex_att_id_ = -1;
int norm_att_id_ = -1;

bool use_identity_mapping = false;
std::unique_ptr<Mesh> mesh(new Mesh());
Mesh* out_mesh = mesh.get();
PointCloud* out_point_cloud_ = static_cast<PointCloud*>(out_mesh);

out_mesh->SetNumFaces(num_obj_faces);
out_point_cloud_->set_num_points(num_obj_faces * 3);

if (num_positions != NULL && num_positions > 0) {
GeometryAttribute va;
va.Init(GeometryAttribute::POSITION, nullptr, 3, DT_FLOAT32, false,
sizeof(float) * 3, 0);
pos_att_id_ = out_point_cloud_->AddAttribute(va, use_identity_mapping, num_positions);
for (int i = 0; i < num_positions; ++i) {
float position[3];
position[0] = positions[3 * i];
position[1] = positions[3 * i + 1];
position[2] = positions[3 * i + 2];
out_point_cloud_->attribute(pos_att_id_)
->SetAttributeValue(AttributeValueIndex(i), position);
}
}
if (num_normals != NULL && num_normals > 0) {
GeometryAttribute va;
va.Init(GeometryAttribute::NORMAL, nullptr, 3, DT_FLOAT32, false,
sizeof(float) * 3, 0);
norm_att_id_ =
out_point_cloud_->AddAttribute(va, use_identity_mapping, num_normals);

for (int i = 0; i < num_normals; ++i) {
float normal[3];
normal[0] = normals[3 * i];
normal[1] = normals[3 * i + 1];
normal[2] = normals[3 * i + 2];
out_point_cloud_->attribute(norm_att_id_)
->SetAttributeValue(AttributeValueIndex(i), normal);
}
}
if (num_tex_coords != NULL && num_tex_coords > 0) {
GeometryAttribute va;
va.Init(GeometryAttribute::TEX_COORD, nullptr, 2, DT_FLOAT32, false,
sizeof(float) * 2, 0);
tex_att_id_ = out_point_cloud_->AddAttribute(va, use_identity_mapping,
num_tex_coords);

for (int i = 0; i < num_tex_coords; ++i) {
float uv[2];
uv[0] = uvs[2 * i];
uv[1] = uvs[2 * i + 1];
out_point_cloud_->attribute(tex_att_id_)
->SetAttributeValue(AttributeValueIndex(i), uv);
}
}


for (int i = 0; i < num_obj_faces; ++i) {
for (int j = 0; j < 3; ++j) {
int index = 3 * i + j;
const PointIndex vert_id(index);

if (pos_att_id_ != -1) {
out_point_cloud_->attribute(pos_att_id_)
->SetPointMapEntry(vert_id, AttributeValueIndex(indexs[index]));
}
if (norm_att_id_ != -1) {
out_point_cloud_->attribute(norm_att_id_)
->SetPointMapEntry(vert_id, AttributeValueIndex(indexs[index]));
}
if (tex_att_id_ != -1) {
out_point_cloud_->attribute(tex_att_id_)
->SetPointMapEntry(vert_id, AttributeValueIndex(indexs[index]));
}
}
}

Mesh::Face face;
for (FaceIndex i(0); i < num_obj_faces; ++i) {
for (int c = 0; c < 3; ++c) {
face[c] = 3 * i.value() + c;
}
out_mesh->SetFace(i, face);
}

out_point_cloud_->DeduplicateAttributeValues();
out_point_cloud_->DeduplicatePointIds();

const int speed = 10 - options.compression_level;
draco::Encoder encoder;
if (options.pos_quantization_bits > 0) {
encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION,
options.pos_quantization_bits);
}
if (options.tex_coords_quantization_bits > 0) {
encoder.SetAttributeQuantization(draco::GeometryAttribute::TEX_COORD,
options.tex_coords_quantization_bits);
}
if (options.normals_quantization_bits > 0) {
encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL,
options.normals_quantization_bits);
}
if (options.generic_quantization_bits > 0) {
encoder.SetAttributeQuantization(draco::GeometryAttribute::GENERIC,
options.generic_quantization_bits);
}
encoder.SetSpeedOptions(speed, speed);
draco::EncoderBuffer buffer;
const draco::Status status = encoder.EncodeMeshToBuffer(*out_mesh, &buffer);
if (!status.ok()) {
printf("Failed to encode the mesh.\n");
printf("%s\n", status.error_msg());
return nullptr;
}
// copy
int size = buffer.size();
*length = size;
char* pc = new char[size];
std::vector<char> data = *(buffer.buffer());
for (int i = 0; i < size; i++) {
pc[i] = data[i];
}
return pc;
}

void deleteDracoData(char* data) {
try {
delete data;
}
catch (const std::exception&)
{
}
}
35 changes: 35 additions & 0 deletions DracoNet/dracoEncoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016 The Draco Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <draco/compression/encode.h>
using namespace draco;
struct DracoEncoderOptions {
int pos_quantization_bits;
int tex_coords_quantization_bits;
int normals_quantization_bits;
int generic_quantization_bits;
int compression_level;
};


extern "C" _declspec(dllexport)
char* dracoEncoder(float* positions, float* uvs, float* normals,
int* indexs, int num_obj_faces, int num_positions,
int num_tex_coords,
int num_normals,
DracoEncoderOptions options,
int* length);

extern "C" _declspec(dllexport) void deleteDracoData(char* data);
Loading

0 comments on commit cc35889

Please sign in to comment.