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 <APEX/APEX_COW.h>
13 #include <APEX/APEX_ParmDict.h>
14 #include <UT/UT_Optional.h>
15 #include <UT/UT_UniquePtr.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_StringSet.h>
18 #include <SYS/SYS_Types.h>
19 
20 class APEXA_Scene;
21 class GU_Detail;
22 
24 {
25 public:
27  {
28  Output() = default;
32  bool copies_geo=false);
33 
34  void clearCachedResult();
35 
39 
42 
43  bool myCopiesGeoFlag = false;
44  };
45 
48 
50 
51  /// Update the source geometry for the scene.
52  /// Returns true if the scene was reloaded. The outputs are also cleared if the scene changed.
53  bool updateSourceGeometry(
54  const GU_Detail &detail,
56  bool preload_animation_clips=false);
57 
58  /// Clear the outputs.
59  void clearOutputs();
60 
61  /// Returns the registered outputs, with their evaluated results if evaluateOutput() has been called.
62  const UT_Array<Output> &getOutputs() const { return myOutputs; }
63 
64  /// Registers a specific output for evaluation, and returns its index into getOutputs().
65  /// @param copies_geo If enabled, a replaceWith call will be run the copies any
66  /// geometries out of the scene instead of grabbing the detail handle. This can
67  /// improve the efficiency of the APEX graph when the output geometry receives preserve
68  /// requests.
69  exint addOutput(const UT_StringHolder &path,
71  bool copies_geo = false);
72 
73  /// Adds the default output shapes for each character to the list of outputs that can be evaluated.
74  void addCharacterShapeOutputs();
75 
76  /// Returns the default output shapes for each character. This can be used instead of
77  /// addCharacterShapeOutputs() if additional processing / validation is needed before
78  /// registering outputs.
79  /// @param include_invisible_chars If enabled, includes characters which are currently hidden in
80  /// the selection sets.
81  UT_Array<Output> findCharacterShapeOutputs(
82  bool include_invisible_chars = false) const;
83 
84  /// Returns the named geometry outputs for each character.
85  /// @param output_name
86  /// @param include_invisible_chars If enabled, includes characters which
87  /// are currently hidden in the selection sets.
88  UT_Array<Output> findCharacterGeometryOutputs(
89  const UT_StringHolder &output_name,
90  bool include_invisible_chars = false) const;
91 
92  /// Returns a list of the available output paths in the scene,
93  /// e.g. /electra.char/Base.rig/output
94  UT_StringArray findOutputPaths() const;
95 
96  /// Analyzes the graph to determine if the output shape is only deformed by a bonedeform SOP.
97  /// If successful, returns the paths which should be evaluated to obtain the rest geometry, rest
98  /// skeleton, and animated skeleton.
99  /// This assumes that the rest_shape and rest_skel are connected directly to an input from the bonedeform.
100  bool findSkinningInputsForShape(
101  const Output &deform_shape_output,
102  Output &rest_shape_output,
103  Output &rest_skel_output,
104  Output &anim_skel_output) const;
105 
106  /// Analyzes the graph to determine if the output shape is only deformed by a bonedeform SOP.
107  /// If successful, returns the path for the animated skeleton.
108  /// This can succeed even when the rest_skel and rest_shape aren't connected directly to an input from the bonedeform.
109  bool findAnimSkelInputForShape(
110  const Output &deform_shape_output,
111  Output &anim_skel_output) const;
112 
113  /// Update the scene to the specified time, clearing any cached output results.
114  void updateEvaluationTime(apex::Float frame);
115 
116  /// Evaluate the specified output at the scene's current time. Returns false if any errors occurred.
117  bool evaluateOutput(exint output_idx, UT_StringHolder &error);
118 
119  /// Set the active animation clip.
120  /// @param clip_path Path to the clip to activate or empty string to use
121  /// the default one from the scene..
122  /// @param error Outputs any error messages if the active clip could not be set.
123  /// @return true if successful, false otherwise
124  bool setActiveClip(const UT_StringHolder &clip_path, UT_StringHolder &error);
125 
126  /// Returns the resolved active clip path on the scene.
127  UT_StringHolder getActiveClipPath() const;
128 
129  /// Returns a list of the available clips in the scene.
130  UT_StringArray getClipPaths() const;
131 
132  /// Override a character geometry input with a new geometry.
133  /// This can be used to inject external animated geometries.
134  /// Call updateEvaluationTime() to force a refresh().
135  bool setCharacterGeoInput(
136  const UT_StringHolder &character_path,
137  const UT_StringHolder &geo_name,
138  const GU_ConstDetailHandle &geo);
139 
140  APEXA_Scene *getScene() { return myScene.get(); }
141 
142  /// Returns whether the name of a packed primitive is likely an item in a packed character
143  /// scene, e.g. "*.char"
144  /// This can be used to identify geometry that should be interpreted as a character scene.
145  static bool isCharacterSceneItemName(const UT_StringRef &name);
146 
147  /// Returns whether there are any channel primitives in the scene. This can be used to only load
148  /// / evaluate the scene when animation is present.
149  static bool hasAnimation(const GU_ConstDetailHandle &scene_gdh);
150 
151 private:
152  /// Load visibility information from selection sets.
153  void loadSelectionSetVisibility(const GU_Detail &detail);
154  /// Returns whether the rig is associated with a visible character.
155  bool isRigVisible(const UT_StringView &rig_path) const;
156 
158  int64 myDetailId = -1;
159  int64 myMetaCacheCount = -1;
160 
161  /// Invisible characters from the selection sets.
162  UT_StringSet myInvisibleChars;
163 
164  UT_Array<Output> myOutputs;
165 };
166 
167 #endif
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
#define UT_NULLOPT
Definition: UT_Optional.h:23
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
< 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
#define APEXA_API
Definition: APEXA_API.h:21
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
UT_Optional< UT_StringHolder > myKey
APEXA_Scene * getScene()
UT_Optional< UT_StringHolder > myPattern