Overte C++ Documentation
ScriptableModel.h
1 //
2 // Copyright 2018 High Fidelity, Inc.
3 // Copyright 2023 Overte e.V.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 // SPDX-License-Identifier: Apache-2.0
8 //
9 
10 #pragma once
11 
12 #include "Forward.h"
13 #include "GraphicsScriptingUtil.h"
14 
15 namespace scriptable {
16 
17  using ScriptableMeshes = QVector<scriptable::ScriptableMeshPointer>;
18 
19  /*@jsdoc
20  * A handle to in-memory model data such as may be used in displaying avatars, 3D entities, or 3D overlays in the rendered
21  * scene. Changes made to the model are visible only to yourself; they are not persisted.
22  * <p>Note: The model may be used for more than one instance of an item displayed in the scene. Modifying the model updates
23  * all instances displayed.</p>
24  *
25  * <p>Create using the {@link Graphics} API or {@link GraphicsModel.cloneModel}.</p>
26  *
27  * @class GraphicsModel
28  * @hideconstructor
29  *
30  * @hifi-interface
31  * @hifi-client-entity
32  * @hifi-avatar
33  *
34  * @property {Uuid} objectID - The ID of the entity or avatar that the model is associated with, if any; <code>null</code>
35  * if the model is not associated with an entity or avatar.
36  * <em>Read-only.</em>
37  * @property {number} numMeshes - The number of meshes in the model.
38  * <em>Read-only.</em>
39  * @property {GraphicsMesh[]} meshes - The meshes in the model. Each mesh may have more than one mesh part.
40  * <em>Read-only.</em>
41  * @property {string[]} materialNames - The names of the materials used by each mesh part in the model. The names are in
42  * the order of the <code>meshes</code> and their mesh parts.
43  * <em>Read-only.</em>
44  * @property {Object.<string,Graphics.MaterialLayer[]>} materialLayers - The mapping from mesh parts and material
45  * names to material layers. The mesh parts are numbered from <code>"0"</code> per the array indexes of
46  * <code>materialNames</code>. The material names are those used in <code>materialNames</code>. (You can look up a
47  * material layer by mesh part number or by material name.)
48  * <em>Read-only.</em>
49  */
50  class ScriptableModel : public ScriptableModelBase {
51  Q_OBJECT
52  Q_PROPERTY(QUuid objectID MEMBER objectID CONSTANT)
53  Q_PROPERTY(glm::uint32 numMeshes READ getNumMeshes)
54  Q_PROPERTY(ScriptableMeshes meshes READ getMeshes)
55  Q_PROPERTY(scriptable::MultiMaterialMap materialLayers READ getMaterialLayers)
56  Q_PROPERTY(QVector<QString> materialNames READ getMaterialNames)
57 
58  public:
59  ScriptableModel(QObject* parent = nullptr) : ScriptableModelBase(parent) {}
60  ScriptableModel(const ScriptableModel& other) : ScriptableModelBase(other) {}
61  ScriptableModel(const ScriptableModelBase& other) : ScriptableModelBase(other) {}
62  ScriptableModel& operator=(const ScriptableModelBase& view) { ScriptableModelBase::operator=(view); return *this; }
63 
64  operator scriptable::ScriptableModelBasePointer() {
65  return QPointer<scriptable::ScriptableModelBase>(qobject_cast<scriptable::ScriptableModelBase*>(this));
66  }
67  ScriptableMeshes getMeshes();
68  const ScriptableMeshes getConstMeshes() const;
69 
70  scriptable::MultiMaterialMap getMaterialLayers() { return materialLayers; }
71  QVector<QString> getMaterialNames() { return materialNames; }
72 
73  public slots:
74 
75  /*@jsdoc
76  * Makes a copy of the model.
77  * @function GraphicsModel.cloneModel
78  * @param {object} [options] - <em>Not used.</em>
79  * @returns {GraphicsModel} A copy of the model.
80  */
81  scriptable::ScriptableModelPointer cloneModel(const QVariantMap& options = QVariantMap());
82 
83  /*@jsdoc
84  * Gets a string description of the model.
85  * @function GraphicsModel.toString
86  * @returns {string} A string description of the model.
87  * @example <caption>Report the string description of your avatar's model.</caption>
88  * var model = Graphics.getModel(MyAvatar.sessionUUID);
89  * print("Avatar model info:", model.toString());
90  */
91  QString toString() const;
92 
93  protected:
94  glm::uint32 getNumMeshes() { return meshes.size(); }
95 
96  };
97 
98 }
99 
100 Q_DECLARE_METATYPE(scriptable::ScriptableModelPointer)
101 Q_DECLARE_METATYPE(QVector<scriptable::ScriptableModelPointer>)
102 Q_DECLARE_METATYPE(scriptable::ScriptableMaterial)
103 Q_DECLARE_METATYPE(scriptable::ScriptableMaterialLayer)
104 Q_DECLARE_METATYPE(scriptable::MultiMaterialMap)