1 #ifndef DALI_TOOLKIT_INTERNAL_OBJ_LOADER_H
2 #define DALI_TOOLKIT_INTERNAL_OBJ_LOADER_H
5 * Copyright (c) 2021 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.
22 #include <dali/public-api/rendering/renderer.h>
49 Vertex(const Vector3& position, const Vector3& normal, const Vector2& textureCoord)
65 VertexExt(const Vector3& tangent, const Vector3& binormal)
79 pointMin = Vector3(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
80 pointMax = Vector3(std::numeric_limits<float>::min(), std::numeric_limits<float>::min(), std::numeric_limits<float>::min());
83 void ConsiderNewPointInVolume(const Vector3& position)
85 pointMin.x = std::min(position.x, pointMin.x);
86 pointMin.y = std::min(position.y, pointMin.y);
87 pointMin.z = std::min(position.z, pointMin.z);
89 pointMax.x = std::max(position.x, pointMax.x);
90 pointMax.y = std::max(position.y, pointMax.y);
91 pointMax.z = std::max(position.z, pointMax.z);
98 //Defines bit masks to declare which properties are needed by anyone requesting a geometry.
101 TEXTURE_COORDINATES = 1 << 0,
107 virtual ~ObjLoader();
109 bool IsSceneLoaded();
110 bool IsMaterialLoaded();
112 bool LoadObject(char* objBuffer, std::streampos fileSize);
114 void LoadMaterial(char* objBuffer, std::streampos fileSize, std::string& diffuseTextureUrl, std::string& normalTextureUrl, std::string& glossTextureUrl);
116 Geometry CreateGeometry(int objectProperties, bool useSoftNormals);
123 bool IsTexturePresent();
124 bool IsDiffuseMapPresent();
125 bool IsNormalMapPresent();
126 bool IsSpecularMapPresent();
129 BoundingVolume mSceneAABB;
132 bool mMaterialLoaded;
133 bool mHasTexturePoints;
135 //Material file properties.
138 bool mHasSpecularMap;
140 Dali::Vector<Vector3> mPoints;
141 Dali::Vector<Vector2> mTextures;
142 Dali::Vector<Vector2> mTextures2;
143 Dali::Vector<Vector3> mNormals;
144 Dali::Vector<Vector3> mTangents;
145 Dali::Vector<Vector3> mBiTangents;
146 Dali::Vector<TriIndex> mTriangles;
149 * @brief Calculates normals for each point on a per-face basis.
151 * There are multiple normals per point, each corresponding to the normal of a face connecting to the point.
153 * @param[in] vertices The vertices of the object.
154 * @param[in, out] triangles The triangles that form the faces. The normals of each triangle will be updated.
155 * @param[in, out] normals The normals to be calculated.
157 void CalculateHardFaceNormals(const Dali::Vector<Vector3>& vertices,
158 Dali::Vector<TriIndex>& triangles,
159 Dali::Vector<Vector3>& normals);
162 * @brief Calculates smoothed normals for each point.
164 * There is one normal per point, an average of the connecting faces.
166 * @param[in] vertices The vertices of the object.
167 * @param[in, out] triangles The triangles that form the faces. The normals of each triangle will be updated.
168 * @param[in, out] normals The normals to be calculated.
170 void CalculateSoftFaceNormals(const Dali::Vector<Vector3>& vertices,
171 Dali::Vector<TriIndex>& triangles,
172 Dali::Vector<Vector3>& normals);
175 * @brief Calculates tangents and bitangents for each point of the object.
177 * These are calculated using the object's points, texture coordinates and normals, so these must be initialised first.
179 void CalculateTangentFrame();
181 void CenterAndScale(bool center, Dali::Vector<Vector3>& points);
184 * @brief Using the data loaded from the file, create arrays of data to be used in creating the geometry.
186 * @param[in] vertices The vertices of the object.
187 * @param[in] textures The texture coordinates of the object.
188 * @param[in] verticesExt Extension to vertices, storing tangents and bitangents.
189 * @param[in] indices Indices of corresponding values to match triangles to their respective data.
190 * @param[in] useSoftNormals Indicates whether we should average the normals at each point to smooth the surface or not.
192 void CreateGeometryArray(Dali::Vector<Vertex>& vertices,
193 Dali::Vector<Vector2>& textures,
194 Dali::Vector<VertexExt>& verticesExt,
195 Dali::Vector<unsigned short>& indices,
196 bool useSoftNormals);
199 } // namespace Internal
201 } // namespace Toolkit
205 #endif // DALI_TOOLKIT_INTERNAL_OBJ_LOADER_H