Skip to content

Commit

Permalink
Merge pull request #48 from iaiotom/atoms4
Browse files Browse the repository at this point in the history
Atoms 4.0
  • Loading branch information
andrewkaufman authored Sep 23, 2021
2 parents a873c47 + f4160ff commit 6366847
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 131 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.0)
project(AtomsGaffer)

option( USE_GAFFER_DEPENDENCIES "Turn this off you're building against your own dependencies (eg boost, python, tbb, exr, cortex) rather than the versions included with Gaffer" ON )
option( USE_ATOMS_PROCEDURAL "Turn this off you plan to load AtomsGaffer in maya or another environment that requires a full atoms license" ON )

set(CMAKE_VERBOSE_MAKEFILE ON)

Expand Down Expand Up @@ -40,21 +39,17 @@ set(DEPENDENCY_INCLUDE_PATHS
file( GLOB AtomsGafferSrc src/AtomsGaffer/*.cpp )
link_directories( AtomsGaffer ${GAFFER_ROOT}/lib ${ATOMS_LIB_PATH} )
add_library( AtomsGaffer SHARED ${AtomsGafferSrc} )
target_compile_definitions( AtomsGaffer PRIVATE BOOST_SIGNALS_NO_DEPRECATION_WARNING=1 LINUX=1 )
target_compile_definitions( AtomsGaffer PRIVATE BOOST_SIGNALS_NO_DEPRECATION_WARNING=1 LINUX=1 _GLIBCXX_USE_CXX11_ABI=0)
target_include_directories( AtomsGaffer SYSTEM PRIVATE ${DEPENDENCY_INCLUDE_PATHS} )
target_include_directories( AtomsGaffer PRIVATE include )
if(USE_ATOMS_PROCEDURAL)
target_link_libraries( AtomsGaffer Gaffer GafferScene AtomsProcedural )
else()
target_link_libraries( AtomsGaffer Gaffer GafferScene AtomsCore AtomsGraph Atoms AtomsUtils )
endif()
target_link_libraries( AtomsGaffer Gaffer GafferScene AtomsCore AtomsGraph Atoms AtomsUtils )
install( TARGETS AtomsGaffer DESTINATION lib )

# build the python bindings
file( GLOB AtomsGafferModuleSrc src/AtomsGafferModule/*.cpp )
add_library( AtomsGafferModule SHARED ${AtomsGafferModuleSrc} )
set_target_properties( AtomsGafferModule PROPERTIES PREFIX "" OUTPUT_NAME "_AtomsGaffer" )
target_compile_definitions( AtomsGafferModule PRIVATE BOOST_SIGNALS_NO_DEPRECATION_WARNING=1 LINUX=1 )
target_compile_definitions( AtomsGafferModule PRIVATE BOOST_SIGNALS_NO_DEPRECATION_WARNING=1 LINUX=1 _GLIBCXX_USE_CXX11_ABI=0)
target_link_libraries( AtomsGafferModule AtomsGaffer )
target_include_directories( AtomsGafferModule SYSTEM PRIVATE ${DEPENDENCY_INCLUDE_PATHS} ${PYTHON_ROOT}/include/python2.7 )
target_include_directories( AtomsGafferModule PRIVATE include )
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setenv ATOMS_ROOT <atoms install path>
setenv ATOMSGAFFER_INSTALL_PREFIX <your desired install path>
cd atomsGaffer
cmake -DGAFFER_ROOT=$GAFFER_ROOT -DATOMS_ROOT=$ATOMS_ROOT -DCMAKE_CXX_FLAGS='-std=c++11' -DCMAKE_INSTALL_PREFIX=$ATOMSGAFFER_INSTALL_PREFIX .
cmake -DGAFFER_ROOT=$GAFFER_ROOT -DATOMS_ROOT=$ATOMS_ROOT -DCMAKE_CXX_FLAGS='-std=c++14' -DCMAKE_INSTALL_PREFIX=$ATOMSGAFFER_INSTALL_PREFIX .
make install -j <num cores>)
```

Expand Down
116 changes: 36 additions & 80 deletions examples/scripts/atomsExampleScene.gfr

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion include/AtomsGaffer/AtomsCrowdGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AtomsCrowdGenerator : public GafferScene::BranchCreator
AtomsCrowdGenerator( const std::string &name = defaultName<AtomsCrowdGenerator>() );
~AtomsCrowdGenerator() = default;

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( AtomsGaffer::AtomsCrowdGenerator, TypeId::AtomsCrowdGeneratorTypeId, GafferScene::BranchCreator );
GAFFER_NODE_DECLARE_TYPE( AtomsGaffer::AtomsCrowdGenerator, TypeId::AtomsCrowdGeneratorTypeId, GafferScene::BranchCreator );

Gaffer::StringPlug *namePlug();
const Gaffer::StringPlug *namePlug() const;
Expand Down
192 changes: 192 additions & 0 deletions include/AtomsGaffer/AtomsMathTranaslator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2018, Toolchefs Ltd. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef ATOMSGAFFER_ATOMSMATHTRNASLATOR_H
#define ATOMSGAFFER_ATOMSMATHTRNASLATOR_H

#include "AtomsCore/AtomsMath.h"

#include "ImathVec.h"
#include "ImathQuat.h"
#include "ImathBox.h"
#include "ImathMatrix.h"

template<typename T, typename Y>
inline void convertFromAtoms( T& out, const Y& in )
{
out = in;
}

template<>
inline void convertFromAtoms( Imath::V2d& out, const AtomsCore::Vector2& in )
{
out.x = in.x;
out.y = in.y;
}

template<>
inline void convertFromAtoms( Imath::V2f& out, const AtomsCore::Vector2f& in )
{
out.x = in.x;
out.y = in.y;
}

template<>
inline void convertFromAtoms( Imath::V2f& out, const AtomsCore::Vector2& in )
{
out.x = static_cast<float>( in.x );
out.y = static_cast<float>( in.y );
}

template<>
inline void convertFromAtoms( Imath::V3d& out, const AtomsCore::Vector3& in )
{
out.x = in.x;
out.y = in.y;
out.z = in.z;
}

template<>
inline void convertFromAtoms( Imath::V3f& out, const AtomsCore::Vector3f& in )
{
out.x = in.x;
out.y = in.y;
out.z = in.z;
}

template<>
inline void convertFromAtoms( Imath::V3f& out, const AtomsCore::Vector3& in )
{
out.x = static_cast<float>( in.x );
out.y = static_cast<float>( in.y );
out.z = static_cast<float>( in.z );
}

template<>
inline void convertFromAtoms( Imath::Quatd& out, const AtomsCore::Quaternion& in )
{
convertFromAtoms(out.v, in.v);
out.r = in.r;
}

template<>
inline void convertFromAtoms( Imath::Quatf& out, const AtomsCore::Quaternionf& in )
{
convertFromAtoms(out.v, in.v);
out.r = in.r;
}

template<>
inline void convertFromAtoms( Imath::Quatf& out, const AtomsCore::Quaternion& in )
{
convertFromAtoms(out.v, in.v);
out.r = static_cast<float>( in.r );
}

template<>
inline void convertFromAtoms( Imath::M44d& out, const AtomsCore::Matrix& in )
{
for ( unsigned short i = 0; i < 4; ++i )
{
for ( unsigned short j = 0; j < 4; ++j )
{
out[i][j] = in[i][j];
}
}
}

template<>
inline void convertFromAtoms( Imath::M44f& out, const AtomsCore::Matrixf& in )
{
for ( unsigned short i = 0; i < 4; ++i )
{
for ( unsigned short j = 0; j < 4; ++j )
{
out[i][j] = in[i][j];
}
}
}

template<>
inline void convertFromAtoms( Imath::M44f& out, const AtomsCore::Matrix& in )
{
for ( unsigned short i = 0; i < 4; ++i )
{
for ( unsigned short j = 0; j < 4; ++j )
{
out[i][j] = static_cast<float>( in[i][j] );
}
}
}

template<>
inline void convertFromAtoms( Imath::Box3d& out, const AtomsCore::Box3& in )
{
convertFromAtoms(out.min, in.min);
convertFromAtoms(out.max, in.max);
}

template<>
inline void convertFromAtoms( Imath::Box3f& out, const AtomsCore::Box3f& in )
{
convertFromAtoms(out.min, in.min);
convertFromAtoms(out.max, in.max);
}

template<>
inline void convertFromAtoms( Imath::Box3f& out, const AtomsCore::Box3& in )
{
convertFromAtoms(out.min, in.min);
convertFromAtoms(out.max, in.max);
}

///////////
// vectors
///////////

template<typename T, typename Y>
inline void convertFromAtoms( std::vector<T>& out, const std::vector<Y>& in )
{
size_t startIndex = out.size();
out.resize( out.size() + in.size() );
for ( size_t i = 0; i < in.size(); ++i)
{
convertFromAtoms( out[startIndex + i], in[i] );
}
}


#endif //ATOMSGAFFER_ATOMSMATHTRNASLATOR_H
12 changes: 10 additions & 2 deletions src/AtomsGaffer/AtomsCrowdClothReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
//////////////////////////////////////////////////////////////////////////

#include "AtomsGaffer/AtomsCrowdClothReader.h"
#include "AtomsGaffer/AtomsMathTranaslator.h"

#include "IECoreScene/PointsPrimitive.h"

Expand Down Expand Up @@ -214,8 +215,15 @@ ConstObjectPtr AtomsCrowdClothReader::computeObject( const ScenePath &path, cons
Box3dDataPtr bbox = new Box3dData;
StringDataPtr stackOrder = new StringData;

cache.loadAgentClothMesh( frame, agentId, meshName, p->writable(), n->writable() );
cache.loadAgentClothMeshBoundingBox( frame, agentId, meshName, bbox->writable() );
std::vector<AtomsCore::Vector3> clothPoints, clothNormals;
AtomsCore::Box3 clothBound;
cache.loadAgentClothMesh( frame, agentId, meshName, clothPoints, clothNormals );
cache.loadAgentClothMeshBoundingBox( frame, agentId, meshName, clothBound );

convertFromAtoms( p->writable(), clothPoints );
convertFromAtoms( n->writable(), clothNormals );
convertFromAtoms( bbox->writable(), clothBound );

stackOrder->writable() = cache.getAgentClothMeshStackOrder( frame, agentId, meshName );
meshData[ "P" ] = p;
meshData[ "N" ] = n;
Expand Down
25 changes: 16 additions & 9 deletions src/AtomsGaffer/AtomsCrowdReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "AtomsGaffer/AtomsCrowdReader.h"
#include "AtomsGaffer/AtomsMetadataTranslator.h"
#include "AtomsGaffer/AtomsMathTranaslator.h"

#include "IECoreScene/PointsPrimitive.h"

Expand Down Expand Up @@ -604,14 +605,15 @@ ConstObjectPtr AtomsCrowdReader::computeSource( const Gaffer::Context *context )
if ( !matrices.empty() )
{
auto& pelvisMtx = matrices[0];
positions[i] = pelvisMtx.translation();
rootMatrix[i] = Imath::M44f( pelvisMtx );
orientation[i] = Imath::extractQuat( pelvisMtx );
auto pelvisPosition = pelvisMtx.translation();
convertFromAtoms( positions[i], pelvisPosition );
convertFromAtoms( rootMatrix[i], pelvisMtx );
convertFromAtoms( orientation[i], AtomsMath::extractQuat( pelvisMtx ) );
}
}
else
{
positions[i] = pose.jointPose( 0 ).translation;
convertFromAtoms( positions[i], pose.jointPose( 0 ).translation );
}
}
}
Expand Down Expand Up @@ -662,7 +664,9 @@ IECore::ConstCompoundObjectPtr AtomsCrowdReader::computeAttributes( const SceneN
auto& translator = AtomsMetadataTranslator::instance();

Box3dDataPtr cacheBox = new Box3dData;
atomsCache.loadBoundingBox( frame, cacheBox->writable() );
AtomsCore::Box3 atomsCacheBox;
atomsCache.loadBoundingBox( frame, atomsCacheBox );
convertFromAtoms( cacheBox->writable(), atomsCacheBox );
//members["atoms:boundingBox"] = cacheBox;

IntVectorDataPtr agentIndices = new IntVectorData;
Expand Down Expand Up @@ -708,7 +712,7 @@ IECore::ConstCompoundObjectPtr AtomsCrowdReader::computeAttributes( const SceneN

auto& outMatrices = matricesData->writable();
auto& outNormalMatrices = normalMatricesData->writable();
outMatrices = poser.getAllWorldMatrix( posePtr->get() );
convertFromAtoms( outMatrices, poser.getAllWorldMatrix( posePtr->get() ) );
outNormalMatrices.resize( outMatrices.size() );

//update the position metadata
Expand All @@ -730,16 +734,19 @@ IECore::ConstCompoundObjectPtr AtomsCrowdReader::computeAttributes( const SceneN
// Store the matrices for the skinning
for ( unsigned int j = 0; j < outMatrices.size(); j++ )
{
AtomsCore::Matrix &jMtx = outMatrices[j];
auto &jMtx = outMatrices[j];
agentBBoxData.extendBy(jMtx.translation());
jMtx = bindPosesInv[j] * jMtx;
Imath::M44d bindInverseMatrix;
convertFromAtoms( bindInverseMatrix, bindPosesInv[j] );
jMtx = bindInverseMatrix * jMtx;
outNormalMatrices[j] = jMtx.inverse().transpose();
}

agentCompound["poseWorldMatrices"] = matricesData;
agentCompound["poseNormalWorldMatrices"] = normalMatricesData;

M44dDataPtr rootMatrixData = new M44dData( rootMatrix );
M44dDataPtr rootMatrixData = new M44dData( );
convertFromAtoms( rootMatrixData->writable(), rootMatrix );
agentCompound["rootMatrix"] = rootMatrixData;

// This is an hash of the agent pose in local space
Expand Down
Loading

0 comments on commit 6366847

Please sign in to comment.