Skip to content

Commit 6057026

Browse files
committed
Merge pull request #261 from ldmoser/nukeSceneReaderFix2
Fixing and revamping SceneCacheReader for Nuke
2 parents 29ab467 + 9f922a6 commit 6057026

16 files changed

+614
-300
lines changed

include/IECoreNuke/SceneCacheReader.h

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////
22
//
3-
// Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
3+
// Copyright (c) 2013-2014, Image Engine Design Inc. All rights reserved.
44
//
55
// Redistribution and use in source and binary forms, with or without
66
// modification, are permitted provided that the following conditions are
@@ -94,9 +94,9 @@ class SceneCacheReader : public DD::Image::SourceGeo
9494
// Returns the name of the item at index itemIndex in the SceneView_knob.
9595
const std::string &itemName( int itemIndex ) const;
9696
// Returns a SceneInterface for the root item.
97-
IECore::ConstSceneInterfacePtr getSceneInterface() const;
97+
IECore::ConstSceneInterfacePtr getSceneInterface();
9898
// Returns a SceneInterface for the item at path.
99-
IECore::ConstSceneInterfacePtr getSceneInterface( const std::string &path ) const;
99+
IECore::ConstSceneInterfacePtr getSceneInterface( const std::string &path );
100100
//@}
101101

102102
//! @name Methods which control the SceneView_knob
@@ -116,19 +116,12 @@ class SceneCacheReader : public DD::Image::SourceGeo
116116
/// is rebuilt then the selection will be lost. The filterScene() method must
117117
/// be called immediately afterwards.
118118
void rebuildSceneView();
119-
/// This recursive method is called from rebuildSceneView() and traverses the
120-
/// sceneInterface to build a list of item names and a mapping of the tags to
121-
/// the indices in the items.
122-
void buildSceneView( std::vector< std::string > &list, const IECore::ConstSceneInterfacePtr sceneInterface );
123119
/// Rebuilds the sceneView to show only items which are already selected or have
124-
/// a names that matches filterText and a tag which matches tagText.
120+
/// names that matches filterText and a tag which matches tagText.
125121
/// Passing an empty string to either filterText or tagText will disable the
126122
/// filtering of the names and tags respectively. This should be called
127123
/// immediately after any call to rebuildSceneView().
128-
void filterScene( const std::string &filterText, const std::string &tagText );
129-
/// Rebuilds the current geometry selection from the entries that are selected
130-
/// in the SceneView_knob.
131-
void rebuildSelection();
124+
void filterScene( const std::string &filterText, const std::string &tagText, bool keepSelection = true );
132125
/// Clear any selected geometry from the SceneView_knob.
133126
void clearSceneViewSelection();
134127
//@}
@@ -140,45 +133,28 @@ class SceneCacheReader : public DD::Image::SourceGeo
140133
void loadPrimitive( DD::Image::GeometryList &out, const std::string &path );
141134
/// Get the hash of the file path and root knob.
142135
DD::Image::Hash sceneHash() const;
143-
/// Evaluates the file path for the current context and returns the result.
144-
std::string filePath() const;
136+
/// Get the hash of the SceneView knob (the default hash implementation of that knob returns a constant hash...)
137+
DD::Image::Hash selectionHash( bool force = false ) const;
145138

146139
Imath::M44d worldTransform( IECore::ConstSceneInterfacePtr scene, IECore::SceneInterface::Path root, double time );
147140

148141
// uses firstOp to return the Op that has the up-to-date private data
149142
SceneCacheReader *firstReader();
150-
151-
/// Returns an InternedString with the name of the geometry tag.
152-
static const IECore::InternedString &geometryTag();
143+
const SceneCacheReader *firstReader() const;
144+
145+
class SharedData;
146+
147+
// this function should only be called from the firstReader() object.
148+
SharedData *sharedData();
149+
const SharedData *sharedData() const;
153150

154151
// Knob Members.
155152
const char *m_filePath; // Holds the raw SceneCache file path.
156-
std::string m_evaluatedFilePath; // Holds the SceneCache file path after any TCL scripts have been evaluated..
157153
std::string m_root; // Holds the root item in the SceneCache.
158-
std::string m_filterText; // The text to filter the scene with.
159-
std::string m_filterTagText; // The text to filter the tags with. This is set from the Enumeration_knob.
154+
std::string m_filter; // The text to filter the scene with.
160155
bool m_worldSpace; // Set to ignore local transforms..
161156
DD::Image::Matrix4 m_baseParentMatrix; // The global matrix that is applied to the geo.
162-
163-
// Hashes that are used to both provide an early-out to some methods
164-
// and also contribute towards a hash for the geometry.
165-
DD::Image::Hash m_selectionHash;
166-
DD::Image::Hash m_filterHash;
167-
DD::Image::Hash m_sceneHash;
168-
169-
// When buildSceneView is called to parse the scene cache and generate a list of entries for the SceneView_knob,
170-
// this map is also populated. It holds a mapping of tag names to the indices of items which have that tag.
171-
// It is used within the filterScene method to quickly filter items with a particular tag.
172-
typedef std::map< std::string, std::vector< unsigned int > > TagMap;
173-
TagMap m_tagMap;
174-
175-
// When specifying a root we store the path to it's parent item along with the length of it. We do this so that when
176-
// we are building the list of items in the SceneView_knob we can strip this path quickly from the front of the
177-
// name and easily restore it later to load it from the SceneCache. This ensures that the names of the items in the
178-
// SceneView_knob are kept short.
179-
std::string m_pathPrefix;
180-
unsigned int m_pathPrefixLength;
181-
157+
182158
// Pointers to various knobs.
183159
DD::Image::Knob *m_filePathKnob;
184160
DD::Image::Knob *m_baseParentMatrixKnob;
@@ -187,19 +163,8 @@ class SceneCacheReader : public DD::Image::SourceGeo
187163
DD::Image::Knob *m_sceneFilterKnob;
188164
DD::Image::Knob *m_rootKnob;
189165

190-
// A flag which is set when all of the knobs have been loaded from the script.
191-
bool m_scriptFinishedLoading;
192-
193-
// A flag which is used to initialize the internal data structures the first time the node is run.
194-
bool m_isFirstRun;
195-
196-
/// The SceneView_knob holds a list of all leaf items in the scene. When filtering the SceneView we specify indices into
197-
/// this list. When setting or querying the selected items in the SceneView_knob we need to use indices into the list of
198-
/// filtered (visible) items. This means that we have to keep a look-up table of mappings between indices in the filtered
199-
/// list of items and the index within the complete list of items in the scene.
200-
std::map<int, int> m_itemToFiltered; // Mapping of the index within the full scene list and the filtered scene list.
201-
std::vector<unsigned int> m_filteredToItem; // Mapping from an index in the filtered scene list to the complete scene list.
202-
std::vector< bool > m_itemSelected; // An array of flags which indicate whether an item in the filtered list is selected or not.
166+
// only the first reader allocates the shared data
167+
SharedData *m_data;
203168
};
204169

205170
} // namespace IECoreNuke

0 commit comments

Comments
 (0)