annotate dmscene.cpp @ 107:2b30217a3c39 default tip

Fix verbose build echos.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 29 Feb 2024 21:48:47 +0200
parents 03aa729a9e90
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
2 // GLDragon - OpenGL PLY model viewer / simple benchmark
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
3 // -- Scene file handling
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
5 // (C) Copyright 2019 Tecnic Software productions (TNSP)
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
7 // See file "COPYING" for license information.
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 //
61
7b138613e2fc Rename dmmodel.* to dmscene.*
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
9 #include "dmscene.h"
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
12 bool dmParseVector(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMVector3 &vec)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
13 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
14 if (tokens.size() == offs + 1)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
15 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
16 vec.x = vec.y = vec.z = std::stof(tokens[offs]);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
17 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
18 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
19 if (tokens.size() == offs + 3)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
20 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
21 vec.x = std::stof(tokens[offs]);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
22 vec.y = std::stof(tokens[offs + 1]);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
23 vec.z = std::stof(tokens[offs + 2]);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
24 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
25 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
26 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
27 return info.syntaxError(
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
28 "Expected 1/3 value vector for '"+ *info.key +"'");
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
29 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
30
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
31 return true;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
32 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
33
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
34
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
35 bool dmParseVector(DMTextFileInfo &info, const std::vector<std::string> tokens, const size_t offs, DMVector4 &vec)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
36 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
37 if (tokens.size() == offs + 1)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
38 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
39 vec.p.x = vec.p.y = vec.p.z = std::stof(tokens[offs]);
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
40 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
41 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
42 if (tokens.size() == offs + 3 || tokens.size() == offs + 4)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
43 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
44 vec.p.x = std::stof(tokens[offs]);
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
45 vec.p.y = std::stof(tokens[offs + 1]);
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
46 vec.p.z = std::stof(tokens[offs + 2]);
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
47
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
48 if (tokens.size() == offs + 4)
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
49 vec.p.w = std::stof(tokens[offs + 3]);
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
50 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
51 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
52 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
53 return info.syntaxError(
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
54 "Expected 1/3/4 value vector for '"+ *info.key +"'");
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
55 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
56
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
57 return true;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
58 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
59
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
60
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 bool DMSimpleScene::loadInfo(const std::string &filename)
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 DMTextFileInfo info;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
64 DMModel *model = 0;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
65 DMLight *light = 0;
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
66 DMVector4 *ppos = 0, *ppointAt = 0;
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
67 DMMaterial *pmat = 0;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 info.filename = filename;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 info.nline = info.state = 0;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 info.file.open(info.filename.c_str(), std::fstream::in | std::fstream::binary);
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
73 dmMsg("Trying to read scene data from '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 info.filename.c_str());
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if (!info.file.is_open())
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
78 dmError("Unable to open file '%s'.\n",
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 info.filename.c_str());
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 return false;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 while (info.state >= 0)
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 // Read one line
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
86 if (!info.readLine())
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 {
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 info.state = -1;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 break;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 // Skip empty lines and comments
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 if (info.line.empty() ||
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 info.line[0] == '#' ||
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 info.line[0] == ';')
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 continue;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 // Split key and values
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 std::vector<std::string> tokens = dmStrSplit(info.line);
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
100 std::string key = tokens[0];
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
101 info.key = &key;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
103 if (key == "model")
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
105 DMModel newmodel;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
106 if (tokens.size() != 2)
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
108 return info.syntaxError(
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
109 "Keyword model expects a filename argument");
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
112 models.push_back(newmodel);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
113 model = &models.back();
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
114 model->modelFile = tokens[1];
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
115 pmat = &model->material;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
116 info.state = 1;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 else
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
119 if (info.state == 1 && (key == "shaderfile"))
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
120 {
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
121 if (tokens.size() != 3)
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
122 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
123 return info.syntaxError(
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
124 "Keyword shaderfile expects shader type (fs, vs) and filename arguments");
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
125 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
126
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
127 std::string
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
128 &shtype = tokens[1],
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
129 &shfile = tokens[2];
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
130
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
131 if (shtype == "fs")
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
132 model->fragShaderFile = shfile;
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
133 else
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
134 if (shtype == "vs")
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
135 model->vertShaderFile = shfile;
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
136 else
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
137 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
138 return info.syntaxError(
33
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
139 "Invalid shaderfile type '"+ shtype +"'");
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
140 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
141 }
2e85c180afdf Add support for specifying shader file filenames in the scene for each model.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
142 else
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
143 if (info.state == 1 && (key == "translate" || key == "rotate" || key == "scale"))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
144 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
145 DMVector3 vec;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
147 if (!dmParseVector(info, tokens, 1, vec))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
148 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
149
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
150 if (!model)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
151 return false;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 if (key == "translate")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
154 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
155 model->translate = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
156 model->translateSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
157 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 if (key == "rotate")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
160 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
161 model->rotate = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
162 model->rotateSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
163 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 if (key == "scale")
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
166 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
167 model->scale = vec;
36
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
168 model->scaleSet = true;
d640f2a34031 Only scale/translate/rotate the model if those attributes have been set in the scenefile.
Matti Hamalainen <ccr@tnsp.org>
parents: 33
diff changeset
169 }
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 else
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
172 if (info.state == 1 && key == "shininess")
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
173 {
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
174 if (tokens.size() != 2)
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
175 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
176 return info.syntaxError(
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
177 "Expected argument for shininess");
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
178 }
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
179
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
180 model->material.shininess = std::stoi(tokens[1], 0, 0);
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
181 }
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
182 else
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 if (key == "light")
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 {
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
185 DMLight newlight;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
186
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
187 if (lights.size() >= 4)
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
189 return info.textError(
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
190 "Too many lights defined (max 4)");
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 }
32
1215fdd0a8ab Add support for specifying specular and shininess values per model.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
192
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
193 lights.push_back(newlight);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
194 light = &lights.back();
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
195 ppos = &light->position;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
196 ppointAt = &light->pointAt;
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
197 pmat = &light->color;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
198 info.state = 2;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
199 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
200 else
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
201 if ((info.state == 1 || info.state == 2) &&
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
202 (key == "ambient" || key == "diffuse" || key == "specular"))
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
203 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
204 DMVector4 val;
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
205 val.c.a = 1.0f;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
206
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
207 if (!dmParseVector(info, tokens, 1, val))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
208 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
209
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
210 if (key == "ambient")
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
211 pmat->ambient = val;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212 else
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
213 if (key == "diffuse")
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
214 pmat->diffuse = val;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
215 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
216 if (key == "specular")
48
0ae1ff609626 Implement diffuse setting for models in scenefile. Also refactor
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
217 pmat->specular = val;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
218 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
219 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
220 if (key == "camera")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
221 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
222 info.state = 3;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
223
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
224 ppos = &camera.position;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
225 ppointAt = &camera.pointAt;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
226 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
227 else
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
228 if ((info.state == 3 || info.state == 2) &&
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
229 (key == "position" || key == "pos" || key == "point_at"))
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
230 {
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
231 DMVector4 vec;
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
232 vec.p.w = 0;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
233
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
234 if (!dmParseVector(info, tokens, 1, vec))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
235 return false;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
236
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 22
diff changeset
237 if (key == "position" || key == "pos")
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
238 *ppos = vec;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
239 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
240 if (key == "point_at")
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
241 *ppointAt = vec;
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 else
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
245 return info.syntaxError(
19
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 "Unexpected key '"+ key +"'");
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 }
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 return true;
a329f0216491 Implement PLY file format parsing and extremely simplistic scene setup file format.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 }