ScummVM API documentation
xskinmesh.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Based on skin and mesh code from Wine sources.
24 * Copyright (C) 2005 Henri Verbeet
25 * Copyright (C) 2006 Ivan Gyurdiev
26 * Copyright (C) 2009 David Adam
27 * Copyright (C) 2010 Tony Wasserka
28 * Copyright (C) 2011 Dylan Smith
29 * Copyright (C) 2011 Michael Mc Donnell
30 * Copyright (C) 2013 Christian Costa
31 */
32
33#ifndef WINTERMUTE_XSKINMESH_H
34#define WINTERMUTE_XSKINMESH_H
35
36#include "engines/wintermute/base/gfx/xbuffer.h"
37#include "engines/wintermute/base/gfx/xfile_loader.h"
38#include "engines/wintermute/base/gfx/xmath.h"
39
40namespace Wintermute {
41
42#define DXFVF_XYZ 0x0002
43#define DXFVF_NORMAL 0x0010
44#define DXFVF_DIFFUSE 0x0040
45#define DXFVF_TEX1 0x0100
46
47typedef enum {
48 DXDECLUSAGE_NORMAL = 3,
49 DXDECLUSAGE_TEXCOORD = 5,
50 DXDECLUSAGE_TANGENT = 6,
51 DXDECLUSAGE_BINORMAL = 7,
52} DXDECLUSAGE;
53
54typedef enum {
55 DXDECLTYPE_FLOAT2 = 1,
56 DXDECLTYPE_FLOAT3 = 2,
57} DXDECLTYPE;
58
59#if defined(SCUMMVM_USE_PRAGMA_PACK)
60#pragma pack(4)
61#endif
62
64 uint32 _attribId;
65 uint32 _faceStart;
66 uint32 _faceCount;
67 uint32 _vertexStart;
68 uint32 _vertexCount;
69};
70
72 uint32 _size;
73 DXAttributeRange *_ptr;
74};
75
76typedef union {
77 struct {
78 float _r;
79 float _g;
80 float _b;
81 float _a;
82 } color;
83 float _data[4];
85
86typedef struct {
87 DXColorValue _diffuse;
88 DXColorValue _ambient;
89 DXColorValue _specular;
90 DXColorValue _emissive;
91 float _power;
92 char _textureFilename[XMAX_NAME_LEN];
94
95struct DXBone {
96 char *_name;
97 DXMatrix _transform;
98 uint32 _numInfluences;
99 uint32 *_vertices;
100 float *_weights;
101};
102
103#if defined(SCUMMVM_USE_PRAGMA_PACK)
104#pragma pack()
105#endif
106
108 uint32 _fvf{};
109 uint32 _numVertices{};
110 uint32 _numBones{};
111 DXBone *_bones{};
112
113public:
114 ~DXSkinInfo() { destroy(); }
115 bool create(uint32 vertexCount, uint32 fvf, uint32 boneCount);
116 void destroy();
117 uint32 getNumBones() { return _numBones; }
118 bool setBoneName(uint32 boneIdx, const char *name);
119 char *getBoneName(uint32 boneIdx) { return _bones[boneIdx]._name; }
120 bool setBoneInfluence(uint32 boneIdx, uint32 numInfluences, const uint32 *vertices, const float *weights);
121 DXBone *getBone(uint32 boneIdx);
122 bool setBoneOffsetMatrix(uint32 boneIdx, const float *boneTransform);
123 DXMatrix *getBoneOffsetMatrix(uint32 boneIdx) { return &_bones[boneIdx]._transform; }
124 bool updateSkinnedMesh(const DXMatrix *boneTransforms, void *srcVertices, void *dstVertices);
125};
126
127class DXMesh {
128 uint32 _numFaces;
129 uint32 _numVertices;
130 uint32 _fvf;
131 uint32 _vertexSize;
132 DXBuffer _vertexBuffer;
133 DXBuffer _indexBuffer;
134 DXBuffer _attribBuffer;
135 DXAttributeRangeTable _attribTable;
136
137 struct DXVertexMetadata {
138 float _key;
139 uint32 _vertexIndex;
140 uint32 _firstSharedIndex;
141 };
142
143 static int compareVertexKeys(const void *a, const void *b);
144
145public:
146 ~DXMesh() { destroy(); }
147 bool create(uint32 numFaces, uint32 numVertices, uint32 fvf);
148 void destroy();
149 bool cloneMesh(DXMesh **cloneMeshOut);
150 uint32 getNumFaces() { return _numFaces; }
151 uint32 getNumVertices() { return _numVertices; }
152 uint32 getFVF() { return _fvf; }
153 DXBuffer getVertexBuffer() { return _vertexBuffer; }
154 DXBuffer getIndexBuffer() { return _indexBuffer; }
155 DXBuffer getAtribBuffer() { return _attribBuffer; }
156 DXAttributeRangeTable *getAttributeTable() { return &_attribTable; }
157 bool generateAdjacency(uint32 *adjacency);
158};
159
160bool DXLoadSkinMesh(XFileData *fileData, DXBuffer &materialsOut, uint32 &numMaterialsOut, DXSkinInfo **skinInfoOut, DXMesh **meshOut);
161uint32 DXGetFVFVertexSize(uint32 fvf);
162bool DXComputeBoundingBox(DXVector3 *pfirstposition, uint32 numvertices, uint32 dwstride, DXVector3 *pmin, DXVector3 *pmax);
163
164} // namespace Wintermute
165
166#endif
Definition: xskinmesh.h:127
Definition: xskinmesh.h:107
Definition: xfile_loader.h:459
Definition: xskinmesh.h:63
Definition: xskinmesh.h:71
Definition: xskinmesh.h:95
Definition: xbuffer.h:30
Definition: xskinmesh.h:86
Definition: xmath.h:139
Definition: xmath.h:72
Definition: xskinmesh.h:76