1 #ifndef __DALI_MODEL_H__
2 #define __DALI_MODEL_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
22 #include <boost/function.hpp>
26 #include <dali/public-api/common/loading-state.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/signals/dali-signal-v2.h>
30 namespace Dali DALI_IMPORT_API
36 namespace Internal DALI_INTERNAL
42 * @brief A handle to 3D model data loaded as a resource.
44 * Use ModelActorFactory::BuildActorTree() to create actors from this model.
45 * Use ModelActorFactory::BuildAnimation() to create animations on such actors.
47 class Model : public BaseHandle
51 typedef SignalV2<void (Model)> ModelSignalV2; ///< Signal type
52 typedef SignalV2<void (Model,bool)> ModelSaveSignalV2; ///< Signal type for saving models
55 static const char* const SIGNAL_MODEL_LOADING_FINISHED; ///< name "model-loading-finished"
56 static const char* const SIGNAL_MODEL_SAVING_FINISHED; ///< name "model-saving-finished"
60 * @brief Create an uninitialized Model.
62 * This can be initialised with Model::New(). Calling member
63 * functions with an uninitialized Dali::Object is not allowed.
68 * @brief Asynchronously load a model.
70 * Connect to SignalLoadingFinished() to determine when the model
71 * has finished loading.
73 * @param [in] url The url of the model data.
74 * @return A handle to a newly allocated Dali resource.
76 static Model New(const std::string& url);
79 * @brief Downcast an Object handle to Model handle.
81 * If handle points to a Model object the downcast produces valid
82 * handle. If not the returned handle is left uninitialized.
84 * @param[in] handle to An object
85 * @return handle to an Model object or an uninitialized handle
87 static Model DownCast( BaseHandle handle );
90 * @brief Virtual destructor.
92 * Dali::Object derived classes typically do not contain member data.
97 * @copydoc Dali::BaseHandle::operator=
99 using BaseHandle::operator=;
102 * @brief Query whether the model data has loaded.
104 * The asynchronous loading begins when the Model object is created.
105 * After the Model object is discarded, the model data will be released from memory.
106 * @return The loading state, either Loading, Success or Failed.
108 LoadingState GetLoadingState();
111 * @brief Emitted when the model data loads successfully or when the loading fails.
113 * @return A signal object to Connect() with.
115 ModelSignalV2& LoadingFinishedSignal();
118 * @brief Emitted when the model data save request completes.
120 * @return A signal object to Connect() with.
122 ModelSaveSignalV2& SavingFinishedSignal();
125 * @brief Get number of animations in the model.
127 * @pre The model has been loaded.
128 * @return The number of animations encoded in the model, or zero if the model
129 * hasn't finished loading.
131 size_t NumberOfAnimations() const;
134 * @brief Get the index of a named animation map in the model.
136 * @param[in] animationName The name of the animation to find
137 * @param[out] animationIndex The index of the named animation if found
138 * @return true if the animation was foud, false if not found.
140 bool FindAnimation(const std::string& animationName, unsigned int& animationIndex);
143 * @brief Write the model data to the standard output in textual format.
145 * Note - will assert if any part of the model is on the scene graph (i.e. if
146 * an actor has been created from this model)
151 * @brief Save a Dali representation of the mode data.
153 * Used for faster loading on subsequent uses.
154 * @param[in] url The resource url for the data
156 void Save(const std::string& url);
158 public: // Not intended for application developers
161 * @brief This constructor is used by Dali New() methods.
163 * @param [in] model A pointer to a newly allocated Dali resource
165 explicit DALI_INTERNAL Model(Internal::Model* model);
170 #endif // __DALI_MODEL_H__