ScummVM API documentation
t3d_mesh.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 #ifndef WATCHMAKER_T3D_MESH_H
23 #define WATCHMAKER_T3D_MESH_H
24 
25 #include "watchmaker/3d/t3d_face.h"
26 #include "watchmaker/t3d.h"
27 
28 namespace Watchmaker {
29 
30 struct t3dMESH {
31  Common::String name; // mesh name
32  Common::String portalName; // dest room name (if portal)
33  uint16 NumFaces() {
34  return FList.size();
35  }; // faces number
36  uint16 NumVerts = 0; // verts number
37  uint16 NumNormals = 0; // face normals number
38  uint16 NumVerticesNormals = 0; // verts normals number
39  gVertex *SavedVertexBuffer = nullptr; // saved vertices pos (original)
40  gVertex *VertexBuffer = nullptr; // cur vertices pos
41  gVertex *OldVertexBuffer = nullptr; // last vertices pos
42  t3dV3F *VertsInterpolants = nullptr; // verts interpolants (for blending)
43  gVertex *VBptr = nullptr; // temp pointer to vertexbuffer
44  Common::Array<t3dMORPH> MorphFrames; // morph frames list
45  Common::Array<t3dFACE> FList; // faces list
46  NormalList NList; // normals list
47  t3dV3F Pos; // mesh center
48  t3dV3F Trasl; // mesh traslation (world)
49  t3dF32 Radius = 0.0f; // radius for Bounding Sphere culling
50  t3dVERTEX BBox[8] = {}; // Bounding box
51  t3dNORMAL BBoxNormal[6] = {}; // bound box normals
52  t3dF32 BBoxAverageZ = 0.0f; // average distance from eye
53  t3dV3F Intersection; // intersecton form eye
54  t3dM3X3F Matrix; // transformation matrix (useful only for 1st mesh in body)
55  uint16 LightmapDim = 0; // lightmap texture dimensions
56  Common::Array<t3dMODVERTS> ModVertices; // mod vertices list
57  t3dBONEANIM DefaultAnim; // Default Animations
58  t3dBONEANIM Anim; // Animations
59  int16 CurFrame = 0; // current animation frames (0 no anim)
60  int16 LastFrame = 0; // last animation frames
61  uint8 BlendPercent = 0; // blend animation percentage
62  uint8 LastBlendPercent = 0; // last blend animation percentage
63  uint32 ExpressionFrame = 0; // current expression frames
64  uint32 LastExpressionFrame = 0; // last expression frames
65  int32 *WaterBuffer1 = nullptr; // pointers to ripple buffer
66  int32 *WaterBuffer2 = nullptr; // pointers to ripple buffer
67  t3dF32 WavesSpeed; // waves speed
68  t3dF32 YSpeed; // waves y speed
69  t3dF32 XInc, YInc; // waves movements
70 
71  t3dV3F SolarRGBVar[4]; // Override ambient color variation for solar movement
72 
73  uint32 Flags; // Flags
74  t3dBODY *PortalList = nullptr; // Pointer to portal connected
75  Common::Array<t3dMESH *> RejectedMeshes; // rejected mesh from portal
76 
77  void saveVertexBuffer() { // Scorre le mesh
78  this->VBptr = this->VertexBuffer;
79  if (this->OldVertexBuffer)
80  memcpy(this->OldVertexBuffer, this->VBptr, sizeof(gVertex)*this->NumVerts);
81  if (this->SavedVertexBuffer)
82  memcpy(this->SavedVertexBuffer, this->VBptr, sizeof(gVertex)*this->NumVerts);
83  this->VBptr = nullptr;
84  }
85 
86  void preCalcLights(const t3dV3F &ambientLight) {
87 #ifndef WMGEN
88  this->VBptr = this->VertexBuffer;
89 #endif
90  for (uint16 j = 0; j < this->NumFaces(); j++) { // Scorre le facce
91  t3dFACE &Face = this->FList[j];
92  MaterialPtr Material = Face.getMaterial();
93  uint32 alphaval = 2;
94  uint32 rr = 0, gg = 0, bb = 0;
95 
96  rr = Material->r; // Prende Ambient da materiale
97  gg = Material->g;
98  bb = Material->b;
99 
100  if (Material->hasFlag(T3D_MATERIAL_CLIPMAP)) { // Se il materiale e' clipmap
101  alphaval = 0xfe;
102  Face.flags |= T3D_MATERIAL_CLIPMAP; // lo setta sulla faccia
103  /* Face->flags&=~T3D_MATERIAL_OPACITY;
104  Face->flags&=~T3D_MATERIAL_GLASS;
105  Material->Flags&=~T3D_MATERIAL_OPACITY;
106  Material->Flags&=~T3D_MATERIAL_GLASS;*/
107 // r=g=b=0;
108  }
109  if (Material->hasFlag(T3D_MATERIAL_OPACITY)) { // Se il materiale e' opacity
110  Face.flags |= T3D_MATERIAL_OPACITY; // lo setta sulla faccia
111  alphaval = 0x88;
112  rr = gg = bb = 0;
113  }
114  if (Material->hasFlag(T3D_MATERIAL_GLASS)) { // Se e' un glass
115  Face.flags |= T3D_MATERIAL_GLASS; // lo setta sulla faccia
116  alphaval = 0xfe;
117  rr = gg = bb = 255;
118  }
119  if (Material->hasFlag(T3D_MATERIAL_BOTTLE)) { // Se e' un bottle
120  Face.flags |= T3D_MATERIAL_BOTTLE; // sulla faccia
121  alphaval = 0x88;
122  rr = gg = bb = 255;
123  }
124  if (Material->hasFlag(T3D_MATERIAL_ADDITIVE)) { // Se e' un additivo
125  Face.flags |= T3D_MATERIAL_ADDITIVE; // sulla faccia
126  alphaval = 0x88;
127  rr = gg = bb = 255;
128  }
129  if (rr < ambientLight.x) rr = (uint8)ambientLight.x;
130  if (gg < ambientLight.y) gg = (uint8)ambientLight.y;
131  if (bb < ambientLight.z) bb = (uint8)ambientLight.z;
132  this->VBptr[Face.VertexIndex[0]].diffuse = RGBA_MAKE(rr, gg, bb, alphaval); // Cambia diffse dei vertici della mesh
133  this->VBptr[Face.VertexIndex[1]].diffuse = RGBA_MAKE(rr, gg, bb, alphaval);
134  this->VBptr[Face.VertexIndex[2]].diffuse = RGBA_MAKE(rr, gg, bb, alphaval);
135  }
136 #ifndef WMGEN
137  this->VBptr = nullptr;
138 #endif
139 // rOptimizeVertexArray(Mesh->VertexBuffer);
140  }
141 
142  t3dMESH() = default;
143  t3dMESH(t3dBODY *b, Common::SeekableReadStream &stream, t3dMESH *&ReceiveRipples, uint8 &Mirror);
144  t3dMESH(const t3dMESH &other);
145  t3dMESH(t3dMESH &&old);
146  t3dMESH& operator=(t3dMESH rhs);
147  ~t3dMESH();
148  void loadFaces(t3dBODY *b, Common::SeekableReadStream &stream, int numFaces);
149  void release();
150  void releaseAnim(uint8 flag);
151 
152  bool hasFaceMaterial() const {
153  return !this->FList.empty() && (bool)(this->FList[0].getMaterial());
154  }
155 
156  void setMovieFrame(uint32 dwCurrFrame) {
157  // TODO: Could just inline rSetMovieFrame?
158  if (!this->FList.empty() && this->FList[0].getMaterial()) {
159  rSetMovieFrame(this->FList[0].getMaterial(), dwCurrFrame);
160  }
161  }
162  uint32 getMovieFrame() {
163  assert(!this->FList.empty() && this->FList[0].getMaterial());
164  return rGetMovieFrame(this->FList[0].getMaterial());
165  }
166 };
167 
168 } // End of namespace Watchmaker
169 
170 #endif // WATCHMAKER_T3D_MESH_H
Definition: t3d.h:128
Definition: types3d.h:38
Definition: 2d_stuff.h:30
Definition: str.h:59
Definition: array.h:52
Definition: types3d.h:101
Definition: vertex.h:33
Definition: t3d_face.h:31
Definition: stream.h:745
bool empty() const
Definition: array.h:351
Definition: t3d_body.h:32
Definition: render.h:83
Definition: t3d_mesh.h:30
Definition: t3d.h:181
Definition: t3d.h:116