質問編集履歴
6
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
-
提示コードですが`Mesh::Draw()`関数の`shader.setUniformMatrix4fv("uTranslate",getMatTranslation());`関数で下記のエラーが出ます。これはなぜでしょうか?`Mesh`クラスのコンストラクタでシェーダーをロードして`
|
1
|
+
提示コードですが`Mesh::Draw()`関数の`shader.setUniformMatrix4fv("uTranslate",getMatTranslation());`関数で下記のエラーが出ます。これはなぜでしょうか?`Mesh`クラスのコンストラクタでシェーダーをロードして`Draw()`関数で使っているのですが
|
2
|
+
|
2
|
-
|
3
|
+
なぜ-1のエラーが返ってくるのか原因がわりません。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
##### 確認したこと
|
8
|
+
|
3
|
-
|
9
|
+
その他の2Dで円や矩形などの描画はこのクラスで行えるので`shader`クラスは問題ないです。
|
4
10
|
|
5
11
|
|
6
12
|
|
@@ -190,6 +196,36 @@
|
|
190
196
|
|
191
197
|
```Mode.cpp
|
192
198
|
|
199
|
+
#include "../header/Model.hpp"
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
#include <iostream>
|
204
|
+
|
205
|
+
#include <assert.h>
|
206
|
+
|
207
|
+
#include <vector>
|
208
|
+
|
209
|
+
#include <assimp/Importer.hpp>
|
210
|
+
|
211
|
+
#include <assimp/scene.h>
|
212
|
+
|
213
|
+
#include <assimp/postprocess.h>
|
214
|
+
|
215
|
+
#include <glm/glm.hpp>
|
216
|
+
|
217
|
+
#include <GL/glew.h>
|
218
|
+
|
219
|
+
#include "../lib/stb/stb_image.h"
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
#include "../header/Resource.hpp"
|
224
|
+
|
225
|
+
#include "../header/Camera.hpp"
|
226
|
+
|
227
|
+
|
228
|
+
|
193
229
|
|
194
230
|
|
195
231
|
FrameWork::D3::Mesh::Mesh(std::vector<VertexAttribute> ver, std::vector<unsigned int> idx, std::vector<Texture> tex) : Transform()
|
@@ -212,10 +248,6 @@
|
|
212
248
|
|
213
249
|
|
214
250
|
|
215
|
-
|
216
|
-
|
217
|
-
//printf("あああ\n");
|
218
|
-
|
219
251
|
if ( shader.Input(FrameWork::LoadShader("Shader/3D/BasicMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasicMono_3D.frag")->data()) == false)
|
220
252
|
|
221
253
|
{
|
@@ -226,11 +258,77 @@
|
|
226
258
|
|
227
259
|
|
228
260
|
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
glGenVertexArrays(1, &VAO);
|
266
|
+
|
267
|
+
glGenBuffers(1, &VBO);
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
glBindVertexArray(VAO);
|
272
|
+
|
273
|
+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, index.size() * sizeof(unsigned int),index.data(), GL_DYNAMIC_DRAW);
|
282
|
+
|
283
|
+
glBufferData(GL_ARRAY_BUFFER, vertex.size() * sizeof(VertexAttribute), vertex.data(), GL_DYNAMIC_DRAW);
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
GLint attrib = shader.getAttribLocation("vertexPosition");
|
288
|
+
|
289
|
+
glEnableVertexAttribArray(attrib);
|
290
|
+
|
291
|
+
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
292
|
+
|
293
|
+
shader.setBindAttribLocation("vertexPosition");
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
229
|
-
//printf("
|
299
|
+
//printf("あああ\n");
|
300
|
+
|
301
|
+
|
302
|
+
|
230
|
-
|
303
|
+
// vertex texture coords
|
304
|
+
|
231
|
-
|
305
|
+
//attrib = shader.getAttribLocation("vertexUV");
|
306
|
+
|
232
|
-
|
307
|
+
//glEnableVertexAttribArray(attrib);
|
308
|
+
|
309
|
+
//glVertexAttribPointer(attrib, 2, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 3));
|
310
|
+
|
311
|
+
//printf("ららら\n");
|
312
|
+
|
313
|
+
// vertex normals
|
314
|
+
|
315
|
+
//attrib = shader.getAttribLocation("vertexNormal");
|
316
|
+
|
317
|
+
//glEnableVertexAttribArray(attrib);
|
318
|
+
|
319
|
+
//glVertexAttribPointer(attrib, 3, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 5));
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
233
|
-
|
325
|
+
glBindVertexArray(0);
|
326
|
+
|
327
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
234
332
|
|
235
333
|
}
|
236
334
|
|
@@ -316,62 +414,6 @@
|
|
316
414
|
|
317
415
|
|
318
416
|
|
319
|
-
void FrameWork::D3::Mesh::SetUp()
|
320
|
-
|
321
|
-
{
|
322
|
-
|
323
|
-
glGenVertexArrays(1, &VAO);
|
324
|
-
|
325
|
-
glGenBuffers(1, &VBO);
|
326
|
-
|
327
|
-
//glGenBuffers(1, &EBO);
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
glBindVertexArray(VAO);
|
332
|
-
|
333
|
-
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, index.size() * sizeof(unsigned int),index.data(), GL_DYNAMIC_DRAW);
|
342
|
-
|
343
|
-
glBufferData(GL_ARRAY_BUFFER, vertex.size() * sizeof(VertexAttribute), vertex.data(), GL_DYNAMIC_DRAW);
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
GLint attrib = shader.getAttribLocation("vertexPosition");
|
348
|
-
|
349
|
-
glEnableVertexAttribArray(attrib);
|
350
|
-
|
351
|
-
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
352
|
-
|
353
|
-
shader.setBindAttribLocation("vertexPosition");
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
FrameWork::D3::Model::Model(const char *path)
|
366
|
-
|
367
|
-
{
|
368
|
-
|
369
|
-
loadModel(path);
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
|
374
|
-
|
375
417
|
void FrameWork::D3::Model::processNode(aiNode *node, const aiScene *scene)
|
376
418
|
|
377
419
|
{
|
@@ -382,6 +424,10 @@
|
|
382
424
|
|
383
425
|
{
|
384
426
|
|
427
|
+
//printf("push_back\n");
|
428
|
+
|
429
|
+
|
430
|
+
|
385
431
|
aiMesh *m = scene->mMeshes[node->mMeshes[i]];
|
386
432
|
|
387
433
|
mesh.push_back(processMesh(m,scene));
|
@@ -394,6 +440,8 @@
|
|
394
440
|
|
395
441
|
{
|
396
442
|
|
443
|
+
//printf("再帰的\n");
|
444
|
+
|
397
445
|
processNode(node->mChildren[i],scene);
|
398
446
|
|
399
447
|
}
|
@@ -408,6 +456,8 @@
|
|
408
456
|
|
409
457
|
Assimp::Importer import;
|
410
458
|
|
459
|
+
//const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate);
|
460
|
+
|
411
461
|
const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs);
|
412
462
|
|
413
463
|
|
@@ -492,17 +542,39 @@
|
|
492
542
|
|
493
543
|
|
494
544
|
|
495
|
-
|
545
|
+
// texture coordinates
|
546
|
+
|
547
|
+
if(m->mTextureCoords != NULL)
|
548
|
+
|
549
|
+
{
|
550
|
+
|
551
|
+
glm::vec2 vec;
|
552
|
+
|
553
|
+
//vert.uv[0] = m->mTextureCoords[0][i].x;
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
}
|
558
|
+
|
559
|
+
else
|
560
|
+
|
561
|
+
{
|
562
|
+
|
563
|
+
//vert.uv[0] = 0.0f;
|
564
|
+
|
565
|
+
//vert.uv[1] = 0.0f;
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
}
|
496
570
|
|
497
571
|
ver.push_back(vert);
|
498
572
|
|
499
573
|
}
|
500
574
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
575
|
+
|
576
|
+
|
577
|
+
|
506
578
|
|
507
579
|
return Mesh(ver, idx, tex);
|
508
580
|
|
@@ -512,178 +584,4 @@
|
|
512
584
|
|
513
585
|
|
514
586
|
|
515
|
-
std::vector<FrameWork::D3::Texture> FrameWork::D3::Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type,std::string typeName)
|
516
|
-
|
517
|
-
{
|
518
|
-
|
519
|
-
std::vector<Texture> texture;
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
524
|
-
|
525
|
-
{
|
526
|
-
|
527
|
-
aiString str;
|
528
|
-
|
529
|
-
mat->GetTexture(type, i, &str);
|
530
|
-
|
531
|
-
bool skip = false;
|
532
|
-
|
533
|
-
for(unsigned int j = 0; j < textures_loaded.size(); j++)
|
534
|
-
|
535
|
-
{
|
536
|
-
|
537
|
-
if(std::strcmp(textures_loaded[j].path.data, str.C_Str()) == 0)
|
538
|
-
|
539
|
-
{
|
540
|
-
|
541
|
-
texture.push_back(textures_loaded[j]);
|
542
|
-
|
543
|
-
skip = true;
|
544
|
-
|
545
|
-
break;
|
546
|
-
|
547
|
-
}
|
548
|
-
|
549
|
-
}
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
if(!skip)
|
554
|
-
|
555
|
-
{
|
556
|
-
|
557
|
-
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
558
|
-
|
559
|
-
{
|
560
|
-
|
561
|
-
aiString str;
|
562
|
-
|
563
|
-
mat->GetTexture(type, i, &str);
|
564
|
-
|
565
|
-
Texture tex;
|
566
|
-
|
567
|
-
tex.id = TextureFromFile(str.C_Str(), directory);
|
568
|
-
|
569
|
-
tex.type = typeName;
|
570
|
-
|
571
|
-
tex.path = str;
|
572
|
-
|
573
|
-
texture.push_back(tex);
|
574
|
-
|
575
|
-
}
|
576
|
-
|
577
|
-
}
|
578
|
-
|
579
|
-
}
|
580
|
-
|
581
|
-
return texture;
|
582
|
-
|
583
|
-
}
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
unsigned int FrameWork::D3::Model::TextureFromFile(const char *path, const std::string &directory)
|
590
|
-
|
591
|
-
{
|
592
|
-
|
593
|
-
std::string filename = std::string(path);
|
594
|
-
|
595
|
-
filename = directory + '/' + filename;
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
unsigned int textureID;
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
// glGenTextures(1, &textureID);
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
int width, height, nrComponents;
|
608
|
-
|
609
|
-
unsigned char *data = NULL;// = stbi_load(filename.c_str(), &width, &height, &nrComponents, 0);
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
if (data != NULL)
|
614
|
-
|
615
|
-
{
|
616
|
-
|
617
|
-
GLenum format;
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
if (nrComponents == 1)
|
622
|
-
|
623
|
-
{
|
624
|
-
|
625
|
-
format = GL_RED;
|
626
|
-
|
627
|
-
}
|
628
|
-
|
629
|
-
else if (nrComponents == 3)
|
630
|
-
|
631
|
-
{
|
632
|
-
|
633
|
-
format = GL_RGB;
|
634
|
-
|
635
|
-
}
|
636
|
-
|
637
|
-
else if (nrComponents == 4)
|
638
|
-
|
639
|
-
{
|
640
|
-
|
641
|
-
format = GL_RGBA;
|
642
|
-
|
643
|
-
}
|
644
|
-
|
645
|
-
}
|
646
|
-
|
647
|
-
else
|
648
|
-
|
649
|
-
{
|
650
|
-
|
651
|
-
//std::cerr << "Texture failed to load at path: " << path << std::endl;
|
652
|
-
|
653
|
-
//stbi_image_free(data);
|
654
|
-
|
655
|
-
}
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
return textureID;
|
660
|
-
|
661
|
-
}
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
void FrameWork::D3::Model::Draw(glm::vec3 pos)
|
668
|
-
|
669
|
-
{
|
670
|
-
|
671
|
-
for(unsigned int i = 0; i < mesh.size(); i++)
|
672
|
-
|
673
|
-
{
|
674
|
-
|
675
|
-
printf("あああ\n");
|
676
|
-
|
677
|
-
mesh[i].Draw();
|
678
|
-
|
679
|
-
printf("いいい\n");
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
}
|
684
|
-
|
685
|
-
}
|
686
|
-
|
687
|
-
|
688
|
-
|
689
587
|
```
|
5
タグを修正
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
4
文章を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
提示コードですが`Mesh::Draw()`関数の`shader.setUniformMatrix4fv("uTranslate",getMatTranslation());`関数で下記のエラーが出ます。これはなぜでしょうか?`Mesh`クラスのコンストラクタでシェーダーをロードして`SetUp`関数で頂点情報を設定してそれを`Draw()`関数で使っているのですが
|
2
|
+
|
3
|
+
なぜ-1のエラーが返ってくるのか原因がわりません。その他の2Dで円や矩形などの描画はこのクラスで行えるので`shader`クラスは問題ないです。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
Github: https://github.com/Shigurechan/GL
|
10
|
+
|
11
|
+
|
12
|
+
|
1
13
|
```command
|
2
14
|
|
3
15
|
$ ./GL
|
3
質問内容を変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
GLSL 変数を使っているのにglGetUniformLocation()関数で-1が返ってくる理由が知りたい。
|
test
CHANGED
@@ -1,38 +1,122 @@
|
|
1
|
+
```command
|
2
|
+
|
3
|
+
$ ./GL
|
4
|
+
|
5
|
+
this->vertex: 24
|
6
|
+
|
7
|
+
this->index: 0
|
8
|
+
|
9
|
+
this->texture: 0
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
あああ
|
14
|
+
|
1
|
-
|
15
|
+
GL: source/Shader.cpp:295: void FrameWork::Shader::setUniformMatrix4fv(const char*, glm::mat4): Assertion `0' failed.
|
2
16
|
|
3
17
|
|
4
18
|
|
5
19
|
```
|
6
20
|
|
21
|
+
|
22
|
+
|
7
|
-
|
23
|
+
```Shader.cpp
|
8
|
-
|
9
|
-
|
24
|
+
|
10
|
-
|
11
|
-
node->mNumMeshes: 0
|
12
|
-
|
13
|
-
|
25
|
+
// ##################################### mat4 #####################################
|
14
|
-
|
15
|
-
|
26
|
+
|
16
|
-
|
17
|
-
node->mNumChildren: 0
|
18
|
-
|
19
|
-
node->mNumMeshes: 2
|
20
|
-
|
21
|
-
らららららら: 2147483647
|
22
|
-
|
23
|
-
m->mNumFaces: 6624
|
24
|
-
|
25
|
-
Se
|
27
|
+
void FrameWork::Shader::setUniformMatrix4fv(const char* name, const glm::mat4 m)
|
28
|
+
|
26
|
-
|
29
|
+
{
|
30
|
+
|
27
|
-
|
31
|
+
const GLuint object = glGetUniformLocation(program, name);
|
32
|
+
|
33
|
+
if (object == -1) { assert(0); } //エラー処理
|
34
|
+
|
35
|
+
glUniformMatrix4fv(object, 1, false, glm::value_ptr(m));
|
36
|
+
|
37
|
+
}
|
28
38
|
|
29
39
|
```
|
30
40
|
|
31
41
|
|
32
42
|
|
33
|
-
|
43
|
+
```vert
|
44
|
+
|
34
|
-
|
45
|
+
/*#########################################################################
|
46
|
+
|
35
|
-
|
47
|
+
#
|
48
|
+
|
49
|
+
###########################################################################*/
|
50
|
+
|
51
|
+
#version 420
|
52
|
+
|
53
|
+
//#extension GL_ARB_explicit_uniform_location : require
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
layout(location = 0) in vec3 vertexPosition;
|
60
|
+
|
61
|
+
//layout(location = 1) in vec2 vertexUV;
|
62
|
+
|
63
|
+
//layout(location = 2) in vec3 vertexNormal;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//layout(location = 3) out vec2 vUV;
|
70
|
+
|
71
|
+
layout(location = 1) out vec4 vFragment;
|
72
|
+
|
73
|
+
//layout(location = 4) out vec3 vNormal;
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
uniform mat4 uTranslate;
|
82
|
+
|
83
|
+
uniform mat4 uRotate;
|
84
|
+
|
85
|
+
uniform mat4 uScale;
|
86
|
+
|
87
|
+
uniform mat4 uViewProjection;
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
uniform vec4 uFragment;
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
void main()
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
vec4 vertex = vec4(vertexPosition,1.0);
|
102
|
+
|
103
|
+
mat4 model = uTranslate * uRotate * uScale;
|
104
|
+
|
105
|
+
gl_Position = (uViewProjection * model) * vertex;
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
// vUV = vertexUV;
|
114
|
+
|
115
|
+
vFragment = uFragment;
|
116
|
+
|
117
|
+
// vNormal = vertexNormal;
|
118
|
+
|
119
|
+
}
|
36
120
|
|
37
121
|
```
|
38
122
|
|
@@ -40,6 +124,62 @@
|
|
40
124
|
|
41
125
|
|
42
126
|
|
127
|
+
```.frag
|
128
|
+
|
129
|
+
/*#########################################################################
|
130
|
+
|
131
|
+
#
|
132
|
+
|
133
|
+
###########################################################################*/
|
134
|
+
|
135
|
+
#version 420
|
136
|
+
|
137
|
+
//#extension GL_ARB_explicit_uniform_location : require
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
//layout(location = 3) in vec2 vUV;
|
144
|
+
|
145
|
+
layout(location = 1) in vec4 vfragment;
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
//layout(location = 4) in vec3 vNormal;
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
//uniform sampler2D uImage;
|
158
|
+
|
159
|
+
out vec4 fragment;
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
void main()
|
164
|
+
|
165
|
+
{
|
166
|
+
|
167
|
+
fragment = vfragment;
|
168
|
+
|
169
|
+
// fragment = texture(uImage,vUV);
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
```Mode.cpp
|
180
|
+
|
181
|
+
|
182
|
+
|
43
183
|
FrameWork::D3::Mesh::Mesh(std::vector<VertexAttribute> ver, std::vector<unsigned int> idx, std::vector<Texture> tex) : Transform()
|
44
184
|
|
45
185
|
{
|
@@ -64,7 +204,15 @@
|
|
64
204
|
|
65
205
|
//printf("あああ\n");
|
66
206
|
|
67
|
-
shader.Input(FrameWork::LoadShader("Shader/3D/BasicMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasicMono_3D.frag")->data())
|
207
|
+
if ( shader.Input(FrameWork::LoadShader("Shader/3D/BasicMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasicMono_3D.frag")->data()) == false)
|
208
|
+
|
209
|
+
{
|
210
|
+
|
211
|
+
printf("シェーダーロード失敗\n");
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
|
68
216
|
|
69
217
|
//printf("いいい\n");
|
70
218
|
|
@@ -84,7 +232,73 @@
|
|
84
232
|
|
85
233
|
{
|
86
234
|
|
87
|
-
|
235
|
+
shader.setEnable();
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
glBindVertexArray(VAO);
|
240
|
+
|
241
|
+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexAttribute) * vertex.size(), vertex.data());
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
//Transform
|
250
|
+
|
251
|
+
setPosition(glm::vec3(0,0,-20)); //座標
|
252
|
+
|
253
|
+
setScale(glm::vec3(10,10,10)); //スケール
|
254
|
+
|
255
|
+
setRotate(glm::vec3(0,0,0),0); //回転
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
//描画
|
260
|
+
|
261
|
+
shader.setUniformMatrix4fv("uTranslate",getMatTranslation());
|
262
|
+
|
263
|
+
shader.setUniformMatrix4fv("uRotate", getMatRotate());
|
264
|
+
|
265
|
+
shader.setUniformMatrix4fv("uScale", getMatScale());
|
266
|
+
|
267
|
+
shader.setUniform4f("uFragment", FrameWork::GetGlColor(glm::vec4(0,0,255,255)));
|
268
|
+
|
269
|
+
shader.setUniformMatrix4fv("uViewProjection", FrameWork::Camera::getViewProjection());
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
for(unsigned int i = 0; i < texture.size(); i++)
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
//glBindTexture(GL_TEXTURE_2D, texture[i].id);
|
278
|
+
|
279
|
+
//glActiveTexture(GL_TEXTURE0 + i);
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
//glDrawElements(GL_TRIANGLES, index.size(), GL_UNSIGNED_INT, 0);
|
286
|
+
|
287
|
+
glDrawArrays(GL_TRIANGLES,0,vertex.size());
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
//バインド解除
|
292
|
+
|
293
|
+
glBindVertexArray(0);
|
294
|
+
|
295
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
296
|
+
|
297
|
+
//glBindTexture(GL_TEXTURE_2D, 0);
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
shader.setDisable();
|
88
302
|
|
89
303
|
}
|
90
304
|
|
@@ -102,8 +316,6 @@
|
|
102
316
|
|
103
317
|
|
104
318
|
|
105
|
-
|
106
|
-
|
107
319
|
glBindVertexArray(VAO);
|
108
320
|
|
109
321
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
@@ -120,471 +332,313 @@
|
|
120
332
|
|
121
333
|
|
122
334
|
|
123
|
-
// vertex positions
|
124
|
-
|
125
|
-
|
335
|
+
GLint attrib = shader.getAttribLocation("vertexPosition");
|
126
|
-
|
336
|
+
|
127
|
-
glEnableVertexAttribArray(attrib);
|
337
|
+
glEnableVertexAttribArray(attrib);
|
128
|
-
|
338
|
+
|
129
|
-
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, sizeof(
|
339
|
+
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
|
130
340
|
|
131
341
|
shader.setBindAttribLocation("vertexPosition");
|
132
342
|
|
133
343
|
|
134
344
|
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
FrameWork::D3::Model::Model(const char *path)
|
354
|
+
|
355
|
+
{
|
356
|
+
|
357
|
+
loadModel(path);
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
void FrameWork::D3::Model::processNode(aiNode *node, const aiScene *scene)
|
364
|
+
|
365
|
+
{
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
for(unsigned int i = 0; i< node->mNumMeshes; i++)
|
370
|
+
|
371
|
+
{
|
372
|
+
|
373
|
+
aiMesh *m = scene->mMeshes[node->mMeshes[i]];
|
374
|
+
|
135
|
-
|
375
|
+
mesh.push_back(processMesh(m,scene));
|
376
|
+
|
136
|
-
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
for(unsigned int i = 0; i< node->mNumChildren; i++)
|
382
|
+
|
383
|
+
{
|
384
|
+
|
385
|
+
processNode(node->mChildren[i],scene);
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
void FrameWork::D3::Model::loadModel(const char *path)
|
394
|
+
|
395
|
+
{
|
396
|
+
|
397
|
+
Assimp::Importer import;
|
398
|
+
|
399
|
+
const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs);
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
if(scene == NULL)
|
404
|
+
|
405
|
+
{
|
406
|
+
|
407
|
+
std::cerr<<"ERROR::ASIMP: " << import.GetErrorString() <<std::endl;
|
408
|
+
|
409
|
+
assert(0);
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
std::string str(path);
|
416
|
+
|
417
|
+
|
418
|
+
|
137
|
-
|
419
|
+
directory = str.substr(0,str.find_last_of('/'));
|
138
|
-
|
420
|
+
|
421
|
+
|
422
|
+
|
139
|
-
|
423
|
+
processNode(scene->mRootNode, scene);
|
424
|
+
|
140
|
-
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
141
|
-
|
433
|
+
FrameWork::D3::Mesh FrameWork::D3::Model::processMesh(aiMesh *m, const aiScene *scene)
|
142
|
-
|
434
|
+
|
143
|
-
|
435
|
+
{
|
144
|
-
|
436
|
+
|
145
|
-
//
|
437
|
+
// data to fill
|
146
|
-
|
147
|
-
|
438
|
+
|
148
|
-
|
149
|
-
|
439
|
+
std::vector<VertexAttribute> ver(0);
|
150
|
-
|
440
|
+
|
151
|
-
|
441
|
+
std::vector<unsigned int> idx(0);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
442
|
+
|
157
|
-
|
443
|
+
std::vector<Texture> tex(0);
|
158
|
-
|
159
|
-
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
160
444
|
|
161
445
|
|
162
446
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
Assimp::Importer import;
|
216
|
-
|
217
|
-
const aiScene *scene = import.ReadFile(path,aiProcess_Triangulate | aiProcess_FlipUVs);
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
if(scene == NULL)
|
222
|
-
|
223
|
-
{
|
224
|
-
|
225
|
-
std::cerr<<"ERROR::ASIMP: " << import.GetErrorString() <<std::endl;
|
226
|
-
|
227
|
-
assert(0);
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
std::string str(path);
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
directory = str.substr(0,str.find_last_of('/'));
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
processNode(scene->mRootNode, scene);
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
FrameWork::D3::Mesh FrameWork::D3::Model::processMesh(aiMesh *m, const aiScene *scene)
|
252
|
-
|
253
|
-
{
|
254
|
-
|
255
|
-
// data to fill
|
256
|
-
|
257
|
-
std::vector<VertexAttribute> ver(0);
|
258
|
-
|
259
|
-
std::vector<unsigned int> idx(0);
|
260
|
-
|
261
|
-
std::vector<Texture> tex(0);
|
447
|
+
|
448
|
+
|
449
|
+
for(unsigned int i = 0; i < m->mNumVertices; i++)
|
450
|
+
|
451
|
+
{
|
452
|
+
|
453
|
+
VertexAttribute vert;
|
454
|
+
|
455
|
+
glm::vec3 vector;
|
456
|
+
|
457
|
+
vert.position[0] = m->mVertices[i].x;
|
458
|
+
|
459
|
+
vert.position[1] = m->mVertices[i].y;
|
460
|
+
|
461
|
+
vert.position[2] = m->mVertices[i].z;
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
// normals
|
466
|
+
|
467
|
+
if (m->HasNormals() == true)
|
468
|
+
|
469
|
+
{
|
470
|
+
|
471
|
+
//vert.normal[0] = m->mNormals[i].x;
|
472
|
+
|
473
|
+
//vert.normal[1] = m->mNormals[i].y;
|
474
|
+
|
475
|
+
//vert.normal[2] = m->mNormals[i].z;
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
}
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
ver.push_back(vert);
|
486
|
+
|
487
|
+
}
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
return Mesh(ver, idx, tex);
|
262
496
|
|
263
497
|
|
264
498
|
|
265
|
-
|
499
|
+
}
|
266
|
-
|
500
|
+
|
501
|
+
|
502
|
+
|
267
|
-
|
503
|
+
std::vector<FrameWork::D3::Texture> FrameWork::D3::Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type,std::string typeName)
|
268
|
-
|
504
|
+
|
269
|
-
|
505
|
+
{
|
270
|
-
|
506
|
+
|
271
|
-
|
507
|
+
std::vector<Texture> texture;
|
508
|
+
|
509
|
+
|
510
|
+
|
272
|
-
|
511
|
+
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
512
|
+
|
513
|
+
{
|
514
|
+
|
273
|
-
g
|
515
|
+
aiString str;
|
274
|
-
|
516
|
+
|
275
|
-
|
517
|
+
mat->GetTexture(type, i, &str);
|
276
|
-
|
518
|
+
|
277
|
-
|
519
|
+
bool skip = false;
|
278
|
-
|
520
|
+
|
279
|
-
|
521
|
+
for(unsigned int j = 0; j < textures_loaded.size(); j++)
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
// normals
|
284
|
-
|
285
|
-
if (m->HasNormals() == true)
|
286
522
|
|
287
523
|
{
|
288
524
|
|
525
|
+
if(std::strcmp(textures_loaded[j].path.data, str.C_Str()) == 0)
|
526
|
+
|
527
|
+
{
|
528
|
+
|
289
|
-
|
529
|
+
texture.push_back(textures_loaded[j]);
|
290
|
-
|
530
|
+
|
291
|
-
|
531
|
+
skip = true;
|
292
|
-
|
532
|
+
|
293
|
-
|
533
|
+
break;
|
534
|
+
|
294
|
-
|
535
|
+
}
|
295
|
-
|
296
536
|
|
297
537
|
}
|
298
538
|
|
299
539
|
|
300
540
|
|
301
|
-
// texture coordinates
|
302
|
-
|
303
|
-
if(
|
541
|
+
if(!skip)
|
304
542
|
|
305
543
|
{
|
306
544
|
|
545
|
+
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
546
|
+
|
547
|
+
{
|
548
|
+
|
549
|
+
aiString str;
|
550
|
+
|
551
|
+
mat->GetTexture(type, i, &str);
|
552
|
+
|
307
|
-
|
553
|
+
Texture tex;
|
308
|
-
|
309
|
-
|
554
|
+
|
310
|
-
|
311
|
-
//vert.uv[1] = m->mTextureCoords[0][i].y;
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
/*
|
316
|
-
|
317
|
-
// tangent
|
318
|
-
|
319
|
-
vector.x = m->mTangents[i].x;
|
320
|
-
|
321
|
-
vector.y = m->mTangents[i].y;
|
322
|
-
|
323
|
-
vector.z = m->mTangents[i].z;
|
324
|
-
|
325
|
-
//vert.Tangent = vector;
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
// bitangent
|
330
|
-
|
331
|
-
vector.x = m->mBitangents[i].x;
|
332
|
-
|
333
|
-
vector.y = m->mBitangents[i].y;
|
334
|
-
|
335
|
-
vector.z = m->mBitangents[i].z;
|
336
|
-
|
337
|
-
|
555
|
+
tex.id = TextureFromFile(str.C_Str(), directory);
|
556
|
+
|
338
|
-
|
557
|
+
tex.type = typeName;
|
558
|
+
|
339
|
-
|
559
|
+
tex.path = str;
|
560
|
+
|
561
|
+
texture.push_back(tex);
|
562
|
+
|
563
|
+
}
|
340
564
|
|
341
565
|
}
|
342
566
|
|
567
|
+
}
|
568
|
+
|
343
|
-
|
569
|
+
return texture;
|
570
|
+
|
571
|
+
}
|
572
|
+
|
573
|
+
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
unsigned int FrameWork::D3::Model::TextureFromFile(const char *path, const std::string &directory)
|
578
|
+
|
579
|
+
{
|
580
|
+
|
581
|
+
std::string filename = std::string(path);
|
582
|
+
|
583
|
+
filename = directory + '/' + filename;
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
unsigned int textureID;
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
// glGenTextures(1, &textureID);
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
int width, height, nrComponents;
|
596
|
+
|
597
|
+
unsigned char *data = NULL;// = stbi_load(filename.c_str(), &width, &height, &nrComponents, 0);
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
if (data != NULL)
|
602
|
+
|
603
|
+
{
|
604
|
+
|
605
|
+
GLenum format;
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
if (nrComponents == 1)
|
344
610
|
|
345
611
|
{
|
346
612
|
|
347
|
-
|
613
|
+
format = GL_RED;
|
348
|
-
|
349
|
-
//vert.uv[1] = 0.0f;
|
350
|
-
|
351
|
-
|
352
614
|
|
353
615
|
}
|
354
616
|
|
355
|
-
ver.push_back(vert);
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
//////////////////////////////////////////////////////////////////////////////////
|
360
|
-
|
361
|
-
/*
|
362
|
-
|
363
|
-
for(unsigned int i = 0; i < m->mNumFaces; i++)
|
364
|
-
|
365
|
-
{
|
366
|
-
|
367
|
-
|
617
|
+
else if (nrComponents == 3)
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
for(unsigned int j = 0; j < face.mNumIndices; j++)
|
372
618
|
|
373
619
|
{
|
374
620
|
|
375
|
-
|
621
|
+
format = GL_RGB;
|
376
622
|
|
377
623
|
}
|
378
624
|
|
379
|
-
}
|
380
|
-
|
381
|
-
*/
|
382
|
-
|
383
|
-
//////////////////////////////////////////////////////////////////////////////////
|
384
|
-
|
385
|
-
/*
|
386
|
-
|
387
|
-
printf("ああ %d\n",m->mMaterialIndex);
|
388
|
-
|
389
|
-
// process materials
|
390
|
-
|
391
|
-
aiMaterial* material = scene->mMaterials[m->mMaterialIndex];
|
392
|
-
|
393
|
-
|
625
|
+
else if (nrComponents == 4)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
// 1. diffuse maps
|
398
|
-
|
399
|
-
std::vector<Texture> diffuseMaps = loadMaterialTextures(material, aiTextureType_DIFFUSE, "texture_diffuse");
|
400
|
-
|
401
|
-
tex.insert(tex.end(), diffuseMaps.begin(), diffuseMaps.end());
|
402
|
-
|
403
|
-
// 2. specular maps
|
404
|
-
|
405
|
-
std::vector<Texture> specularMaps = loadMaterialTextures(material, aiTextureType_SPECULAR, "texture_specular");
|
406
|
-
|
407
|
-
tex.insert(tex.end(), specularMaps.begin(), specularMaps.end());
|
408
|
-
|
409
|
-
// 3. normal maps
|
410
|
-
|
411
|
-
std::vector<Texture> normalMaps = loadMaterialTextures(material, aiTextureType_HEIGHT, "texture_normal");
|
412
|
-
|
413
|
-
tex.insert(tex.end(), normalMaps.begin(), normalMaps.end());
|
414
|
-
|
415
|
-
// 4. height maps
|
416
|
-
|
417
|
-
std::vector<Texture> heightMaps = loadMaterialTextures(material, aiTextureType_AMBIENT, "texture_height");
|
418
|
-
|
419
|
-
tex.insert(tex.end(), heightMaps.begin(), heightMaps.end());
|
420
|
-
|
421
|
-
// return a mesh object created from the extracted mesh data
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
*/
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
return Mesh(ver, idx, tex);
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
std::vector<FrameWork::D3::Texture> FrameWork::D3::Model::loadMaterialTextures(aiMaterial *mat, aiTextureType type,std::string typeName)
|
438
|
-
|
439
|
-
{
|
440
|
-
|
441
|
-
std::vector<Texture> texture;
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
446
|
-
|
447
|
-
{
|
448
|
-
|
449
|
-
aiString str;
|
450
|
-
|
451
|
-
mat->GetTexture(type, i, &str);
|
452
|
-
|
453
|
-
bool skip = false;
|
454
|
-
|
455
|
-
for(unsigned int j = 0; j < textures_loaded.size(); j++)
|
456
626
|
|
457
627
|
{
|
458
628
|
|
459
|
-
if(std::strcmp(textures_loaded[j].path.data, str.C_Str()) == 0)
|
460
|
-
|
461
|
-
{
|
462
|
-
|
463
|
-
texture.push_back(textures_loaded[j]);
|
464
|
-
|
465
|
-
|
629
|
+
format = GL_RGBA;
|
466
|
-
|
467
|
-
break;
|
468
|
-
|
469
|
-
}
|
470
630
|
|
471
631
|
}
|
472
632
|
|
473
|
-
|
474
|
-
|
475
|
-
if(!skip)
|
476
|
-
|
477
|
-
{
|
478
|
-
|
479
|
-
for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
|
480
|
-
|
481
|
-
{
|
482
|
-
|
483
|
-
aiString str;
|
484
|
-
|
485
|
-
mat->GetTexture(type, i, &str);
|
486
|
-
|
487
|
-
Texture tex;
|
488
|
-
|
489
|
-
tex.id = TextureFromFile(str.C_Str(), directory);
|
490
|
-
|
491
|
-
tex.type = typeName;
|
492
|
-
|
493
|
-
tex.path = str;
|
494
|
-
|
495
|
-
texture.push_back(tex);
|
496
|
-
|
497
|
-
}
|
498
|
-
|
499
|
-
}
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
return texture;
|
504
|
-
|
505
|
-
}
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
unsigned int FrameWork::D3::Model::TextureFromFile(const char *path, const std::string &directory)
|
512
|
-
|
513
|
-
{
|
514
|
-
|
515
|
-
std::string filename = std::string(path);
|
516
|
-
|
517
|
-
filename = directory + '/' + filename;
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
unsigned int textureID;
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
// glGenTextures(1, &textureID);
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
int width, height, nrComponents;
|
530
|
-
|
531
|
-
unsigned char *data = stbi_load(filename.c_str(), &width, &height, &nrComponents, 0);
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
if (data != NULL)
|
536
|
-
|
537
|
-
{
|
538
|
-
|
539
|
-
GLenum format;
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
if (nrComponents == 1)
|
544
|
-
|
545
|
-
{
|
546
|
-
|
547
|
-
format = GL_RED;
|
548
|
-
|
549
|
-
}
|
550
|
-
|
551
|
-
else if (nrComponents == 3)
|
552
|
-
|
553
|
-
{
|
554
|
-
|
555
|
-
format = GL_RGB;
|
556
|
-
|
557
|
-
}
|
558
|
-
|
559
|
-
else if (nrComponents == 4)
|
560
|
-
|
561
|
-
{
|
562
|
-
|
563
|
-
format = GL_RGBA;
|
564
|
-
|
565
|
-
}
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
/*
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
stbi_image_free(data);
|
576
|
-
|
577
|
-
*/
|
578
|
-
|
579
633
|
}
|
580
634
|
|
581
635
|
else
|
582
636
|
|
583
637
|
{
|
584
638
|
|
585
|
-
std::cerr << "Texture failed to load at path: " << path << std::endl;
|
639
|
+
//std::cerr << "Texture failed to load at path: " << path << std::endl;
|
586
|
-
|
640
|
+
|
587
|
-
stbi_image_free(data);
|
641
|
+
//stbi_image_free(data);
|
588
642
|
|
589
643
|
}
|
590
644
|
|
@@ -606,13 +660,17 @@
|
|
606
660
|
|
607
661
|
{
|
608
662
|
|
663
|
+
printf("あああ\n");
|
664
|
+
|
609
665
|
mesh[i].Draw();
|
610
666
|
|
667
|
+
printf("いいい\n");
|
668
|
+
|
669
|
+
|
670
|
+
|
611
|
-
}
|
671
|
+
}
|
612
|
-
|
672
|
+
|
613
|
-
}
|
673
|
+
}
|
614
|
-
|
615
|
-
|
616
674
|
|
617
675
|
|
618
676
|
|
2
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,27 +36,37 @@
|
|
36
36
|
|
37
37
|
```
|
38
38
|
|
39
|
-
|
39
|
+
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
|
41
|
+
|
42
|
+
|
45
|
-
FrameWork::D3::Mesh::Mesh(std::vector<VertexAttribute> ver, std::vector<unsigned int> idx, std::vector<Texture> tex)
|
43
|
+
FrameWork::D3::Mesh::Mesh(std::vector<VertexAttribute> ver, std::vector<unsigned int> idx, std::vector<Texture> tex) : Transform()
|
46
|
-
|
44
|
+
|
47
|
-
{
|
45
|
+
{
|
48
|
-
|
46
|
+
|
49
|
-
this->vertex = ver;
|
47
|
+
this->vertex = ver; //頂点
|
50
|
-
|
48
|
+
|
51
|
-
this->index = idx;
|
49
|
+
this->index = idx; //インデックス
|
52
|
-
|
50
|
+
|
53
|
-
this->texture = tex;
|
51
|
+
this->texture = tex; //テクスチャ
|
52
|
+
|
53
|
+
|
54
|
+
|
54
|
-
|
55
|
+
printf("this->vertex: %d\n",this->vertex.size());
|
56
|
+
|
55
|
-
|
57
|
+
printf("this->index: %d\n",this->index.size());
|
58
|
+
|
56
|
-
|
59
|
+
printf("this->texture: %d\n\n",this->texture.size());
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
//printf("あああ\n");
|
66
|
+
|
57
|
-
shader.Input(FrameWork::LoadShader("Shader/3D/BasiMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasiMono_3D.frag")->data());
|
67
|
+
shader.Input(FrameWork::LoadShader("Shader/3D/BasicMono_3D.vert")->data(), FrameWork::LoadShader("Shader/3D/BasicMono_3D.frag")->data());
|
68
|
+
|
58
|
-
|
69
|
+
//printf("いいい\n");
|
59
|
-
|
60
70
|
|
61
71
|
|
62
72
|
|
@@ -74,7 +84,7 @@
|
|
74
84
|
|
75
85
|
{
|
76
86
|
|
77
|
-
|
87
|
+
|
78
88
|
|
79
89
|
}
|
80
90
|
|
@@ -84,7 +94,71 @@
|
|
84
94
|
|
85
95
|
{
|
86
96
|
|
87
|
-
|
97
|
+
glGenVertexArrays(1, &VAO);
|
98
|
+
|
99
|
+
glGenBuffers(1, &VBO);
|
100
|
+
|
101
|
+
//glGenBuffers(1, &EBO);
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
glBindVertexArray(VAO);
|
108
|
+
|
109
|
+
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
//glBufferData(GL_ELEMENT_ARRAY_BUFFER, index.size() * sizeof(unsigned int),index.data(), GL_DYNAMIC_DRAW);
|
118
|
+
|
119
|
+
glBufferData(GL_ARRAY_BUFFER, vertex.size() * sizeof(VertexAttribute), vertex.data(), GL_DYNAMIC_DRAW);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
// vertex positions
|
124
|
+
|
125
|
+
GLint attrib = shader.getAttribLocation("vertexPosition");
|
126
|
+
|
127
|
+
glEnableVertexAttribArray(attrib);
|
128
|
+
|
129
|
+
glVertexAttribPointer(attrib, 1, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)0);
|
130
|
+
|
131
|
+
shader.setBindAttribLocation("vertexPosition");
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
// vertex texture coords
|
136
|
+
|
137
|
+
//attrib = shader.getAttribLocation("vertexUV");
|
138
|
+
|
139
|
+
//glEnableVertexAttribArray(attrib);
|
140
|
+
|
141
|
+
//glVertexAttribPointer(attrib, 2, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 3));
|
142
|
+
|
143
|
+
printf("ららら\n");
|
144
|
+
|
145
|
+
// vertex normals
|
146
|
+
|
147
|
+
//attrib = shader.getAttribLocation("vertexNormal");
|
148
|
+
|
149
|
+
//glEnableVertexAttribArray(attrib);
|
150
|
+
|
151
|
+
//glVertexAttribPointer(attrib, 3, GL_FLOAT, GL_FALSE, sizeof(VertexAttribute), (void*)(sizeof(GLfloat) * 5));
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
glBindVertexArray(0);
|
158
|
+
|
159
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
160
|
+
|
161
|
+
|
88
162
|
|
89
163
|
}
|
90
164
|
|
@@ -108,8 +182,6 @@
|
|
108
182
|
|
109
183
|
{
|
110
184
|
|
111
|
-
printf("node->mNumMeshes: %d\n",node->mNumMeshes);
|
112
|
-
|
113
185
|
|
114
186
|
|
115
187
|
for(unsigned int i = 0; i< node->mNumMeshes; i++)
|
@@ -124,12 +196,6 @@
|
|
124
196
|
|
125
197
|
|
126
198
|
|
127
|
-
|
128
|
-
|
129
|
-
printf("node->mNumChildren: %d\n",node->mNumChildren);
|
130
|
-
|
131
|
-
|
132
|
-
|
133
199
|
for(unsigned int i = 0; i< node->mNumChildren; i++)
|
134
200
|
|
135
201
|
{
|
@@ -138,10 +204,6 @@
|
|
138
204
|
|
139
205
|
}
|
140
206
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
207
|
}
|
146
208
|
|
147
209
|
|
@@ -156,7 +218,7 @@
|
|
156
218
|
|
157
219
|
|
158
220
|
|
159
|
-
if(
|
221
|
+
if(scene == NULL)
|
160
222
|
|
161
223
|
{
|
162
224
|
|
@@ -176,14 +238,8 @@
|
|
176
238
|
|
177
239
|
|
178
240
|
|
179
|
-
printf("ああああ\n");
|
180
|
-
|
181
|
-
|
182
|
-
|
183
241
|
processNode(scene->mRootNode, scene);
|
184
242
|
|
185
|
-
printf("うううううう\n");
|
186
|
-
|
187
243
|
}
|
188
244
|
|
189
245
|
|
@@ -198,15 +254,15 @@
|
|
198
254
|
|
199
255
|
// data to fill
|
200
256
|
|
201
|
-
std::vector<VertexAttribute> ver;
|
257
|
+
std::vector<VertexAttribute> ver(0);
|
202
|
-
|
258
|
+
|
203
|
-
std::vector<unsigned int> idx;
|
259
|
+
std::vector<unsigned int> idx(0);
|
204
|
-
|
260
|
+
|
205
|
-
std::vector<Texture> tex;
|
261
|
+
std::vector<Texture> tex(0);
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
210
266
|
|
211
267
|
for(unsigned int i = 0; i < m->mNumVertices; i++)
|
212
268
|
|
@@ -214,11 +270,7 @@
|
|
214
270
|
|
215
271
|
VertexAttribute vert;
|
216
272
|
|
217
|
-
glm::vec3 vector;
|
218
|
-
|
219
|
-
// positions
|
220
|
-
|
221
|
-
// printf("てててててててて\n");
|
273
|
+
glm::vec3 vector;
|
222
274
|
|
223
275
|
vert.position[0] = m->mVertices[i].x;
|
224
276
|
|
@@ -234,11 +286,11 @@
|
|
234
286
|
|
235
287
|
{
|
236
288
|
|
237
|
-
vert.normal[0] = m->mNormals[i].x;
|
289
|
+
//vert.normal[0] = m->mNormals[i].x;
|
238
|
-
|
290
|
+
|
239
|
-
vert.normal[1] = m->mNormals[i].y;
|
291
|
+
//vert.normal[1] = m->mNormals[i].y;
|
240
|
-
|
292
|
+
|
241
|
-
vert.normal[2] = m->mNormals[i].z;
|
293
|
+
//vert.normal[2] = m->mNormals[i].z;
|
242
294
|
|
243
295
|
|
244
296
|
|
@@ -246,25 +298,17 @@
|
|
246
298
|
|
247
299
|
|
248
300
|
|
249
|
-
// printf("ええええ\n");
|
250
|
-
|
251
|
-
|
252
|
-
|
253
301
|
// texture coordinates
|
254
302
|
|
255
|
-
if(m->mTextureCoords != NULL)
|
303
|
+
if(m->mTextureCoords != NULL)
|
256
304
|
|
257
305
|
{
|
258
306
|
|
259
307
|
glm::vec2 vec;
|
260
308
|
|
261
|
-
// a vert can contain up to 8 different texture coordinates. We thus make the assumption that we won't
|
262
|
-
|
263
|
-
// use models where a vert can have multiple texture coordinates so we always take the first set (0).
|
264
|
-
|
265
|
-
vert.uv[0] = m->mTextureCoords[0][i].x;
|
309
|
+
//vert.uv[0] = m->mTextureCoords[0][i].x;
|
266
|
-
|
310
|
+
|
267
|
-
vert.uv[1] = m->mTextureCoords[0][i].y;
|
311
|
+
//vert.uv[1] = m->mTextureCoords[0][i].y;
|
268
312
|
|
269
313
|
|
270
314
|
|
@@ -300,9 +344,9 @@
|
|
300
344
|
|
301
345
|
{
|
302
346
|
|
303
|
-
vert.uv[0] = 0.0f;
|
347
|
+
//vert.uv[0] = 0.0f;
|
304
|
-
|
348
|
+
|
305
|
-
vert.uv[1] = 0.0f;
|
349
|
+
//vert.uv[1] = 0.0f;
|
306
350
|
|
307
351
|
|
308
352
|
|
@@ -310,21 +354,9 @@
|
|
310
354
|
|
311
355
|
ver.push_back(vert);
|
312
356
|
|
313
|
-
// printf("yoyoyoyoyoyo\n");
|
314
|
-
|
315
357
|
}
|
316
358
|
|
317
|
-
//////////////////////////////////////////////////////////////////////////////////
|
359
|
+
//////////////////////////////////////////////////////////////////////////////////
|
318
|
-
|
319
|
-
printf("らららららら: %d\n",AI_MAX_FACES);
|
320
|
-
|
321
|
-
printf("m->mNumFaces: %d\n",m->mNumFaces);
|
322
|
-
|
323
|
-
printf("m->mFaces: %d\n",m->mFaces[0]);
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
printf("っっっっっっっっっっっっっっ\n");
|
328
360
|
|
329
361
|
/*
|
330
362
|
|
@@ -332,14 +364,8 @@
|
|
332
364
|
|
333
365
|
{
|
334
366
|
|
335
|
-
printf(" いいいいいい\n");
|
336
|
-
|
337
|
-
|
338
|
-
|
339
367
|
aiFace face = m->mFaces[i];
|
340
368
|
|
341
|
-
printf("ああああああ\n");
|
342
|
-
|
343
369
|
|
344
370
|
|
345
371
|
for(unsigned int j = 0; j < face.mNumIndices; j++)
|
@@ -350,31 +376,23 @@
|
|
350
376
|
|
351
377
|
}
|
352
378
|
|
353
|
-
|
354
|
-
|
355
379
|
}
|
356
380
|
|
357
381
|
*/
|
358
382
|
|
359
|
-
//////////////////////////////////////////////////////////////////////////////////
|
383
|
+
//////////////////////////////////////////////////////////////////////////////////
|
384
|
+
|
360
|
-
|
385
|
+
/*
|
386
|
+
|
361
|
-
printf("
|
387
|
+
printf("ああ %d\n",m->mMaterialIndex);
|
362
388
|
|
363
389
|
// process materials
|
364
390
|
|
365
391
|
aiMaterial* material = scene->mMaterials[m->mMaterialIndex];
|
366
392
|
|
367
|
-
// we assume a convention for sampler names in the shaders. Each diffuse texture should be named
|
368
|
-
|
369
|
-
// as 'texture_diffuseN' where N is a sequential number ranging from 1 to MAX_SAMPLER_NUMBER.
|
370
|
-
|
371
|
-
// Same applies to other texture as the following list summarizes:
|
372
|
-
|
373
|
-
// diffuse: texture_diffuseN
|
374
|
-
|
375
|
-
// specular: texture_specularN
|
376
|
-
|
377
|
-
|
393
|
+
printf("いいい \n");
|
394
|
+
|
395
|
+
|
378
396
|
|
379
397
|
// 1. diffuse maps
|
380
398
|
|
@@ -402,7 +420,13 @@
|
|
402
420
|
|
403
421
|
// return a mesh object created from the extracted mesh data
|
404
422
|
|
423
|
+
|
424
|
+
|
425
|
+
*/
|
426
|
+
|
427
|
+
|
428
|
+
|
405
|
-
|
429
|
+
return Mesh(ver, idx, tex);
|
406
430
|
|
407
431
|
|
408
432
|
|
@@ -436,11 +460,11 @@
|
|
436
460
|
|
437
461
|
{
|
438
462
|
|
439
|
-
texture.push_back(textures_loaded[j]);
|
463
|
+
texture.push_back(textures_loaded[j]);
|
440
|
-
|
464
|
+
|
441
|
-
skip = true;
|
465
|
+
skip = true;
|
442
|
-
|
466
|
+
|
443
|
-
break;
|
467
|
+
break;
|
444
468
|
|
445
469
|
}
|
446
470
|
|
@@ -496,7 +520,9 @@
|
|
496
520
|
|
497
521
|
unsigned int textureID;
|
498
522
|
|
523
|
+
|
524
|
+
|
499
|
-
glGenTextures(1, &textureID);
|
525
|
+
// glGenTextures(1, &textureID);
|
500
526
|
|
501
527
|
|
502
528
|
|
@@ -506,7 +532,7 @@
|
|
506
532
|
|
507
533
|
|
508
534
|
|
509
|
-
if (data)
|
535
|
+
if (data != NULL)
|
510
536
|
|
511
537
|
{
|
512
538
|
|
@@ -540,33 +566,23 @@
|
|
540
566
|
|
541
567
|
|
542
568
|
|
543
|
-
glBindTexture(GL_TEXTURE_2D, textureID);
|
544
|
-
|
545
|
-
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
|
546
|
-
|
547
|
-
|
569
|
+
/*
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
570
|
+
|
552
|
-
|
553
|
-
|
571
|
+
|
554
|
-
|
555
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
556
|
-
|
557
|
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
558
572
|
|
559
573
|
|
560
574
|
|
561
575
|
stbi_image_free(data);
|
562
576
|
|
577
|
+
*/
|
578
|
+
|
563
579
|
}
|
564
580
|
|
565
581
|
else
|
566
582
|
|
567
583
|
{
|
568
584
|
|
569
|
-
std::c
|
585
|
+
std::cerr << "Texture failed to load at path: " << path << std::endl;
|
570
586
|
|
571
587
|
stbi_image_free(data);
|
572
588
|
|
@@ -586,15 +602,17 @@
|
|
586
602
|
|
587
603
|
{
|
588
604
|
|
589
|
-
for(unsigned int i = 0; i < mesh.size(); i++)
|
605
|
+
for(unsigned int i = 0; i < mesh.size(); i++)
|
590
|
-
|
606
|
+
|
591
|
-
{
|
607
|
+
{
|
592
|
-
|
608
|
+
|
593
|
-
mesh[i].Draw();
|
609
|
+
mesh[i].Draw();
|
594
|
-
|
610
|
+
|
595
|
-
}
|
611
|
+
}
|
596
|
-
|
612
|
+
|
597
|
-
}
|
613
|
+
}
|
614
|
+
|
615
|
+
|
598
616
|
|
599
617
|
|
600
618
|
|
1
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
提示コードの`processMesh` 関数部ですがコメント部の行で`m->mFaces[0]`配列にアクセスするとセグメンテーションエラーが出ます。これはなぜアクセスエラーが出るのでしょうか?上の行で要素の数を確認していますがかなりの数がるので0番目の配列はアクセス出来るはずです。原因がわかりません
|
1
|
+
提示コードの`processMesh` 関数部ですがコメント部の行で`m->mFaces[0]`配列にアクセスするとセグメンテーションエラーが出ます。これはなぜアクセスエラーが出るのでしょうか?上の行で要素の数を確認していますがかなりの数がるので0番目の配列はアクセス出来るはずです。原因がわかりません
|
2
2
|
|
3
3
|
|
4
4
|
|