HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
APEXA_SceneInvoke.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  */
6 
7 #ifndef __APEXA_SCENE_INVOKE_H__
8 #define __APEXA_SCENE_INVOKE_H__
9 
10 #include "APEXA_API.h"
11 
12 #include "APEXA_SceneUtils.h"
13 
14 #include <APEX/APEX_COW.h>
15 #include <APEX/APEX_ParmDict.h>
16 #include <GU/GU_OnionSkin.h>
17 #include <UT/UT_Optional.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <UT/UT_StringHolder.h>
20 #include <UT/UT_StringSet.h>
21 #include <SYS/SYS_Types.h>
22 
23 class APEXA_Scene;
24 class GU_Detail;
25 
27 {
28 public:
30  {
31  Output() = default;
34  const UT_StringRef &pattern = "*",
35  bool copies_geo=false);
36 
37  void clearCachedResult();
38 
40  const GU_CommonOnionSkinOptions &onion_skin_opts) const
41  {
42  if (!myOnionSkinOptions)
43  return 0;
44  return myOnionSkinOptions->getNumOnionSkins(onion_skin_opts);
45  }
46 
50 
53 
55 
56  bool myCopiesGeoFlag = false;
57  };
58 
59  APEXA_SceneInvoke(bool reuse_cached_scene=false);
61 
63 
64  /// Update the source geometry for the scene.
65  /// Returns true if the scene was reloaded. The outputs are also cleared if the scene changed.
66  bool updateSourceGeometry(
67  const GU_Detail &detail,
69  bool preload_animation_clips=false);
70 
71  /// Clear the outputs.
72  void clearOutputs();
73 
74  /// Returns the registered outputs, with their evaluated results if evaluateOutput() has been called.
75  const UT_Array<Output> &getOutputs() const { return myOutputs; }
76 
77  /// Registers a specific output for evaluation, and returns its index into getOutputs().
78  /// @param copies_geo If enabled, a replaceWith call will be run the copies any
79  /// geometries out of the scene instead of grabbing the detail handle. This can
80  /// improve the efficiency of the APEX graph when the output geometry receives preserve
81  /// requests.
82  /// @param track_output If enabled, the output will be tracked and can be evaluated
83  /// in parallel.
84  exint addOutput(const UT_StringHolder &path,
86  bool copies_geo = false,
87  bool track_output = false);
88 
89  /// Adds the default output shapes for each character to the list of outputs that can be evaluated.
90  /// @param track_outputs If true, all character shape outputs will be tracked and can be
91  /// evaluated in parallel.
92  void addCharacterShapeOutputs(bool track_outputs=false);
93 
94  /// Returns the default output shapes for each character. This can be used instead of
95  /// addCharacterShapeOutputs() if additional processing / validation is needed before
96  /// registering outputs.
97  /// @param include_invisible_chars If enabled, includes characters which are currently hidden in
98  /// the selection sets.
99  UT_Array<Output> findCharacterShapeOutputs(
100  bool include_invisible_chars = false) const;
101 
102  /// Returns the named geometry outputs for each character.
103  /// @param output_name
104  /// @param include_invisible_chars If enabled, includes characters which
105  /// are currently hidden in the selection sets.
106  UT_Array<Output> findCharacterGeometryOutputs(
107  const UT_StringHolder &output_name,
108  bool include_invisible_chars = false) const;
109 
110  /// Returns a list of the available output paths in the scene,
111  /// e.g. /electra.char/Base.rig/output
112  UT_StringArray findOutputPaths() const;
113 
114  /// Analyzes the graph to determine if the output shape is only deformed by a bonedeform SOP.
115  /// If successful, returns the paths which should be evaluated to obtain the rest geometry, rest
116  /// skeleton, and animated skeleton.
117  /// This assumes that the rest_shape and rest_skel are connected directly to an input from the bonedeform.
118  bool findSkinningInputsForShape(
119  const Output &deform_shape_output,
120  Output &rest_shape_output,
121  Output &rest_skel_output,
122  Output &anim_skel_output) const;
123 
124  /// Analyzes the graph to determine if the output shape is only deformed by a bonedeform SOP.
125  /// If successful, returns the path for the animated skeleton.
126  /// This can succeed even when the rest_skel and rest_shape aren't connected directly to an input from the bonedeform.
127  bool findAnimSkelInputForShape(
128  const Output &deform_shape_output,
129  Output &anim_skel_output) const;
130 
131  /// Update the scene to the specified time, clearing any cached output results.
132  /// @param evaluate_tracked_outputs If true, the tracked outputs will be
133  /// evaluated in parallel.
134  void updateEvaluationTime(
135  apex::Float frame,
136  bool evaluate_tracked_ouputs = true);
137 
138  /// Evaluate the specified output at the scene's current time. Returns false if any errors occurred.
139  bool evaluateOutput(exint output_idx, UT_StringHolder &error);
140 
141  /// Set the active animation clip.
142  /// @param clip_path Path to the clip to activate or empty string to use
143  /// the default one from the scene..
144  /// @param error Outputs any error messages if the active clip could not be set.
145  /// @return true if successful, false otherwise
146  bool setActiveClip(const UT_StringHolder &clip_path, UT_StringHolder &error);
147 
148  /// Returns the resolved active clip path on the scene.
149  UT_StringHolder getActiveClipPath() const;
150 
151  /// Returns a list of the available clips in the scene.
152  UT_StringArray getClipPaths() const;
153 
154  /// Override a character geometry input with a new geometry.
155  /// This can be used to inject external animated geometries.
156  /// Call updateEvaluationTime() to force a refresh().
157  bool setCharacterGeoInput(
158  const UT_StringHolder &character_path,
159  const UT_StringHolder &geo_name,
160  const GU_ConstDetailHandle &geo);
161 
162  /// Sets the animation cache mode
163  void setAnimationCachingMode(APEXA_AnimationCachingMode mode);
164 
165  /// Returns the animation caching mode
166  APEXA_AnimationCachingMode animationCachingMode() const { return myAnimationCachingMode; }
167 
168  APEXA_Scene *getScene() { return myScene.get(); }
169 
170  /// Returns whether the name of a packed primitive is likely an item in a packed character
171  /// scene, e.g. "*.char"
172  /// This can be used to identify geometry that should be interpreted as a character scene.
173  static bool isCharacterSceneItemName(const UT_StringRef &name);
174 
175  /// Returns whether there are any channel primitives in the scene. This can be used to only load
176  /// / evaluate the scene when animation is present.
177  static bool hasAnimation(const GU_ConstDetailHandle &scene_gdh);
178 
179 private:
180  /// Load visibility information from selection sets.
181  void loadSelectionSetVisibility(const GU_Detail &detail);
182  /// Returns whether the rig is associated with a visible character.
183  bool isRigVisible(const UT_StringView &rig_path) const;
184 
185 private:
186  /// The APEX Scene object
188 
189  /// Whether to attempt to reuse a scene in the animation cache
190  bool myReuseCachedScene;
191 
192  int64 myDetailId = -1;
193  int64 myMetaCacheCount = -1;
194 
195  /// Invisible characters from the selection sets.
196  UT_StringSet myInvisibleChars;
198 
199  UT_Array<Output> myOutputs;
200 };
201 
202 #endif
UT_Optional< GU_OnionSkinOptions > myOnionSkinOptions
const UT_Array< Output > & getOutputs() const
Returns the registered outputs, with their evaluated results if evaluateOutput() has been called...
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
int64 exint
Definition: SYS_Types.h:125
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
< returns > If no error
Definition: snippets.dox:2
UT_Optional< apex::Dict > myDict
A utility class to do read-only operations on a subset of an existing string.
Definition: UT_StringView.h:40
APEXA_AnimationCachingMode animationCachingMode() const
Returns the animation caching mode.
#define APEXA_API
Definition: APEXA_API.h:21
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
double Float
Definition: APEX_Include.h:62
UT_Optional< apex::ApexGeometry > myGeometry
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLushort pattern
Definition: glad.h:2583
APEXA_AnimationCachingMode
GLenum mode
Definition: glcorearb.h:99
UT_Optional< UT_StringHolder > myKey
exint getNumOnionSkins(const GU_CommonOnionSkinOptions &onion_skin_opts) const
APEXA_Scene * getScene()