-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgl3Mesh.pas
155 lines (133 loc) · 4.29 KB
/
gl3Mesh.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
unit gl3Mesh;
(* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the gl3ds main unit.
*
* The Initial Developer of the Original Code is
* Noeska Software.
* Portions created by the Initial Developer are Copyright (C) 2002-2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* M van der Honing
*
*)
{$IFDEF FPC}
{$MODE Delphi}
{$H+}
{$M+}
{$codepage utf8}
{$IFNDEF WINDOWS}
{$LINKLIB c}
{$ENDIF}
{$ENDIF}
interface
uses classes, dglOpenGl, Mesh, glMath, sysutils;
type
Tgl3Mesh = class(TBaseMesh)
protected
fDrawStyle: GLenum;
fNormalAttribId: GlInt;
fColorAttribId: GlInt;
fVertexAttribId: GlInt;
fBoneAttribId: GlInt;
fBoneAttribWeight: GlInt;
fBones: GlInt;
foffset: integer;
fsize: integer;
public
destructor Destroy; override;
procedure Init; override;
procedure Render; override;
property DrawStyle: GLenum read fDrawStyle write fDrawStyle;
property VertexAttribId: GLInt read fVertexAttribId write fVertexAttribId;
property ColorAttribId: GLInt read fColorAttribId write fColorAttribId;
property NormalAttribId: GLInt read fNormalAttribId write fNormalAttribId;
property BoneAttribId: GLInt read fBoneAttribId write fBoneAttribId;
property BoneAttribWeight: GLInt read fBoneAttribWeight write fBoneAttribWeight;
property Bones: GLInt read fBones write fBones;
property Offset: integer read foffset write foffset;
property Size: integer read fsize write fsize;
end;
implementation
uses Material, model, gl3Render, glvbo;
destructor Tgl3Mesh.Destroy;
begin
inherited;
end;
procedure Tgl3Mesh.Init;
var
j: integer;
test: TVBOVertex;
begin
if (fdrawstyle = 0) then fDrawStyle:=GL_TRIANGLES;
fId:= Tgl3Render(Owner.Owner).VBO.AddMesh(GL_TRIANGLES);
// fill the vbo buffer with vertices and colors and normals (and uv tex coords)
for j:=0 to fnumvertexindices-1 do
begin
test.Position:=fVertex[fVertexIndices[j]];
test.Normal:=fvNormal[fNormalIndices[j]];
if TBaseModel(owner).NumMaterials>=1 then
begin
test.Color.r:=TBaseModel(owner).material[fmatid[j div 3]].DiffuseRed;
test.Color.g:=TBaseModel(owner).material[fmatid[j div 3]].DiffuseGreen;
test.Color.b:=TBaseModel(owner).material[fmatid[j div 3]].DiffuseBlue;
test.Color.a:=TBaseModel(owner).material[fmatid[j div 3]].Transparency;
end
else
begin
test.Color.r:=1.0;
test.Color.g:=1.0;
test.Color.b:=1.0;
test.Color.a:=1.0;
end;
if high(fMappingIndices)>=1 then
begin
test.TexCoord.tu:=fMapping[fMappingIndices[j]].tu;
test.TexCoord.tv:=fMapping[fMappingIndices[j]].tv;
end
else
begin
test.TexCoord.tu:=0.0;
test.TexCoord.tv:=0.0;
end;
test.BoneIndex.x:=fBoneIndices[FVertexIndices[j],0]; //only one bone for now
test.BoneIndex.y:=fBoneIndices[FVertexIndices[j],1];
test.BoneIndex.z:=fBoneIndices[FVertexIndices[j],2];
test.BoneIndex.w:=fBoneIndices[FVertexIndices[j],3];
test.BoneWeight.x:=fBoneWeights[FVertexIndices[j],0]; //only one bone for now
test.BoneWeight.y:=fBoneWeights[FVertexIndices[j],1];
test.BoneWeight.z:=fBoneWeights[FVertexIndices[j],2];
test.BoneWeight.w:=fBoneWeights[FVertexIndices[j],3];
Tgl3Render(TBaseModel(Owner).Owner).VBO.AddVertex(test);
end;
fOffset:=Tgl3Render(Owner.Owner).VBO.getOffset(fId);
fSize:=Tgl3Render(Owner.Owner).VBO.getSize(fId);
//TODO: implement further
end;
procedure Tgl3Mesh.Render;
var
imatid: integer;
begin
if fvisible then
begin
imatid := MatId[0];
if TBaseModel(owner).NumMaterials >0 then
if (TBaseModel(owner).material[imatid]<>nil) then
if (TBaseModel(owner).material[imatid] is TBaseMaterial) then
TBaseModel(owner).material[imatid].apply;
Tgl3Render(Owner.Owner).Render(fId);
end;
end;
end.