Skip to content

Commit

Permalink
Add draco (#6)
Browse files Browse the repository at this point in the history
* Merge pull request PixarAnimationStudios#499 from shassard/dev

switch libtiff to http download

* Update CHANGELOG.md for 0.8.5a release

(Internal change: 1858057)

* Initial version of Draco plugin for USD.

* Fixing copyright date.

* Fixing more copyright dates.

* Renaming Draco CMake option in USD build script.

* Addressing Ondrej's comments.

* Fixing attribute indices with polygon recovery and refactoring.

* Checking quantization bits option range, zero indicates no quantization.

* Adding compression level option.

* Resolving code review comments.

* Resolving code review comments.

* Changing hole_faces and added_edges attribute types to uint8_t.

* Deleting Draco decoder before mesh translation starts.

* Finding Draco library and making it available as a build variable.

* Updating copyright headers.

* Updating Draco plugin version to match Draco release version.
  • Loading branch information
igorvytyaz authored Feb 7, 2019
1 parent 94ed3bc commit 1e99f83
Show file tree
Hide file tree
Showing 28 changed files with 2,706 additions and 0 deletions.
11 changes: 11 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ This plugin is compatible with MaterialX 1.36.0. The additional dependencies tha

For further information see our additional documentation on the MaterialX plugins [here](http://openusd.org/docs/MaterialX-USD-Plugins.html).

##### Draco Plugin

Enable the [Draco](https://github.com/google/draco) plugin in the build by specifying the cmake flag ```PXR_BUILD_DRACO_PLUGIN=TRUE```
when invoking cmake. This plugin is compatible with Draco 1.3.4. The additional dependencies that must be supplied when invoking cmake are:

| Dependency Name | Description | Version |
| ------------------ |---------------------------------------- | ------- |
| DRACO_ROOT | The root path to a Draco SDK install. | 1.3.4 |

Note that the Draco plugin is only tested on Linux.

## Tests

Disable unit testing and prevent tests from being built by specifying the cmake flag ```PXR_BUILD_TESTS=FALSE```
Expand Down
34 changes: 34 additions & 0 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,19 @@ def InstallAlembic(context, force, buildArgs):

ALEMBIC = Dependency("Alembic", InstallAlembic, "include/Alembic/Abc/Base.h")

############################################################
# Draco

DRACO_URL = "https://github.com/google/draco/archive/master.zip"

def InstallDraco(context, force, buildArgs):
with CurrentWorkingDirectory(DownloadURL(DRACO_URL, context, force)):
cmakeOptions = ['-DBUILD_USD_PLUGIN=ON']
cmakeOptions += buildArgs
RunCMake(context, force, cmakeOptions)

DRACO = Dependency("Draco", InstallDraco, "include/Draco/src/draco/compression/decode.h")

############################################################
# MaterialX

Expand Down Expand Up @@ -1073,6 +1086,11 @@ def InstallUSD(context, force, buildArgs):
else:
extraArgs.append('-DPXR_BUILD_ALEMBIC_PLUGIN=OFF')

if context.buildDraco:
extraArgs.append('-DPXR_BUILD_DRACO_PLUGIN=ON')
else:
extraArgs.append('-DPXR_BUILD_DRACO_PLUGIN=OFF')

if context.buildMaterialX:
extraArgs.append('-DPXR_BUILD_MATERIALX_PLUGIN=ON')
else:
Expand Down Expand Up @@ -1287,6 +1305,14 @@ def InstallUSD(context, force, buildArgs):
subgroup.add_argument("--no-hdf5", dest="enable_hdf5", action="store_false",
help="Disable HDF5 support in the Alembic plugin (default)")

group = parser.add_argument_group(title="Draco Plugin Options")
subgroup = group.add_mutually_exclusive_group()
subgroup.add_argument("--draco", dest="build_draco", action="store_true",
default=False,
help="Build Draco plugin for USD")
subgroup.add_argument("--no-draco", dest="build_draco", action="store_false",
help="Do not build Draco plugin for USD (default)")

group = parser.add_argument_group(title="MaterialX Plugin Options")
subgroup = group.add_mutually_exclusive_group()
subgroup.add_argument("--materialx", dest="build_materialx", action="store_true",
Expand Down Expand Up @@ -1420,6 +1446,9 @@ def __init__(self, args):
self.buildAlembic = args.build_alembic
self.enableHDF5 = self.buildAlembic and args.enable_hdf5

# - Draco Plugin
self.buildDraco = args.build_draco

# - MaterialX Plugin
self.buildMaterialX = args.build_materialx

Expand Down Expand Up @@ -1481,6 +1510,9 @@ def ForceBuildDependency(self, dep):
requiredDependencies += [HDF5]
requiredDependencies += [OPENEXR, ALEMBIC]

if context.buildDraco:
requiredDependencies += [DRACO]

if context.buildMaterialX:
requiredDependencies += [MATERIALX]

Expand Down Expand Up @@ -1623,6 +1655,7 @@ def ForceBuildDependency(self, dep):
Tests {buildTests}
Alembic Plugin {buildAlembic}
HDF5 support: {enableHDF5}
Draco Plugin {buildDraco}
MaterialX Plugin {buildMaterialX}
Maya Plugin {buildMaya}
Katana Plugin {buildKatana}
Expand Down Expand Up @@ -1669,6 +1702,7 @@ def FormatBuildArguments(buildArgs):
buildDocs=("On" if context.buildDocs else "Off"),
buildTests=("On" if context.buildTests else "Off"),
buildAlembic=("On" if context.buildAlembic else "Off"),
buildDraco=("On" if context.buildDraco else "Off"),
buildMaterialX=("On" if context.buildMaterialX else "Off"),
enableHDF5=("On" if context.enableHDF5 else "Off"),
buildMaya=("On" if context.buildMaya else "Off"),
Expand Down
1 change: 1 addition & 0 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ option(PXR_BUILD_KATANA_PLUGIN "Build usd katana plugin" OFF)
option(PXR_BUILD_MAYA_PLUGIN "Build usd maya plugin" OFF)
option(PXR_BUILD_ALEMBIC_PLUGIN "Build the Alembic plugin for USD" OFF)
option(PXR_BUILD_HOUDINI_PLUGIN "Build the Houdini plugin for USD" OFF)
option(PXR_BUILD_DRACO_PLUGIN "Build the Draco plugin for USD" OFF)
option(PXR_BUILD_MATERIALX_PLUGIN "Build the MaterialX plugin for USD" OFF)
option(PXR_BUILD_DOCUMENTATION "Generate doxygen documentation" OFF)
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
Expand Down
4 changes: 4 additions & 0 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ if (PXR_BUILD_ALEMBIC_PLUGIN)
endif()
endif()

if (PXR_BUILD_DRACO_PLUGIN)
find_package(Draco REQUIRED)
endif()

if (PXR_BUILD_MATERIALX_PLUGIN)
find_package(MaterialX REQUIRED)
endif()
Expand Down
28 changes: 28 additions & 0 deletions cmake/modules/FindDraco.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2019 Pixar
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
# Find Draco Compression Library using DRACO_ROOT as a hint location and
# provides the result by defining variable DRACO_LIBRARY.
#

find_library(DRACO_LIBRARY libdraco.a ${DRACO_ROOT})
3 changes: 3 additions & 0 deletions pxr/usd/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
if (${PXR_BUILD_ALEMBIC_PLUGIN})
add_subdirectory(usdAbc)
endif()
if (${PXR_BUILD_DRACO_PLUGIN})
add_subdirectory(usdDraco)
endif()
if (${PXR_BUILD_MATERIALX_PLUGIN})
add_subdirectory(usdMtlx)
endif()
Expand Down
37 changes: 37 additions & 0 deletions pxr/usd/plugin/usdDraco/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
set(PXR_PREFIX pxr/usd)
set(PXR_PACKAGE usdDraco)

pxr_plugin(${PXR_PACKAGE}
LIBRARIES
tf
gf
sdf
usd
usdGeom
${DRACO_LIBRARY}

INCLUDE_DIRS
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS}

CPPFILES
attributeDescriptor.cpp
exportTranslator.cpp
fileFormat.cpp
importTranslator.cpp
writer.cpp

PYTHON_CPPFILES
moduleDeps.cpp

PYMODULE_CPPFILES
module.cpp
wrapDraco.cpp

PYMODULE_FILES
__init__.py

RESOURCE_FILES
plugInfo.json
)

40 changes: 40 additions & 0 deletions pxr/usd/plugin/usdDraco/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright 2019 Pixar
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#
import _usdDraco
from pxr import Tf
Tf.PrepareModule(_usdDraco, locals())
del Tf

try:
import __DOC
__DOC.Execute(locals())
del __DOC
except Exception:
try:
import __tmpDoc
__tmpDoc.Execute(locals())
del __tmpDoc
except:
pass

125 changes: 125 additions & 0 deletions pxr/usd/plugin/usdDraco/attributeDescriptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//

#include "attributeDescriptor.h"

#include "pxr/pxr.h"
#include "pxr/usd/sdf/types.h"
#include "pxr/usd/usdGeom/tokens.h"


PXR_NAMESPACE_OPEN_SCOPE


const std::string UsdDracoAttributeDescriptor::METADATA_NAME_KEY = "name";

UsdDracoAttributeDescriptor::UsdDracoAttributeDescriptor(
draco::GeometryAttribute::Type attributeType,
TfToken name,
const std::string &metadataName,
draco::DataType dataType,
SdfValueTypeName valueType,
bool isPrimvar,
size_t numComponents) :
attributeType(attributeType),
name(name),
metadataName(metadataName),
dataType(dataType),
valueType(valueType),
isPrimvar(isPrimvar),
numComponents(numComponents) {
}


namespace attributedescriptor {

UsdDracoAttributeDescriptor ForPositions() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::POSITION,
UsdGeomTokens->points,
"", /* metadataName */
draco::DT_FLOAT32,
SdfValueTypeNames->Float3Array,
false, /* isPrimvar */
3 /* numComponents */);
}

UsdDracoAttributeDescriptor ForTexCoords() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::TEX_COORD,
TfToken("Texture_uv"),
"", /* metadataName */
draco::DT_FLOAT32,
SdfValueTypeNames->Float2Array,
true, /* isPrimvar */
2 /* numComponents */);
}

UsdDracoAttributeDescriptor ForNormals() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::NORMAL,
UsdGeomTokens->normals,
"", /* metadataName */
draco::DT_FLOAT32,
SdfValueTypeNames->Float3Array,
true, /* isPrimvar */
3 /* numComponents */);
}

UsdDracoAttributeDescriptor ForHoleFaces() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::GENERIC,
TfToken(),
"hole_faces",
draco::DT_UINT8,
SdfValueTypeName(),
false, /* isPrimvar */
1 /* numComponents */);
}

UsdDracoAttributeDescriptor ForAddedEdges() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::GENERIC,
TfToken(),
"added_edges",
draco::DT_UINT8,
SdfValueTypeName(),
false, /* isPrimvar */
1 /* numComponents */);
}

UsdDracoAttributeDescriptor ForPosOrder() {
return UsdDracoAttributeDescriptor(
draco::GeometryAttribute::GENERIC,
TfToken(),
"point_order",
draco::DT_UINT32,
SdfValueTypeName(),
false, /* isPrimvar */
1 /* numComponents */);
}

} // namespace attributedescriptor

PXR_NAMESPACE_CLOSE_SCOPE
Loading

0 comments on commit 1e99f83

Please sign in to comment.