Commit 35bccd7c authored by Johannes Braun's avatar Johannes Braun
Browse files

Began binary mesh file

parent 29478ae8
<scene version="1.0">
<!--
any "source" tag will work as a replacement for all inner parameters.
Therefore, you can put item-sub-tags (for example all "property" tags) into a dedicated file.
All properties which are not given will be set to their according default value.
-->
<textures>
<item id="mat_001_spec" source="file::textures/mat_001_spec.png"/>
<item id="posx" source="file::textures/cm/posx.png"/>
<item id="posy" source="file::textures/cm/posy.png"/>
<item id="posz" source="file::textures/cm/posz.png"/>
<item id="negx" source="file::textures/cm/negx.png"/>
<item id="negy" source="file::textures/cm/negy.png"/>
<item id="negz" source="file::textures/cm/negz.png"/>
</textures>
<materials>
<item id="material.001">
<property name="diffuse" type="color" value="0 0.5 0.8 1"/>
<property name="specular" type="texture" value="textures::mat_001_spec"/>
<property name="shininess" type="uint" value="100"/>
</item>
<!-- Load file containing the properties -->
<item id="material.002" source="file::materials/material.prop">
</materials>
<geometries>
<!-- Use an external binary mesh file format -->
<item id="cube" source="file::meshes/cubemesh.mesh">
</geometries>
<cameras>
<item id="cam_node.camera">
<property name="fov" type="float" value="60"/>
<property name="projection" type="string" value="ortho"/>
</item>
</cameras>
<lights>
<item id="some_light">
<property name="color" type="color" value="5 5 5 5"/>
<property name="type" type="string" value="point"/>
</item>
</lights>
<!--
Objects shall be initialized by themselves by giving them their according data.
That means that they could even have multiple definitions.
-->
<cubemaps>
<item id="my_cubemap">
<property name="type" type="string" value="collection"/>
<property name="collection_source" type="source" value="file::cubemaps/cubemap01"/>
</item>
<item id="my_other_cubemap">
<property name="type" type="string" value="items"/>
<property name="posx" type="source" value="textures::posx"/>
<property name="posy" type="source" value="textures::posy"/>
<property name="posz" type="source" value="textures::posz"/>
<property name="negx" type="source" value="textures::negx"/>
<property name="negy" type="source" value="textures::negy"/>
<property name="negz" type="source" value="textures::negz"/>
</item>
</cubemaps>
<!-- Add your very own component types to be attached to the objects -->
<your_very_own_component_type>
<item id="my_own_component">
<property name="my_property" type="uint" value="5"/>
</item>
</your_very_own_component_type>
<environment>
<background type="cubemap" source="cubemaps::my_cubemap"/>
</environment>
<graph>
<node name="root_node">
<transform matrix="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"/>
<children>
<node name="sub_node">
<transform matrix="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"/>
<component type="MeshRenderer">
<mesh source="geometries::cube"/>
<material source="materials::material.001"/>
</component>
</node>
<node name="cam_node">
<transform matrix="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1"/>
<component type="Camera" source="cameras::cam_node.camera"/>
<component type="FramerateCounter" source="file::frc.prop"/>
<component type="PlayerController" source="file::pcont.prop"/>
<component type="MyComponent" source="your_very_own_component_type::my_own_component"/>
</node>
<node name="light_node">
<component type="Light" source="lights::some_light"/>
</node>
</children>
</node>
</graph>
</scene>
<!-- ###################### THIS IS A DIFFERENT FILE ########################## -->
<!-- Example of loading just a collada file -->
<scene>
<cubemaps>
<item id="my_cubemap">
<property name="type" type="string" value="collection"/>
<property name="collection_source" type="source" value="file::cubemaps/cubemap01"/>
</item>
</cubemaps>
<environment>
<background type="cubemap" source="cubemaps::my_cubemap"/>
</environment>
<collada>
<item id="my_scene" source="file::scenes/collada/scene.dae">
<!--Should actually default to true, adds playercontroller and frameratecounter-->
<property name="default_camera_components" type="bool" value="true"/>
</item>
</collada>
<graph source="collada::my_scene::scene01"/>
</scene>
<settings>
<!-- Splash screen settings --/>
<!-- Splash screen settings -->
<item name="splash_image">/textures/splash.png</item>
<item name="splash_sound">/audio/swoosh.wav</item>
<item name="splash_background">0.1 0.4 0.7 1.0</item>
<item name="splash_duration">200</item>
<!-- General settings --/>
<!-- General settings -->
<item name="settings_window_title">GLARE Window</item>
<item name="settings_window_size_x">1280</item>
<item name="settings_window_size_y">720</item>
<item name="settings_vsync_mode">0</item>
<item name="settings_msaa_samples">4</item>
<!-- Pathtracer settings --/>
<!-- Pathtracer settings -->
<item name="pathtrace_quality">0.4</item>
<item name="pathtrace_shadow_quality">0.04</item>
<item name="pathtrace_clamp_direct">8</item>
......@@ -24,6 +24,6 @@
<item name="pathtrace_bounces_transparent">8</item>
<item name="pathtrace_bounces_emissive">0</item>
<!-- Line Space settings --/>
<!-- Line Space settings -->
<item name="linespace_max_resolution">16</item>
</settings>
\ No newline at end of file
......@@ -7,6 +7,8 @@
#include <engine/rendering/SplashScreen.h>
#include <linespace/LineSpace.h>
#include <io/Export.h>
namespace glare
{
......@@ -67,15 +69,20 @@ namespace glare
//Create a skybox from cube map.
m_skybox = std::make_shared<core::Skybox>(core::Skybox::collectFilesFrom(core::asset("/textures/ryfjallet/")));
//auto cube_node = io::Resources::getInstance().getColladaSceneMeshNode("", m_current_scene_root / "benchmark_stfd_dragon_diff.dae", "dragon_vrip");
//io::Export::meshAsBinary(cube_node->getComponent<core::MeshRenderer>()->getMesh(), core::asset("dragon.mesh"), true);
//quitPromptDefault(0);
// BENCHMARKS
//initializeScene(m_current_scene_root / "benchmark_single_quad_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_single_cube_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_suzanne_x1_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_suzanne_x2_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_teapot_diff.dae", 1.f);
initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_bunny_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_armadillo_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_dragon_diff.dae", 1.f);
initializeScene(m_current_scene_root / "benchmark_stfd_dragon_diff.dae", 1.f);
//initializeScene(m_current_scene_root / "benchmark_stfd_asian_dragon_diff.dae", 1.f);
// ARTIFACT CHECK (GLASS)
......@@ -96,7 +103,7 @@ namespace glare
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_emissive.dae", 1.f);
//initializeScene(m_current_scene_root / "artifact_suzanne_x2_transparent.dae", 1.f);
//initializeScene(m_current_scene_root / "cornell_dragon.dae", 1.f);
initializeScene(m_current_scene_root / "block_of_rock.dae", 1.f);
initializeRenderRequirements();
initializeAdvanced();
initializeGUI();
......
#include "Export.h"
#include <engine/Log.h>
#include <sstream>
#include <lodepng/lodepng.h>
namespace glare
{
namespace io
{
void Export::meshAsBinary(std::shared_ptr<core::Mesh> mesh, const fs::path &target, bool overwrite, bool compress)
{
if (fs::exists(target) && !overwrite)
{
Log_Info << "File " << target.string() << " already exists.";
return;
}
const auto &vertices = mesh->getVertices();
const auto &indices = mesh->getIndices();
const uint32_t vertex_count = uint32_t(vertices.size());
const uint32_t index_count = uint32_t(indices.size());
const uint32_t buffer_size = (vertex_count * 8 * sizeof(float)) +
(index_count * sizeof(uint32_t)) +
64*sizeof(char) +
3*sizeof(uint32_t);
std::stringstream buffer(std::ios::binary | std::ios::out);
buffer.write("MESH", 4 * sizeof(char));
buffer.write("FVER", 4 * sizeof(char));
buffer.write(reinterpret_cast<const char*>(&c_binary_version), sizeof(uint32_t));
buffer.write("VERT", 4 * sizeof(char));
buffer.write(reinterpret_cast<const char*>(&vertex_count), sizeof(uint32_t));
for (uint32_t v = 0; v < vertex_count; ++v)
{
writeVertex(buffer, vertices[v]);
}
buffer.write("INDX", 4 * sizeof(char));
buffer.write(reinterpret_cast<const char*>(&index_count), sizeof(uint32_t));
for (uint32_t i = 0; i < index_count; ++i)
{
buffer.write(reinterpret_cast<const char*>(&(indices[i])), sizeof(uint32_t));
}
std::string data = buffer.str();
std::vector<uint8_t> input(data.begin(), data.end());
if (compress) {
std::vector<uint8_t> output;
lodepng::compress(output, input);
std::ofstream file(target, std::ios::binary | std::ios::out);
file.write(reinterpret_cast<const char*>(output.data()), output.size());
file.close();
}
else
{
std::ofstream file(target, std::ios::binary | std::ios::out);
file.write(reinterpret_cast<const char*>(input.data()), input.size());
file.close();
}
}
void Export::writeVertex(std::stringstream &file, const math::Vertex &vertex)
{
// writing 8 floats = 32bytes
file.write(reinterpret_cast<const char*>(&(vertex.position)), 3 * sizeof(float));
file.write(reinterpret_cast<const char*>(&(vertex.normal)), 3 * sizeof(float));
file.write(reinterpret_cast<const char*>(&(vertex.texcoord)), 2 * sizeof(float));
}
}
}
#ifndef __EXPORT_H
#define __EXPORT_H
#include <engine/graphics/Mesh.h>
#include <filesystem>
#include <memory>
#include <fstream>
namespace glare
{
namespace io
{
namespace fs = std::experimental::filesystem;
constexpr uint32_t c_binary_version = 1;
class Export
{
public:
static void meshAsBinary(std::shared_ptr<core::Mesh> mesh, const fs::path &target, bool overwrite = false, bool compress = true);
private:
static void writeVertex(std::stringstream &file, const math::Vertex &vertex);
};
}
}
#endif //__EXPORT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment