1 #ifndef __DALI_MODEL_H__
2 #define __DALI_MODEL_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <boost/function.hpp>
27 #include <dali/public-api/common/loading-state.h>
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/signals/dali-signal-v2.h>
31 namespace Dali DALI_IMPORT_API
37 namespace Internal DALI_INTERNAL
43 * @brief A handle to 3D model data loaded as a resource.
45 * Use ModelActorFactory::BuildActorTree() to create actors from this model.
46 * Use ModelActorFactory::BuildAnimation() to create animations on such actors.
48 class Model : public BaseHandle
52 typedef SignalV2<void (Model)> ModelSignalV2; ///< Signal type
53 typedef SignalV2<void (Model,bool)> ModelSaveSignalV2; ///< Signal type for saving models
56 static const char* const SIGNAL_MODEL_LOADING_FINISHED; ///< name "model-loading-finished"
57 static const char* const SIGNAL_MODEL_SAVING_FINISHED; ///< name "model-saving-finished"
61 * @brief Create an uninitialized Model.
63 * This can be initialised with Model::New(). Calling member
64 * functions with an uninitialized Dali::Object is not allowed.
69 * @brief Asynchronously load a model.
71 * Connect to SignalLoadingFinished() to determine when the model
72 * has finished loading.
74 * @param [in] url The url of the model data.
75 * @return A handle to a newly allocated Dali resource.
77 static Model New(const std::string& url);
80 * @brief Downcast an Object handle to Model handle.
82 * If handle points to a Model object the downcast produces valid
83 * handle. If not the returned handle is left uninitialized.
85 * @param[in] handle to An object
86 * @return handle to an Model object or an uninitialized handle
88 static Model DownCast( BaseHandle handle );
91 * @brief Virtual destructor.
93 * Dali::Object derived classes typically do not contain member data.
98 * @copydoc Dali::BaseHandle::operator=
100 using BaseHandle::operator=;
103 * @brief Query whether the model data has loaded.
105 * The asynchronous loading begins when the Model object is created.
106 * After the Model object is discarded, the model data will be released from memory.
107 * @return The loading state, either Loading, Success or Failed.
109 LoadingState GetLoadingState();
112 * @brief Emitted when the model data loads successfully or when the loading fails.
114 * @return A signal object to Connect() with.
116 ModelSignalV2& LoadingFinishedSignal();
119 * @brief Emitted when the model data save request completes.
121 * @return A signal object to Connect() with.
123 ModelSaveSignalV2& SavingFinishedSignal();
126 * @brief Get number of animations in the model.
128 * @pre The model has been loaded.
129 * @return The number of animations encoded in the model, or zero if the model
130 * hasn't finished loading.
132 size_t NumberOfAnimations() const;
135 * @brief Get the index of a named animation map in the model.
137 * @param[in] animationName The name of the animation to find
138 * @param[out] animationIndex The index of the named animation if found
139 * @return true if the animation was foud, false if not found.
141 bool FindAnimation(const std::string& animationName, unsigned int& animationIndex);
144 * @brief Write the model data to the standard output in textual format.
146 * Note - will assert if any part of the model is on the scene graph (i.e. if
147 * an actor has been created from this model)
152 * @brief Save a Dali representation of the mode data.
154 * Used for faster loading on subsequent uses.
155 * @param[in] url The resource url for the data
157 void Save(const std::string& url);
159 public: // Not intended for application developers
162 * @brief This constructor is used by Dali New() methods.
164 * @param [in] model A pointer to a newly allocated Dali resource
166 explicit DALI_INTERNAL Model(Internal::Model* model);
171 #endif // __DALI_MODEL_H__