NDEVR
API Documentation
BlockModelFactory.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: IOFactory
28File: BlockModelFactory
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/FactoryOptions.h>
34#include <NDEVR/BlockGeometry.h>
35#include "Base/Headers/Scanner.h"
36#include "Base/Headers/Translator.h"
37#include "Base/Headers/Exception.h"
38
39namespace NDEVR
40{
45 {
46 public:
47 static void readFile(File& file, Model& model, const FactoryOptions&)
48 {
49 Scanner scanner(file);
50
51
52 Vector<2, fltp08> offset;
54 Vector<2, uint04> index_size;
55 Geometry geo = model.createChildGeometry();
56 BlockGeometry grid_mesh(geo);
57 scanner.nextLine(); offset[Y] = scanner.getNext<fltp08>();
58 scanner.nextLine(); offset[X] = scanner.getNext<fltp08>();
59 scanner.nextLine(); size[Y] = scanner.getNext<fltp08>() - offset[Y];
60 scanner.nextLine(); size[X] = scanner.getNext<fltp08>() - offset[X];
61
62
63 scanner.nextLine(); index_size[X] = scanner.getNext<uint04>() + 1;
64 scanner.nextLine(); index_size[Y] = scanner.getNext<uint04>() + 1;
65
66 Vector<2, fltp08> scale = size / (index_size - 1U).as<2, fltp08>();
67
68 grid_mesh.setupVertexTable(Vector<3, uint04>(index_size, 10), Geometry::e_no_vertex);
69 uint04 extra_property = geo.createVertexProperty<fltp04>("Grid");
70 for (uint04 y = 0; y < index_size[Y]; y++)
71 {
72 for (uint04 x = 0; x < index_size[X]; x++)
73 {
74 if (!scanner.nextLine())
75 throw FileException(String(file), _t("Bad vertex size"));
76 grid_mesh.setVertexProperty(extra_property, x, y, 0, scanner.getNext<fltp04>());
77 }
78 }
79 for (uint04 i = 0; i < 10; i++)
80 {
81 for (uint04 y = 0; y < index_size[Y]; y++)
82 {
83 for (uint04 x = 0; x < index_size[X]; x++)
84 {
85 grid_mesh.setVertexProperty(extra_property, x, y, i, grid_mesh.vertexProperty<fltp04>(extra_property, x, y, 0));
86 }
87 }
88 }
89 Matrix<fltp08> trans(1);
90 trans = trans.offset(offset);
91 trans = trans.scale(Vector<3, fltp08>(scale, 25.0f));
92 geo.set<NDPO::transform>(trans);
93
94 //grid_mesh.calculateGridNormals();
95
96 //Material mat = BlockModel::getDefaultMaterial(model);
97 /*mat.set<NDPM::shading_model>(Material::ShadingModelProperty::e_phong);
98
99 mat.setUVMode(UVType::e_KD, Material::UVMode::e_solid_color);
100 mat.setUVColor(UVType::e_KD, Vector<4, fltp04>(.5f, .5f, .5f, 1.0f));
101
102 mat.setUVMode(Material::e_KS, Material::UVMode::e_solid_color);
103 mat.setUVColor(Material::e_KS, Vector<4, fltp04>(.1f, .1f, .1f, 1.0f));*/
104 }
105 static bool canRead(const File& file)
106 {
107 if (file.endsWith(".grd", true))
108 return true;
109 return false;
110 }
111 };
112}
113
Reads block model data from .grd files into a Model's geometry.
void set(t_property_type property, const t_type &value)
Sets a property value in the database.
User-defined options that define preferences for importing and exporting using IOFactory objects.
An Exception that contains information about a runtime error with a particular File.
Definition Exception.h:43
Logic for reading or writing to a file as well as navigating filesystems or other common file operati...
Definition File.h:53
A core class within the model hierarchy containing vertex-based data (Usually 3D data) within a set c...
Definition Geometry.h:143
@ e_no_vertex
No vertex data present.
Definition Geometry.h:151
uint04 createVertexProperty(const StringView &property_name)
Creates a new custom vertex property column with a compile-time type.
Definition Geometry.h:1348
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
A core class that represents a node on model hierarchy.
Definition Model.h:292
Geometry createChildGeometry()
Creates a new child geometry for this model.
Contains methods for easily reading objects in an ascii stream using set deliminators and line logic.
Definition Scanner.h:47
t_type getNext()
Reads and returns the next token parsed as the specified type.
virtual bool nextLine()
Advances the scanner to the next line in the stream.
The core String class for the NDEVR API.
Definition String.h:95
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ file
The source file path associated with this object.
@ transform
A 4x4 transform matrix that maps local coordinates into global space.