2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "game-model.h"
19 #include "game-utils.h"
21 using namespace GameUtils;
25 // 'MODV' tag stored in the big-endian (network) order
26 const uint32_t MODV_TAG(0x4D4F4456);
29 GameModel::GameModel(const char* filename)
34 if(!LoadFile(filename, bytes))
39 mHeader = *(reinterpret_cast<ModelHeader*>(bytes.data()));
42 if(MODV_TAG != mHeader.tag)
44 // jump to little-endian variant
45 mHeader = *(reinterpret_cast<ModelHeader*>(bytes.data() + bytes.size() / 2));
48 mVertexBuffer = Dali::VertexBuffer::New(Dali::Property::Map().Add("aPosition", Dali::Property::VECTOR3).Add("aNormal", Dali::Property::VECTOR3).Add("aTexCoord", Dali::Property::VECTOR2));
50 mVertexBuffer.SetData(bytes.data() + mHeader.dataBeginOffset, mHeader.vertexBufferSize / mHeader.vertexStride);
52 mGeometry = Dali::Geometry::New();
53 mGeometry.AddVertexBuffer(mVertexBuffer);
54 mGeometry.SetType(Dali::Geometry::TRIANGLES);
56 mUniqueId = HashString(filename);
61 GameModel::~GameModel()
65 Dali::Geometry& GameModel::GetGeometry()
70 bool GameModel::IsReady()
75 uint32_t GameModel::GetUniqueId()