Skylicht Engine
Loading...
Searching...
No Matches
COBJMeshFileLoader.h
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5// Modify by Skylicht
6/*
7!@
8MIT License
9
10Copyright (c) 2019 Skylicht Technology CO., LTD
11
12Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
13(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
14merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
15subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25This file is part of the "Skylicht Engine".
26https://github.com/skylicht-lab/skylicht-engine
27!#
28*/
29
30#pragma once
31
32#include "pch.h"
33#include "RenderMesh/CMesh.h"
34#include "RenderMesh/CSkinnedMesh.h"
35
36#include "Importer/CBaseMeshImporter.h"
37
38namespace Skylicht
39{
40 struct SObjMtl
41 {
42 SObjMtl() : Meshbuffer(0), Bumpiness(1.0f), Illumination(0),
43 RecalculateNormals(false)
44 {
45 Meshbuffer = new CMeshBuffer<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(0));
46 Meshbuffer->getMaterial().Shininess = 0.0f;
47 Meshbuffer->getMaterial().AmbientColor = video::SColorf(0.2f, 0.2f, 0.2f, 1.0f).toSColor();
48 Meshbuffer->getMaterial().DiffuseColor = video::SColorf(0.8f, 0.8f, 0.8f, 1.0f).toSColor();
49 Meshbuffer->getMaterial().SpecularColor = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f).toSColor();
50 }
51
52 SObjMtl(const SObjMtl& o)
53 : Name(o.Name), Group(o.Group),
54 Bumpiness(o.Bumpiness), Illumination(o.Illumination),
55 RecalculateNormals(false)
56 {
57 Meshbuffer = new CMeshBuffer<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(0));
58 Meshbuffer->getMaterial() = o.Meshbuffer->getMaterial();
59 }
60
63 core::stringc Name;
64 core::stringc Group;
65 f32 Bumpiness;
66 c8 Illumination;
67 bool RecalculateNormals;
68 };
69
70 class SKYLICHT_API COBJMeshFileLoader : public CBaseMeshImporter
71 {
72 protected:
73 core::array<SObjMtl*> m_materials;
74
75 std::string m_modelName;
76
77 bool m_flipNormalMap;
78
79 public:
80 COBJMeshFileLoader();
81
82 virtual ~COBJMeshFileLoader();
83
84 virtual bool loadModel(const char* resource, CEntityPrefab* output, bool normalMap = true, bool flipNormalMap = true, bool texcoord2 = true, bool batching = false);
85
86 void readMTL(const c8* fileName, const io::path& relPath);
87
88 SObjMtl* findMtl(const core::stringc& mtlName, const core::stringc& grpName);
89
90 bool retrieveVertexIndices(c8* vertexData, s32* idx, const c8* bufEnd, u32 vbsize, u32 vtsize, u32 vnsize);
91
92 void constructScene(CEntityPrefab* output, bool normalMap);
93 private:
94
95 const c8* readTextures(const c8* bufPtr, const c8* const bufEnd, SObjMtl* currMaterial, const io::path& relPath);
96
97 const c8* goFirstWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines = true);
98
99 const c8* goNextWord(const c8* buf, const c8* const bufEnd, bool acrossNewlines = true);
100
101 const c8* goNextLine(const c8* buf, const c8* const bufEnd);
102
103 u32 copyWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
104
105 core::stringc copyLine(const c8* inBuf, const c8* const bufEnd);
106
107 const c8* goAndCopyNextWord(c8* outBuf, const c8* inBuf, u32 outBufLength, const c8* const pBufEnd);
108
109 const c8* readColor(const c8* bufPtr, video::SColor& color, const c8* const pBufEnd);
110
111 const c8* readVec3(const c8* bufPtr, core::vector3df& vec, const c8* const pBufEnd);
112
113 const c8* readUV(const c8* bufPtr, core::vector2df& vec, const c8* const pBufEnd);
114
115 const c8* readBool(const c8* bufPtr, bool& tf, const c8* const bufEnd);
116
117 void cleanUp();
118 };
119}
This object class is created to store data in an array of multiple CEntities.
Definition CEntityPrefab.h:38
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
map template for associative arrays using a red-black tree
Definition irrMap.h:19
Implementation of the IMeshBuffer interface.
Definition CMeshBuffer.h:18
virtual const video::SMaterial & getMaterial() const
Get material of this meshbuffer.
Definition CMeshBuffer.h:240
Class representing a 32 bit ARGB color.
Definition SColor.h:285
Class representing a color with four floats.
Definition SColor.h:542
SColor toSColor() const
Converts this color to a SColor without floats.
Definition SColor.h:574
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
IVideoDriver * getVideoDriver()
Get the video driver used for rendering.
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
string< c8 > stringc
Typedef for character strings.
Definition irrString.h:1373
core::string< fschar_t > path
Type used for all file system related strings.
Definition path.h:17
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
char c8
8 bit character variable.
Definition irrTypes.h:31
signed int s32
32 bit signed variable.
Definition irrTypes.h:66
Definition COBJMeshFileLoader.h:41