|
| 1 | +////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright (c) 2022, Image Engine Design Inc. All rights reserved. |
| 4 | +// |
| 5 | +// Redistribution and use in source and binary forms, with or without |
| 6 | +// modification, are permitted provided that the following conditions are |
| 7 | +// met: |
| 8 | +// |
| 9 | +// * Redistributions of source code must retain the above copyright |
| 10 | +// notice, this list of conditions and the following disclaimer. |
| 11 | +// |
| 12 | +// * Redistributions in binary form must reproduce the above copyright |
| 13 | +// notice, this list of conditions and the following disclaimer in the |
| 14 | +// documentation and/or other materials provided with the distribution. |
| 15 | +// |
| 16 | +// * Neither the name of Image Engine Design nor the names of any |
| 17 | +// other contributors to this software may be used to endorse or |
| 18 | +// promote products derived from this software without specific prior |
| 19 | +// written permission. |
| 20 | +// |
| 21 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 22 | +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 23 | +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 | +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 25 | +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 26 | +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 | +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 | +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 | +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | +// |
| 33 | +////////////////////////////////////////////////////////////////////////// |
| 34 | + |
| 35 | +#ifndef IECORENUKE_LIVESCENE_H |
| 36 | +#define IECORENUKE_LIVESCENE_H |
| 37 | + |
| 38 | +#include "DDImage/GeoOp.h" |
| 39 | +#include "DDImage/GeometryList.h" |
| 40 | + |
| 41 | +#include "IECore/PathMatcher.h" |
| 42 | + |
| 43 | +#include "IECoreScene/SceneInterface.h" |
| 44 | + |
| 45 | +#include "IECoreNuke/Export.h" |
| 46 | +#include "IECoreNuke/TypeIds.h" |
| 47 | + |
| 48 | +namespace IECoreNuke |
| 49 | +{ |
| 50 | + |
| 51 | +IE_CORE_FORWARDDECLARE( LiveScene ); |
| 52 | + |
| 53 | +/// A read-only class for representing a live Nuke scene as an IECore::SceneInterface |
| 54 | +class IECORENUKE_API LiveScene : public IECoreScene::SceneInterface |
| 55 | +{ |
| 56 | + public : |
| 57 | + |
| 58 | + static const std::string& nameAttribute; |
| 59 | + |
| 60 | + IE_CORE_DECLARERUNTIMETYPEDEXTENSION( LiveScene, LiveSceneTypeId, IECoreScene::SceneInterface ); |
| 61 | + |
| 62 | + LiveScene(); |
| 63 | + LiveScene( DD::Image::GeoOp *op, const std::string rootPath="/" ); |
| 64 | + |
| 65 | + ~LiveScene() override; |
| 66 | + |
| 67 | + std::string fileName() const override; |
| 68 | + |
| 69 | + Name name() const override; |
| 70 | + void path( Path &p ) const override; |
| 71 | + |
| 72 | + Imath::Box3d readBound( double time ) const override; |
| 73 | + void writeBound( const Imath::Box3d &bound, double time ); |
| 74 | + |
| 75 | + IECore::ConstDataPtr readTransform( double time ) const override; |
| 76 | + Imath::M44d readTransformAsMatrix( double time ) const override; |
| 77 | + IECore::ConstDataPtr readWorldTransform( double time ) const; |
| 78 | + Imath::M44d readWorldTransformAsMatrix( double time ) const; |
| 79 | + void writeTransform( const IECore::Data *transform, double time ) override; |
| 80 | + |
| 81 | + bool hasAttribute( const Name &name ) const override; |
| 82 | + void attributeNames( NameList &attrs ) const override; |
| 83 | + IECore::ConstObjectPtr readAttribute( const Name &name, double time ) const override; |
| 84 | + void writeAttribute( const Name &name, const IECore::Object *attribute, double time ) override; |
| 85 | + |
| 86 | + bool hasTag( const Name &name, int filter = SceneInterface::LocalTag ) const override; |
| 87 | + void readTags( NameList &tags, int filter = SceneInterface::LocalTag ) const override; |
| 88 | + void writeTags( const NameList &tags ) override; |
| 89 | + |
| 90 | + NameList setNames( bool includeDescendantSets = true ) const override; |
| 91 | + IECore::PathMatcher readSet( const Name &name, bool includeDescendantSets = true, const IECore::Canceller *canceller = nullptr ) const override; |
| 92 | + void writeSet( const Name &name, const IECore::PathMatcher &set ) override; |
| 93 | + void hashSet( const Name& setName, IECore::MurmurHash &h ) const override; |
| 94 | + |
| 95 | + bool hasObject() const override; |
| 96 | + IECore::ConstObjectPtr readObject( double time, const IECore::Canceller *canceller = nullptr ) const override; |
| 97 | + IECoreScene::PrimitiveVariableMap readObjectPrimitiveVariables( const std::vector<IECore::InternedString> &primVarNames, double time ) const override; |
| 98 | + void writeObject( const IECore::Object *object, double time ) override; |
| 99 | + |
| 100 | + void childNames( NameList &childNames ) const override; |
| 101 | + bool hasChild( const Name &name ) const override; |
| 102 | + IECoreScene::SceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) override; |
| 103 | + IECoreScene::ConstSceneInterfacePtr child( const Name &name, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const override; |
| 104 | + IECoreScene::SceneInterfacePtr createChild( const Name &name ) override; |
| 105 | + |
| 106 | + IECoreScene::SceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) override; |
| 107 | + IECoreScene::ConstSceneInterfacePtr scene( const Path &path, MissingBehaviour missingBehaviour = SceneInterface::ThrowIfMissing ) const override; |
| 108 | + |
| 109 | + void hash( HashType hashType, double time, IECore::MurmurHash &h ) const override; |
| 110 | + |
| 111 | + static double timeToFrame( const double& time ); |
| 112 | + static double frameToTime( const int& frame ); |
| 113 | + |
| 114 | + private: |
| 115 | + |
| 116 | + DD::Image::GeoOp *op() const; |
| 117 | + DD::Image::GeometryList geometryList( const double* time=nullptr ) const; |
| 118 | + |
| 119 | + std::string geoInfoPath( const int& index ) const; |
| 120 | + |
| 121 | + DD::Image::GeoOp *m_op; |
| 122 | + std::string m_rootPath; |
| 123 | + IECore::PathMatcher m_pathMatcher; |
| 124 | + typedef std::map<unsigned, std::string> objectPathMap; |
| 125 | + mutable objectPathMap m_objectPathMap; |
| 126 | +}; |
| 127 | + |
| 128 | +IE_CORE_DECLAREPTR( LiveScene ); |
| 129 | + |
| 130 | +} // namespace IECoreNuke |
| 131 | + |
| 132 | +#endif // IECORENUKE_LIVESCENE_H |
0 commit comments