new rendering system and other additions

This commit is contained in:
Tim Nebel 2023-07-19 14:50:43 +02:00
commit 2e24e1714e
33 changed files with 1229 additions and 269 deletions

19
.idea/dataSources.xml generated Normal file
View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@localhost" uuid="6362561d-71b5-4682-8b46-cce91b932bdc">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="postgres@localhost" uuid="7c8311e0-6277-4df2-9b6b-a420b6a35ea8">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://localhost:5432/postgres</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

6
.idea/vcs.xml generated
View file

@ -2,7 +2,11 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/Tools/MapTools/deps/vserialize" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore" vcs="Git" /> <mapping directory="$PROJECT_DIR$/deps/vgcore" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore/deps/IconFontCppHeaders" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore/deps/assimp" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore/deps/glfw" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore/deps/glm" vcs="Git" />
<mapping directory="$PROJECT_DIR$/deps/vgcore/deps/imgui/imgui" vcs="Git" />
</component> </component>
</project> </project>

View file

@ -4,6 +4,7 @@ project(SpoonTool)
set (CMAKE_CXX_STANDARD 20) set (CMAKE_CXX_STANDARD 20)
find_package(Boost REQUIRED COMPONENTS thread chrono) find_package(Boost REQUIRED COMPONENTS thread chrono)
find_package(Lua REQUIRED)
add_subdirectory(deps/vgcore) add_subdirectory(deps/vgcore)
@ -13,6 +14,9 @@ add_executable(SpoonEdit src/main.cpp src/MainWindow.cpp src/MainWindow.h src/Pr
target_link_libraries(SpoonEdit PUBLIC GCore SpoonMapTools Boost::thread Boost::chrono) target_link_libraries(SpoonEdit PUBLIC GCore SpoonMapTools Boost::thread Boost::chrono)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
install(TARGETS SpoonEdit install(TARGETS SpoonEdit
CONFIGURATIONS Debug CONFIGURATIONS Debug
RUNTIME DESTINATION Debug RUNTIME DESTINATION Debug

View file

@ -9,7 +9,7 @@ find_package(GLEW REQUIRED)
find_package(yaml-cpp REQUIRED) find_package(yaml-cpp REQUIRED)
add_library(SpoonMapTools STATIC src/Map.cpp include/Map.h include/LevelObject.h include/Transform.h "include/Vector3.h" src/Vectior3.cpp src/Transform.cpp src/LevelObject.cpp include/Link.h src/Link.cpp include/Rail.h src/Rail.cpp include/RailPoint.h src/RailPoint.cpp include/SpecialObjectParams.h src/SpecialObjectParams.cpp include/SpecialObjectParamVersions/All.h include/SpecialObjectParamVersions/Default.h include/LayerConfig.h include/LayerConfig.h include/Element.h src/Element.cpp) add_library(SpoonMapTools STATIC src/Map.cpp include/Map.h include/LevelObject.h include/Transform.h "include/Vector3.h" src/Vectior3.cpp src/Transform.cpp src/LevelObject.cpp include/Link.h src/Link.cpp include/Rail.h src/Rail.cpp include/RailPoint.h src/RailPoint.cpp include/SpecialObjectParams.h src/SpecialObjectParams.cpp include/SpecialObjectParamVersions/All.h include/SpecialObjectParamVersions/Default.h include/Element.h src/Element.cpp)
target_include_directories(SpoonMapTools PUBLIC include) target_include_directories(SpoonMapTools PUBLIC include)

View file

@ -15,8 +15,8 @@
namespace Teams{ namespace Teams{
constexpr long Player = 0; constexpr long Player = 0;
constexpr long Neutral = 1; constexpr long Enemy = 1;
constexpr long Enemy = 2; constexpr long Neutral = 2;
constexpr std::array<long,3> AllOptions = {Player,Neutral,Enemy}; constexpr std::array<long,3> AllOptions = {Player,Neutral,Enemy};
@ -25,9 +25,9 @@ namespace Teams{
case 0: case 0:
return "Player"; return "Player";
case 1: case 1:
return "Neutral";
case 2:
return "Enemy"; return "Enemy";
case 2:
return "Neutral";
default: default:
return "Invalid"; return "Invalid";
} }

View file

@ -24,6 +24,8 @@ struct Map {
std::vector<Rail> Rails; std::vector<Rail> Rails;
Element* GetElementById(std::string id);
}; };

View file

@ -1,5 +1,6 @@
#include<Element.h> #include<Element.h>
#include<algorithm> #include<algorithm>
#include <iomanip>
Element::Element(const YAML::Node &ObjNode,std::list<std::string> PropertyBlockList) { Element::Element(const YAML::Node &ObjNode,std::list<std::string> PropertyBlockList) {
@ -28,14 +29,14 @@ Element::Element(const YAML::Node &ObjNode,std::list<std::string> PropertyBlockL
ModelName = ObjNode["ModelName"].as<std::string>(); ModelName = ObjNode["ModelName"].as<std::string>();
IsLinkDest = ObjNode["IsLinkDest"].as<bool>(); IsLinkDest = ObjNode["IsLinkDest"].as<bool>();
unsigned int ParamId = 1; unsigned int ParamId = 0;
while(YAML::Node ParamNode = ObjNode["Parameter" + std::to_string(ParamId)]){ while(YAML::Node ParamNode = ObjNode["Parameter" + std::to_string(ParamId)]){
Parameters.push_back(ParamNode.as<long>()); Parameters.push_back(ParamNode.as<long>());
ParamId++; ParamId++;
} }
unsigned int FloatParamId = 1; unsigned int FloatParamId = 0;
while(YAML::Node ParamNode = ObjNode["FloatParameter" + std::to_string(FloatParamId)]){ while(YAML::Node ParamNode = ObjNode["FloatParameter" + std::to_string(FloatParamId)]){
FloatParameters.push_back(ParamNode.as<float>()); FloatParameters.push_back(ParamNode.as<float>());
@ -118,12 +119,16 @@ void Element::YamlInsertBody(YAML::Emitter &Emitter) {
} }
Emitter << YAML::EndMap; Emitter << YAML::EndMap;
for(int i = 1; i <= Parameters.size(); i++){ for(int i = 0; i < Parameters.size(); i++){
Emitter << YAML::Key << "Parameter" + std::to_string(i) << YAML::Value << YAML::LocalTag("l") << Parameters[i-1]; Emitter << YAML::Key << "Parameter" + std::to_string(i) << YAML::Value << YAML::LocalTag("l") << Parameters[i];
} }
for(int i = 1; i <= FloatParameters.size(); i++){ for(int i = 0; i < FloatParameters.size(); i++){
Emitter << YAML::Key << "FloatParameter" + std::to_string(i) << YAML::Value << FloatParameters[i-1];
std::stringstream stream;
stream << std::fixed << std::setprecision(5) << FloatParameters[i];
std::string s = stream.str();
Emitter << YAML::Key << "FloatParameter" + std::to_string(i) << YAML::Value << stream.str();
} }
for(auto opts: OtherOptions){ for(auto opts: OtherOptions){

View file

@ -9,6 +9,7 @@
#include <boost/iostreams/device/file.hpp> #include <boost/iostreams/device/file.hpp>
#include<iostream> #include<iostream>
#include<boost/algorithm/string.hpp> #include<boost/algorithm/string.hpp>
#include<algorithm>
//GENSERIALIZABLECONTENT(Map,(Objects,Rails)) //GENSERIALIZABLECONTENT(Map,(Objects,Rails))
@ -63,6 +64,25 @@ void Map::Export(boost::filesystem::path YamlOut) {
file.close(); file.close();
} }
Element *Map::GetElementById(std::string id) {
//Wish i could use some kind of cache but im too lazy to check removal from Rails or Objects as to not cause any stale references to be output
// might do it at some point in the future
auto elemRef1 = std::find_if(Objects.begin(), Objects.end(),[&](const LevelObject &obj){return obj.Name == id;});
if(elemRef1 != Objects.end())
return &*elemRef1;
if(std::any_of(id.begin(), id.end(),[](char c){return c=='/';})) {
id.erase(id.find('/'));
auto elemRef2 = std::find_if(Rails.begin(), Rails.end(), [&](const Rail &rail) { return rail.Name == id; });
if (elemRef2 != Rails.end())
return &*elemRef2;
}
return nullptr;
}
Map ConvertFromYaml(boost::filesystem::path File){ Map ConvertFromYaml(boost::filesystem::path File){

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

115
res/St_Area/St_Area.dae Normal file
View file

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 3.6.0 commit date:2023-06-27, commit time:08:08, hash:c7fc78b81ecb</authoring_tool>
</contributor>
<created>2023-07-01T00:11:08</created>
<modified>2023-07-01T00:11:08</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_effects>
<effect id="Material-effect">
<profile_COMMON>
<newparam sid="Material_Base_Color-surface">
<surface type="2D">
<init_from>Material_Base_Color</init_from>
</surface>
</newparam>
<newparam sid="Material_Base_Color-sampler">
<sampler2D>
<source>Material_Base_Color-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<lambert>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<diffuse>
<texture texture="Material_Base_Color-sampler" texcoord="UVMap"/>
</diffuse>
<index_of_refraction>
<float sid="ior">1.45</float>
</index_of_refraction>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_images>
<image id="Material_Base_Color" name="Material_Base_Color">
<init_from>Material%20Base%20Color.png</init_from>
</image>
</library_images>
<library_materials>
<material id="Material-material" name="Material">
<instance_effect url="#Material-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="24">50 50 50 50 50 -50 50 -50 50 50 -50 -50 -50 50 50 -50 50 -50 -50 -50 50 -50 -50 -50</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="8" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-normals">
<float_array id="Cube-mesh-normals-array" count="18">0 0 1 0 -1 0 -1 0 0 0 0 -1 1 0 0 0 1 0</float_array>
<technique_common>
<accessor source="#Cube-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-map-0">
<float_array id="Cube-mesh-map-0-array" count="72">0.875 0.5 0.625 0.75 0.625 0.5 0.625 0.75 0.375 1 0.375 0.75 0.625 0 0.375 0.25 0.375 0 0.375 0.5 0.125 0.75 0.125 0.5 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.25 0.375 0.5 0.375 0.25 0.875 0.5 0.875 0.75 0.625 0.75 0.625 0.75 0.625 1 0.375 1 0.625 0 0.625 0.25 0.375 0.25 0.375 0.5 0.375 0.75 0.125 0.75 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.25 0.625 0.5 0.375 0.5</float_array>
<technique_common>
<accessor source="#Cube-mesh-map-0-array" count="36" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<triangles material="Material-material" count="12">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-0" offset="2" set="0"/>
<p>4 0 0 2 0 1 0 0 2 2 1 3 7 1 4 3 1 5 6 2 6 5 2 7 7 2 8 1 3 9 7 3 10 5 3 11 0 4 12 3 4 13 1 4 14 4 5 15 1 5 16 5 5 17 4 0 18 6 0 19 2 0 20 2 1 21 6 1 22 7 1 23 6 2 24 4 2 25 5 2 26 1 3 27 3 3 28 7 3 29 0 4 30 2 4 31 3 4 32 4 5 33 0 5 34 1 5 35</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Cube-mesh" name="Cube">
<bind_material>
<technique_common>
<instance_material symbol="Material-material" target="#Material-material">
<bind_vertex_input semantic="UVMap" input_semantic="TEXCOORD" input_set="0"/>
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

115
res/St_Arrow/St_Arrow.dae Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

View file

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 3.5.1 commit date:2023-04-25, commit time:13:50, hash:6ee8aa4997ee</authoring_tool>
</contributor>
<created>2023-05-30T22:31:04</created>
<modified>2023-05-30T22:31:04</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_effects>
<effect id="Material-effect">
<profile_COMMON>
<newparam sid="Material_Base_Color-surface">
<surface type="2D">
<init_from>Material_Base_Color</init_from>
</surface>
</newparam>
<newparam sid="Material_Base_Color-sampler">
<sampler2D>
<source>Material_Base_Color-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<lambert>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<diffuse>
<texture texture="Material_Base_Color-sampler" texcoord="UVMap"/>
</diffuse>
<index_of_refraction>
<float sid="ior">1.45</float>
</index_of_refraction>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_images>
<image id="Material_Base_Color" name="Material_Base_Color">
<init_from>Material%20Base%20Color.png</init_from>
</image>
</library_images>
<library_materials>
<material id="Material-material" name="Material">
<instance_effect url="#Material-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="24">1 1 1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="8" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-normals">
<float_array id="Cube-mesh-normals-array" count="18">0 0 1 0 -1 0 -1 0 0 0 0 -1 1 0 0 0 1 0</float_array>
<technique_common>
<accessor source="#Cube-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-map-0">
<float_array id="Cube-mesh-map-0-array" count="72">0.875 0.5 0.625 0.75 0.625 0.5 0.625 0.75 0.375 1 0.375 0.75 0.625 0 0.375 0.25 0.375 0 0.375 0.5 0.125 0.75 0.125 0.5 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.25 0.375 0.5 0.375 0.25 0.875 0.5 0.875 0.75 0.625 0.75 0.625 0.75 0.625 1 0.375 1 0.625 0 0.625 0.25 0.375 0.25 0.375 0.5 0.375 0.75 0.125 0.75 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.25 0.625 0.5 0.375 0.5</float_array>
<technique_common>
<accessor source="#Cube-mesh-map-0-array" count="36" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<triangles material="Material-material" count="12">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-0" offset="2" set="1"/>
<p>4 0 0 2 0 1 0 0 2 2 1 3 7 1 4 3 1 5 6 2 6 5 2 7 7 2 8 1 3 9 7 3 10 5 3 11 0 4 12 3 4 13 1 4 14 4 5 15 1 5 16 5 5 17 4 0 18 6 0 19 2 0 20 2 1 21 6 1 22 7 1 23 6 2 24 4 2 25 5 2 26 1 3 27 3 3 28 7 3 29 0 4 30 2 4 31 3 4 32 4 5 33 0 5 34 1 5 35</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Cube-mesh" name="Cube">
<bind_material>
<technique_common>
<instance_material symbol="Material-material" target="#Material-material">
<bind_vertex_input semantic="UVMap" input_semantic="TEXCOORD" input_set="0"/>
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View file

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 3.6.0 commit date:2023-06-27, commit time:08:08, hash:c7fc78b81ecb</authoring_tool>
</contributor>
<created>2023-07-01T01:03:17</created>
<modified>2023-07-01T01:03:17</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_effects>
<effect id="Material-effect">
<profile_COMMON>
<newparam sid="Material_Base_Color-surface">
<surface type="2D">
<init_from>Material_Base_Color</init_from>
</surface>
</newparam>
<newparam sid="Material_Base_Color-sampler">
<sampler2D>
<source>Material_Base_Color-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<lambert>
<emission>
<color sid="emission">0 0 0 1</color>
</emission>
<diffuse>
<texture texture="Material_Base_Color-sampler" texcoord="UVMap"/>
</diffuse>
<index_of_refraction>
<float sid="ior">1.45</float>
</index_of_refraction>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_images>
<image id="Material_Base_Color" name="Material_Base_Color">
<init_from>Material%20Base%20Color.png</init_from>
</image>
</library_images>
<library_materials>
<material id="Material-material" name="Material">
<instance_effect url="#Material-effect"/>
</material>
</library_materials>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="96">1 1 1 1 1 -1 1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1 11 -1 -1 11 1 1 11 -1 1 11 11 1 1 11 1 -1 11 -1 1 11 -1 -1 -1 -11 -1 -1 -11 1 1 -11 1 1 -11 -1 1 11 -1 -1 11 -1 1 11 1 -1 11 1 -1 1 -11 -1 -1 -11 1 1 -11 1 -1 -11 -11 1 -1 -11 -1 -1 -11 -1 1 -11 1 1</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="32" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-normals">
<float_array id="Cube-mesh-normals-array" count="18">-1 0 0 0 0 -1 0 -1 0 0 1 0 0 0 1 1 0 0</float_array>
<technique_common>
<accessor source="#Cube-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube-mesh-map-0">
<float_array id="Cube-mesh-map-0-array" count="360">0.625 0 0.625 0.25 0.625 0.25 0.375 0 0.625 0 0.625 0 0.375 0 0.375 0.25 0.375 0.25 0.125 0.75 0.375 0.75 0.375 0.75 0.625 0.5 0.375 0.5 0.375 0.5 0.625 0.25 0.375 0.25 0.375 0.25 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0.5 0.625 0.75 0.625 0.75 0.625 0.25 0.625 0.5 0.625 0.5 0.625 0.75 0.625 1 0.625 1 0.625 0.5 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.75 0.375 0.75 0.625 0.75 0.625 0.5 0.625 0.5 0.375 0.75 0.625 0.75 0.625 0.75 0.625 0.75 0.375 1 0.375 0.75 0.375 0.75 0.125 0.75 0.125 0.75 0.625 1 0.625 0.75 0.625 0.75 0.625 0.75 0.375 0.75 0.375 0.75 0.625 0.25 0.375 0.5 0.375 0.25 0.125 0.5 0.375 0.5 0.375 0.5 0.625 0.5 0.625 0.25 0.625 0.25 0.375 0.5 0.625 0.5 0.625 0.5 0.375 0.5 0.125 0.75 0.125 0.5 0.375 0.25 0.375 0 0.375 0 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.5 0.125 0.5 0.125 0.5 0.625 0 0.375 0.25 0.375 0 0.625 0.25 0.625 0 0.625 0 0.375 0.25 0.625 0.25 0.625 0.25 0.625 0 0.375 0 0.375 0 0.625 0 0.625 0 0.625 0.25 0.375 0 0.375 0 0.625 0 0.375 0 0.375 0 0.375 0.25 0.125 0.75 0.125 0.75 0.375 0.75 0.625 0.5 0.625 0.5 0.375 0.5 0.625 0.25 0.625 0.25 0.375 0.25 0.875 0.5 0.875 0.75 0.625 0.75 0.625 0.5 0.625 0.5 0.625 0.75 0.625 0.25 0.625 0.25 0.625 0.5 0.625 0.75 0.625 0.75 0.625 1 0.625 0.5 0.625 0.75 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.75 0.625 0.75 0.625 0.75 0.625 0.5 0.375 0.75 0.375 0.75 0.625 0.75 0.625 0.75 0.625 1 0.375 1 0.375 0.75 0.375 0.75 0.125 0.75 0.625 1 0.625 1 0.625 0.75 0.625 0.75 0.625 0.75 0.375 0.75 0.625 0.25 0.625 0.5 0.375 0.5 0.125 0.5 0.125 0.5 0.375 0.5 0.625 0.5 0.625 0.5 0.625 0.25 0.375 0.5 0.375 0.5 0.625 0.5 0.375 0.5 0.375 0.75 0.125 0.75 0.375 0.25 0.375 0.25 0.375 0 0.375 0.75 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.5 0.125 0.5 0.625 0 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.25 0.625 0 0.375 0.25 0.375 0.25 0.625 0.25 0.625 0 0.625 0 0.375 0</float_array>
<technique_common>
<accessor source="#Cube-mesh-map-0-array" count="180" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<triangles material="Material-material" count="60">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Cube-mesh-map-0" offset="2" set="0"/>
<p>6 0 0 11 0 1 4 0 2 7 0 3 17 0 4 6 0 5 7 1 6 28 1 7 5 1 8 7 2 9 27 2 10 3 2 11 0 3 12 13 3 13 1 3 14 4 0 15 21 0 16 5 0 17 11 4 18 8 4 19 10 4 20 0 5 21 8 5 22 2 5 23 4 3 24 10 3 25 0 3 26 2 2 27 9 2 28 6 2 29 12 5 30 15 5 31 13 5 32 1 1 33 15 1 34 3 1 35 2 4 36 12 4 37 0 4 38 3 2 39 14 2 40 2 2 41 18 2 42 16 2 43 19 2 44 3 1 45 16 1 46 7 1 47 6 4 48 18 4 49 2 4 50 2 5 51 19 5 52 3 5 53 23 3 54 20 3 55 21 3 56 5 1 57 20 1 58 1 1 59 0 4 60 23 4 61 4 4 62 1 5 63 22 5 64 0 5 65 26 1 66 25 1 67 24 1 68 5 0 69 25 0 70 7 0 71 3 5 72 26 5 73 1 5 74 1 3 75 24 3 76 5 3 77 30 0 78 28 0 79 29 0 80 4 4 81 30 4 82 6 4 83 5 3 84 31 3 85 4 3 86 6 2 87 29 2 88 7 2 89 6 0 90 9 0 91 11 0 92 7 0 93 16 0 94 17 0 95 7 1 96 29 1 97 28 1 98 7 2 99 25 2 100 27 2 101 0 3 102 12 3 103 13 3 104 4 0 105 23 0 106 21 0 107 11 4 108 9 4 109 8 4 110 0 5 111 10 5 112 8 5 113 4 3 114 11 3 115 10 3 116 2 2 117 8 2 118 9 2 119 12 5 120 14 5 121 15 5 122 1 1 123 13 1 124 15 1 125 2 4 126 14 4 127 12 4 128 3 2 129 15 2 130 14 2 131 18 2 132 17 2 133 16 2 134 3 1 135 19 1 136 16 1 137 6 4 138 17 4 139 18 4 140 2 5 141 18 5 142 19 5 143 23 3 144 22 3 145 20 3 146 5 1 147 21 1 148 20 1 149 0 4 150 22 4 151 23 4 152 1 5 153 20 5 154 22 5 155 26 1 156 27 1 157 25 1 158 5 0 159 24 0 160 25 0 161 3 5 162 27 5 163 26 5 164 1 3 165 26 3 166 24 3 167 30 0 168 31 0 169 28 0 170 4 4 171 31 4 172 30 4 173 5 3 174 28 3 175 31 3 176 6 2 177 30 2 178 29 2 179</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 1</matrix>
<instance_geometry url="#Cube-mesh" name="Cube">
<bind_material>
<technique_common>
<instance_material symbol="Material-material" target="#Material-material">
<bind_vertex_input semantic="UVMap" input_semantic="TEXCOORD" input_set="0"/>
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

115
res/St_Rotate/St_Rotate.dae Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

126
res/St_Scalar/St_Scalar.dae Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 720 B

View file

@ -1,12 +0,0 @@
# Blender 3.5.1 MTL File: 'None'
# www.blender.org
newmtl Material
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

View file

@ -1,40 +0,0 @@
# Blender 3.5.1
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.875000 0.500000
vt 0.625000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.250000
vt 0.875000 0.750000
vt 0.625000 1.000000
vt 0.625000 0.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/5/1 7/9/1 3/3/1
f 4/4/2 3/3/2 7/10/2 8/12/2
f 8/13/3 7/11/3 5/6/3 6/8/3
f 6/7/4 2/2/4 4/4/4 8/14/4
f 2/2/5 1/1/5 3/3/5 4/4/5
f 6/8/6 5/6/6 1/1/6 2/2/6

View file

@ -8,45 +8,9 @@
#include<imgui.h> #include<imgui.h>
#include "IconsFontAwesome6.h" #include "IconsFontAwesome6.h"
#include "glm/gtx/string_cast.hpp" #include "glm/gtx/string_cast.hpp"
#include <glm/gtx/rotate_vector.hpp>
#include<cmath> #include<cmath>
const GLchar *vertexShader = "#version 460\n"
"layout (location = 0) in vec3 aPos;\n"
"layout (location = 1) in vec2 aTexCoord;\n"
"uniform mat4 VP;\n"
"uniform mat4 TransformationMatrix;\n"
"uniform mat4 TransformationMatrixNoYInv;\n"
"out vec2 TexCoord;\n"
"out vec4 WldPos;\n"
"void main(){\n"
" vec3 glPos = vec3(aPos.x,-aPos.y,aPos.z);\n"
" WldPos = TransformationMatrixNoYInv * vec4(aPos.xyz,1);\n"
" gl_Position = (VP * TransformationMatrix) * vec4(glPos.x,glPos.y,glPos.z,1);\n"
" TexCoord = aTexCoord;\n"
"}\n";
const GLchar *fragmentShader = "#version 460\n"
"in vec2 TexCoord;\n"
"in vec4 WldPos;\n"
"layout(location = 1) out vec4 FragColor;\n"
"layout(location = 2) out unsigned int ObjId;\n"
"layout(location = 3) out vec4 WorldPos;\n"
"uniform sampler2D tex;\n"
"uniform unsigned int ObjIdIn;\n"
"uniform vec4 ObjColor;\n"
"//out vec4 CamPos;\n"
"void main(){\n"
" ObjId = ObjIdIn;\n"
" WorldPos = vec4(WldPos.xyz,1);\n"
" //if(WldPos.w == 0) WorldPos=vec4(WldPos.xyz,1);\n"
" vec4 textel = texture(tex,TexCoord);\n"
" if(textel.a < 0.2) discard;\n"
" //textel.a = (CamPos.z / CamPos.w) / 100;\n"
" FragColor = textel * ObjColor;\n"
" //FragColor = vec4(1,1,1,1);\n"
"}";
MainViewport *MainVP; MainViewport *MainVP;
glm::mat4 TransformToMatrix(Transform tf) { glm::mat4 TransformToMatrix(Transform tf) {
@ -64,12 +28,13 @@ glm::mat4 TransformToMatrix(Transform tf) {
} }
glm::vec3 ToGlmVec3(Vector3 Vec3) { glm::vec3 ToGlmVec3(Vector3 Vec3) {
return glm::vec3(Vec3.X, Vec3.Y, Vec3.Z); return {Vec3.X, Vec3.Y, Vec3.Z};
} }
bool IsArea(std::string Type){ bool IsArea(const std::string& Type) {
if (Type == "Area" || if (Type == "Area" ||
Type == "Area_Yellow" || Type == "Area_Yellow" ||
Type == "Area_Pink" ||
Type == "StageArea" || Type == "StageArea" ||
Type == "GeneralArea" || Type == "GeneralArea" ||
Type == "PaintedArea" || Type == "PaintedArea" ||
@ -81,20 +46,72 @@ bool IsArea(std::string Type){
return false; return false;
} }
MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true) { MainViewport::MainViewport() : Graphics::ViewportWidget("Main Viewport", true), VP(1.0f) {
MainVP = this; MainVP = this;
shader = Graphics::Shader(vertexShader, fragmentShader);
m_internalFramebuf = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, GL_COLOR_ATTACHMENT0},
{GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_COLOR_ATTACHMENT1},
{GL_RGBA16F, GL_RGBA, GL_FLOAT, GL_COLOR_ATTACHMENT2},
{GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH_STENCIL_ATTACHMENT}
},
Graphics::Shader("ForwardPass"));
SunCam = std::make_unique<Graphics::Framebuffer>(
std::vector<Graphics::FramebufferTextureInfo>{
{GL_DEPTH_COMPONENT16,GL_DEPTH_COMPONENT,GL_FLOAT,GL_DEPTH_ATTACHMENT}
},
Graphics::Shader("ShadowPass"),
Math::Vector2i(16384,16384));
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
glBindTexture(GL_TEXTURE_2D, tex.m_texture.getId());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D,0);
//ObjMesh = Graphics::Mesh(); //ObjMesh = Graphics::Mesh();
GLuint ObjColPos = glGetUniformLocation(shader.ShaderId, "ObjColor"); GLint ObjColPos = m_internalFramebuf->m_shader.getUniformLocation("ObjColor");
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
} }
void MainViewport::RenderRail(Rail *rail) {
static Model RailPointMdl = Model("St_RailPoint");
if (rail->Points.size() > 1) {
auto lastRailPoint = rail->Points.front();
for (RailPoint &railPoint: rail->Points) {
RailPointMdl.Draw(railPoint.TF, m_internalFramebuf->m_shader, VP);
}
}
}
void MainViewport::Draw() { void MainViewport::Draw() {
GLuint ObjIdPos = glGetUniformLocation(shader.ShaderId, "ObjIdIn");
GLuint ObjColPos = glGetUniformLocation(shader.ShaderId, "ObjColor"); #ifndef NDEBUG
glClearColor(.2, .2, .2, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#endif
m_internalFramebuf->m_shader.use();
GLint ObjIdPos = m_internalFramebuf->m_shader.getUniformLocation("ObjIdIn");
GLint ObjColPos = m_internalFramebuf->m_shader.getUniformLocation("ObjColor");
GLint TeamId = m_internalFramebuf->m_shader.getUniformLocation("TeamId");
GLint CamPosLoc = m_internalFramebuf->m_shader.getUniformLocation("CameraPosition");
static auto lasttime = boost::chrono::high_resolution_clock::now(); static auto lasttime = boost::chrono::high_resolution_clock::now();
@ -151,30 +168,42 @@ void MainViewport::Draw() {
glm::mat4 projectionMatrix = glm::perspective( glm::mat4 projectionMatrix = glm::perspective(
glm::radians( glm::radians(
fov), // The vertical Field of View, in radians: the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in) fov), // The vertical Field of View, in radians: the amount of "zoom". Think "camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in)
(float) framewidth / (float) m_internalFramebuf->getSize().x /
(float) frameheight, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ? (float) m_internalFramebuf->getSize().y, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
0.1f, // Near clipping plane. Keep as big as possible, or you'll get precision issues. NearClippingPlane, // Near clipping plane. Keep as big as possible, or you'll get precision issues.
10000.0f // Far clipping plane. Keep as little as possible. FarClippingPlane // Far clipping plane. Keep as little as possible.
); );
//glm::mat4 ViewMatrix = glm::translate(glm::mat4(1.0f), -camPos); //glm::mat4 ViewMatrix = glm::translate(glm::mat4(1.0f), -camPos);
glm::mat4 ViewMatrix = glm::lookAt(camPos, camPos + cameraDirection, glm::vec3(0, 1, 0)); glm::mat4 ViewMatrix = glm::lookAt(camPos, camPos + cameraDirection, glm::vec3(0, 1, 0));
glm::mat4 ModelMat = glm::mat4(1.0f);
VP = projectionMatrix * ViewMatrix;// * ViewMatrix * ModelMat; VP = projectionMatrix * ViewMatrix;// * ViewMatrix * ModelMat;
glUniform3f(CamPosLoc, camPos.x,camPos.y,camPos.z);
if (ImGui::BeginPopup("Main VP Debug")) { if (ImGui::BeginPopup("Main VP Debug")) {
ImGui::DragFloat3("Camera Postion", &camPos.x, 0.01); ImGui::DragFloat3("Camera Postion", &camPos.x, 0.01);
ImGui::DragFloat2("Camera Rotation", &camrot.x, 0.01); ImGui::DragFloat2("Camera Rotation", &camrot.x, 0.01);
ImGui::SliderFloat("FOV", &fov, 0, 180); ImGui::SliderFloat("FOV", &fov, 0, 180);
ImGui::DragFloat("Speed", &speed, 1); ImGui::DragFloat("Speed", &speed, 1);
ImGui::DragFloat("Near Clipping Plane", &NearClippingPlane, 1);
ImGui::DragFloat("Far Clipping Plane", &FarClippingPlane, 1);
ImGui::DragFloat("Shadow Area", &shadowArea, 0.01);
//ImGui::SliderFloat("Shading Effectiveness", &ShadingEffectiveness, 0, 1);
ImGui::DragFloat3("Light Direction", &LightDir.x, 0.01);
ImGui::Checkbox("Draw All Areas", &drawAllAreas); ImGui::Checkbox("Draw All Areas", &drawAllAreas);
ImGui::EndPopup(); ImGui::EndPopup();
} }
GLuint MatrixID = glGetUniformLocation(shader.ShaderId, "VP"); m_internalFramebuf->m_shader.use();
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, glm::value_ptr(VP));
GLint LightDirId = m_internalFramebuf->m_shader.getUniformLocation("LightDirection");
glUniform3f(LightDirId, LightDir.x , LightDir.y,LightDir.z);
auto &map = GetMainWindow()->loadedMap; auto &map = GetMainWindow()->loadedMap;
@ -190,10 +219,67 @@ void MainViewport::Draw() {
unsigned int ObjID = 16; unsigned int ObjID = 16;
glm::vec3 SunPos = (glm::normalize(LightDir) * 1500.0f) + camPos;
glm::mat4 SunProj = glm::ortho(-shadowArea,shadowArea,-shadowArea,shadowArea,1.0f,4000.0f);
glm::mat4 SunView = glm::lookAt(SunPos,camPos,{0,1,0});
glm::mat4 SunVP = SunProj * SunView;
SunCam->bind();
SunCam->m_shader.use();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glClear(GL_DEPTH_BUFFER_BIT);
for (auto &obj: map.Objects) { for (auto &obj: map.Objects) {
if (IsArea(obj.Type)) {
continue;
}
if (!MdlFromObj.contains(obj.Type)) {
if (boost::filesystem::exists(
boost::filesystem::current_path() / "Models" / obj.Type / (obj.Type + ".dae")))
MdlFromObj.insert({obj.Type, Model(obj.Type)});
else {
MdlFromObj.insert({obj.Type, Model("St_Default")});
std::cout << "Model missing: \n\t" << obj.Type << std::endl;
}
}
auto &mdl = MdlFromObj.find(obj.Type)->second;
mdl.Draw(obj.TF, SunCam->m_shader, SunVP);
}
m_internalFramebuf->bind();
m_internalFramebuf->m_shader.use();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
auto tex = SunCam->getFbTexByAttachment(GL_DEPTH_ATTACHMENT);
tex.m_texture.setActive(5);
GLint SunVpLoc = m_internalFramebuf->m_shader.getUniformLocation("SunVP");
glUniformMatrix4fv(SunVpLoc,1,GL_FALSE,&SunVP[0][0]);
for (auto &obj: map.Objects) {
glUniform1i(TeamId,(GLint)obj.Team);
if (IsArea(obj.Type) && !drawAllAreas) { if (IsArea(obj.Type) && !drawAllAreas) {
ObjID++; ObjID++;
continue; continue;
@ -201,7 +287,7 @@ void MainViewport::Draw() {
static auto AreaMdl = Model("St_Area"); static auto AreaMdl = Model("St_Area");
glUniform1ui(ObjIdPos, ObjID); glUniform1ui(ObjIdPos, ObjID);
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
AreaMdl.Draw(obj.TF); AreaMdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP);
ObjID++; ObjID++;
continue; continue;
} }
@ -217,20 +303,19 @@ void MainViewport::Draw() {
} }
auto mdl = MdlFromObj.find(obj.Type)->second; auto &mdl = MdlFromObj.find(obj.Type)->second;
glUniform1ui(ObjIdPos, ObjID); glUniform1ui(ObjIdPos, ObjID);
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
if (&obj == GetMainWindow()->selectedElem) if (&obj == GetMainWindow()->selectedElem)
glUniform4f(ObjColPos, 1, .7, .7, 1); glUniform4f(ObjColPos, 1, .7, .7, 1);
mdl.Draw(obj.TF); mdl.Draw(obj.TF, m_internalFramebuf->m_shader, VP);
ObjID++; ObjID++;
} }
if (GetMainWindow()->selectedElem != nullptr) { if (GetMainWindow()->selectedElem != nullptr) {
auto selobj = GetMainWindow()->selectedElem; auto selobj = GetMainWindow()->selectedElem;
@ -239,21 +324,25 @@ void MainViewport::Draw() {
glUniform1ui(ObjIdPos, 0); glUniform1ui(ObjIdPos, 0);
AreaMdl.Draw(selobj->TF); AreaMdl.Draw(selobj->TF, m_internalFramebuf->m_shader, VP);
} }
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
for (Link &link: GetMainWindow()->selectedElem->Links) {
glUniform1ui(ObjIdPos, 0);
Element *elem = GetMainWindow()->loadedMap.GetElementById(link.Destination);
if (elem == nullptr)
continue;
if (Rail *rail = dynamic_cast<Rail *>(elem)) {
RenderRail(rail);
}
}
if (Rail *rail = dynamic_cast<Rail *>(GetMainWindow()->selectedElem)) { if (Rail *rail = dynamic_cast<Rail *>(GetMainWindow()->selectedElem)) {
static Model Arrow = Model("St_RailPoint"); glUniform1ui(ObjIdPos, 0);
RenderRail(rail);
if(rail->Points.size() > 1) {
auto lastRailPoint = rail->Points.front();
for (RailPoint &railPoint: rail->Points) {
Arrow.Draw(railPoint.TF);
}
}
} }
//mdl.DrawSelection(selobj->TF); //mdl.DrawSelection(selobj->TF);
@ -265,7 +354,7 @@ void MainViewport::Draw() {
auto tf = Transform(); auto tf = Transform();
tf.Position = selobj->TF.Position; tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos); // float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50}; //tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1, 1, 1}; tf.Scale = {1, 1, 1};
tf.Rotation = {0, 0, 90}; tf.Rotation = {0, 0, 90};
@ -274,21 +363,21 @@ void MainViewport::Draw() {
if (HoveredObjId == 1) if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1); glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1); glUniform1ui(ObjIdPos, 1);
Arrow.Draw(tf); Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {0, 0, 0}; tf.Rotation = {0, 0, 0};
glUniform4f(ObjColPos, 0, 0.5, 0, 1); glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if (HoveredObjId == 2) if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1); glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2); glUniform1ui(ObjIdPos, 2);
Arrow.Draw(tf); Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {90, 0, 0}; tf.Rotation = {90, 0, 0};
glUniform4f(ObjColPos, 0, 0, 0.5, 1); glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if (HoveredObjId == 3) if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1); glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3); glUniform1ui(ObjIdPos, 3);
Arrow.Draw(tf); Arrow.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
} else if (CurrentGizmoType == Scale) { } else if (CurrentGizmoType == Scale) {
@ -296,7 +385,7 @@ void MainViewport::Draw() {
auto tf = Transform(); auto tf = Transform();
tf.Position = selobj->TF.Position; tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos); // float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50}; //tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1, 1, 1}; tf.Scale = {1, 1, 1};
tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y + 90, selobj->TF.Rotation.Z}; tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y + 90, selobj->TF.Rotation.Z};
@ -305,21 +394,21 @@ void MainViewport::Draw() {
if (HoveredObjId == 1) if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1); glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1); glUniform1ui(ObjIdPos, 1);
Scalar.Draw(tf); Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {selobj->TF.Rotation.X, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z}; tf.Rotation = {selobj->TF.Rotation.X, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z};
glUniform4f(ObjColPos, 0, 0.5, 0, 1); glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if (HoveredObjId == 2) if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1); glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2); glUniform1ui(ObjIdPos, 2);
Scalar.Draw(tf); Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z}; tf.Rotation = {selobj->TF.Rotation.X + 90, selobj->TF.Rotation.Y, selobj->TF.Rotation.Z};
glUniform4f(ObjColPos, 0, 0, 0.5, 1); glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if (HoveredObjId == 3) if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1); glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3); glUniform1ui(ObjIdPos, 3);
Scalar.Draw(tf); Scalar.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
} else if (CurrentGizmoType == Rotate) { } else if (CurrentGizmoType == Rotate) {
@ -327,7 +416,7 @@ void MainViewport::Draw() {
auto tf = Transform(); auto tf = Transform();
tf.Position = selobj->TF.Position; tf.Position = selobj->TF.Position;
float size = glm::distance(glm::vec3(tf.Position.X,tf.Position.Y,tf.Position.Z),camPos); // float size = glm::distance(glm::vec3(tf.Position.X, tf.Position.Y, tf.Position.Z), camPos);
//tf.Scale = {size/ 50, size/ 50, size/ 50}; //tf.Scale = {size/ 50, size/ 50, size/ 50};
tf.Scale = {1, 1, 1}; tf.Scale = {1, 1, 1};
tf.Rotation = {0, 0, 90}; tf.Rotation = {0, 0, 90};
@ -336,21 +425,21 @@ void MainViewport::Draw() {
if (HoveredObjId == 1) if (HoveredObjId == 1)
glUniform4f(ObjColPos, 1, 0, 0, 1); glUniform4f(ObjColPos, 1, 0, 0, 1);
glUniform1ui(ObjIdPos, 1); glUniform1ui(ObjIdPos, 1);
Rotator.Draw(tf); Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {0, 0, 0}; tf.Rotation = {0, 0, 0};
glUniform4f(ObjColPos, 0, 0.5, 0, 1); glUniform4f(ObjColPos, 0, 0.5, 0, 1);
if (HoveredObjId == 2) if (HoveredObjId == 2)
glUniform4f(ObjColPos, 0, 1, 0, 1); glUniform4f(ObjColPos, 0, 1, 0, 1);
glUniform1ui(ObjIdPos, 2); glUniform1ui(ObjIdPos, 2);
Rotator.Draw(tf); Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
tf.Rotation = {90, 0, 0}; tf.Rotation = {90, 0, 0};
glUniform4f(ObjColPos, 0, 0, 0.5, 1); glUniform4f(ObjColPos, 0, 0, 0.5, 1);
if (HoveredObjId == 3) if (HoveredObjId == 3)
glUniform4f(ObjColPos, 0, 0, 1, 1); glUniform4f(ObjColPos, 0, 0, 1, 1);
glUniform1ui(ObjIdPos, 3); glUniform1ui(ObjIdPos, 3);
Rotator.Draw(tf); Rotator.Draw(tf, m_internalFramebuf->m_shader, VP);
glUniform4f(ObjColPos, 1, 1, 1, 1); glUniform4f(ObjColPos, 1, 1, 1, 1);
} }
@ -411,18 +500,18 @@ void MainViewport::HandleInput(InputEvent event) {
switch (event.EventType) { switch (event.EventType) {
case (InputType::MouseHover): { case (InputType::MouseHover): {
GLint y = event.y * frameheight; GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * framewidth; GLint x = event.x * m_internalFramebuf->getSize().x;
glReadBuffer(GL_COLOR_ATTACHMENT1); glReadBuffer(GL_COLOR_ATTACHMENT1);
glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId); glReadPixels(x, y, 1, 1, GL_RED_INTEGER, GL_UNSIGNED_INT, &HoveredObjId);
} }
break; break;
case (InputType::MouseDownL): { case (InputType::MouseDownL): {
GLint y = event.y * frameheight; GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * framewidth; GLint x = event.x * m_internalFramebuf->getSize().x;
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_internalFramebuf->getId());
glReadBuffer(GL_COLOR_ATTACHMENT1); glReadBuffer(GL_COLOR_ATTACHMENT1);
unsigned int obj = 0; unsigned int obj = 0;
@ -446,7 +535,8 @@ void MainViewport::HandleInput(InputEvent event) {
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos)); glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x,CurWDirPos.y,CurWDirPos.z},GizmoDir); glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x, CurWDirPos.y, CurWDirPos.z},
GizmoDir);
glm::vec3 objpos = {SelObj->TF.Position.X, SelObj->TF.Position.Y, SelObj->TF.Position.Z}; glm::vec3 objpos = {SelObj->TF.Position.X, SelObj->TF.Position.Y, SelObj->TF.Position.Z};
ObjBindingVec = objpos - GizmoDirPrePos; ObjBindingVec = objpos - GizmoDirPrePos;
@ -477,7 +567,8 @@ void MainViewport::HandleInput(InputEvent event) {
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos)); glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos));
glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x,CurWDirPos.y,CurWDirPos.z},GizmoDir); glm::vec3 GizmoDirPrePos = ProjectToRayNormalized({CurWDirPos.x, CurWDirPos.y, CurWDirPos.z},
GizmoDir);
glm::vec3 objpos = ToGlmVec3(SelObj->TF.Position); glm::vec3 objpos = ToGlmVec3(SelObj->TF.Position);
@ -518,10 +609,10 @@ void MainViewport::HandleInput(InputEvent event) {
} }
break; break;
case (InputType::MouseHoldL): { case (InputType::MouseHoldL): {
GLint y = event.y * frameheight; GLint y = event.y * m_internalFramebuf->getSize().y;
GLint x = event.x * framewidth; GLint x = event.x * m_internalFramebuf->getSize().x;
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, m_internalFramebuf->getId());
glReadBuffer(GL_COLOR_ATTACHMENT1); glReadBuffer(GL_COLOR_ATTACHMENT1);
unsigned int obj = 0; unsigned int obj = 0;
@ -554,8 +645,12 @@ void MainViewport::HandleInput(InputEvent event) {
auto ClipSpaceStart = (VP * Tf) * glm::vec4(0, 0, 0, 1); auto ClipSpaceStart = (VP * Tf) * glm::vec4(0, 0, 0, 1);
auto ClipSpaceEnd = (VP * Tf) * glm::vec4(GizmoDir, 1); auto ClipSpaceEnd = (VP * Tf) * glm::vec4(GizmoDir, 1);
glm::vec2 ScreenSpaceStart = {((ClipSpaceStart.x/ClipSpaceStart.w + 1 ) / 2) * framewidth, ((ClipSpaceStart.y/ClipSpaceStart.w + 1 ) / 2) * frameheight }; glm::vec2 ScreenSpaceStart = {
glm::vec2 ScreenSpaceEnd = {((ClipSpaceEnd.x/ClipSpaceEnd.w + 1 ) / 2) * framewidth, ((ClipSpaceEnd.y/ClipSpaceEnd.w + 1 ) / 2) * frameheight}; ((ClipSpaceStart.x / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceStart.y / ClipSpaceStart.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
glm::vec2 ScreenSpaceEnd = {
((ClipSpaceEnd.x / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().x,
((ClipSpaceEnd.y / ClipSpaceEnd.w + 1) / 2) * (float)m_internalFramebuf->getSize().y};
glm::vec2 ScrenSpaceDir = ScreenSpaceEnd - ScreenSpaceStart; glm::vec2 ScrenSpaceDir = ScreenSpaceEnd - ScreenSpaceStart;
@ -568,11 +663,13 @@ void MainViewport::HandleInput(InputEvent event) {
glReadBuffer(GL_COLOR_ATTACHMENT2); glReadBuffer(GL_COLOR_ATTACHMENT2);
glm::vec4 CurWDirPos = {0, 0, 0, 0}; glm::vec4 CurWDirPos = {0, 0, 0, 0};
glReadPixels(floorf(FixedMousePos.x), floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT, glm::value_ptr(CurWDirPos)); glReadPixels((int)floorf(FixedMousePos.x), (int)floorf(FixedMousePos.y), 1, 1, GL_RGBA, GL_FLOAT,
glm::value_ptr(CurWDirPos));
//std::cout << glm::to_string(CurWDirPos) << std::endl; //std::cout << glm::to_string(CurWDirPos) << std::endl;
auto DirProjectedTranslationPos = ProjectToRayNormalized({CurWDirPos.x,-CurWDirPos.y,CurWDirPos.z},GizmoDir); auto DirProjectedTranslationPos = ProjectToRayNormalized(
{CurWDirPos.x, CurWDirPos.y, CurWDirPos.z}, GizmoDir);
if (SpecialObjCur == 1) { if (SpecialObjCur == 1) {
SelObj->TF.Position.X = ObjBindingVec.x + DirProjectedTranslationPos.x; SelObj->TF.Position.X = ObjBindingVec.x + DirProjectedTranslationPos.x;
@ -626,21 +723,24 @@ void MainViewport::HandleInput(InputEvent event) {
CurWDirPos -= glm::vec4(ObjPos, 1); CurWDirPos -= glm::vec4(ObjPos, 1);
auto DirProjectedTranslationPos = ProjectToRayNormalized(
auto DirProjectedTranslationPos = ProjectToRayNormalized({CurWDirPos.x,-CurWDirPos.y,CurWDirPos.z},GizmoDir); {CurWDirPos.x, CurWDirPos.y, CurWDirPos.z}, GizmoDir);
float VecComp = GetVecComponent(DirProjectedTranslationPos, GizmoDir); float VecComp = GetVecComponent(DirProjectedTranslationPos, GizmoDir);
float DeltaInDir = 0; float DeltaInDir = 0;
if (SpecialObjCur == 1) { if (SpecialObjCur == 1) {
DeltaInDir = (ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x) - SelObj->TF.Scale.X; DeltaInDir = (ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x) -
SelObj->TF.Scale.X;
SelObj->TF.Scale.X = ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x; SelObj->TF.Scale.X = ObjBindingVec.x + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.x;
} else if (SpecialObjCur == 2) { } else if (SpecialObjCur == 2) {
DeltaInDir = (ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y) - SelObj->TF.Scale.Y; DeltaInDir = (ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y) -
SelObj->TF.Scale.Y;
SelObj->TF.Scale.Y = ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y; SelObj->TF.Scale.Y = ObjBindingVec.y + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.y;
} else if (SpecialObjCur == 3) { } else if (SpecialObjCur == 3) {
DeltaInDir = (ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z) - SelObj->TF.Scale.Z; DeltaInDir = (ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z) -
SelObj->TF.Scale.Z;
SelObj->TF.Scale.Z = ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z; SelObj->TF.Scale.Z = ObjBindingVec.z + ((VecComp / ObjScalingDist) - 1) * ObjBindingVec.z;
} }
@ -665,10 +765,12 @@ void MainViewport::HandleInput(InputEvent event) {
break; break;
case (InputType::MouseHoldR): case (InputType::MouseHoldR):
ImGui::SetWindowFocus(); ImGui::SetWindowFocus();
camrot.x += (lastMpos.x - currentMpos.x) * (float) framewidth * .1f; camrot.x += (lastMpos.x - currentMpos.x) * (float) m_internalFramebuf->getSize().x * .1f;
camrot.y -= (lastMpos.y - currentMpos.y) * (float) frameheight * .1f; camrot.y += (lastMpos.y - currentMpos.y) * (float) m_internalFramebuf->getSize().y * .1f;
lastMpos = currentMpos; lastMpos = currentMpos;
break; break;
default:
break;
} }
} }

View file

@ -7,12 +7,14 @@
#include <queue> #include <queue>
#include "virintox/gcore/ViewportWidget.h" #include "virintox/gcore/gui/ViewportWidget.h"
#include "virintox/gcore/Shader.h" #include "virintox/gcore/Shader.h"
#include "glm/vec3.hpp" #include "glm/vec3.hpp"
#include "virintox/gcore/Mesh.h" #include "virintox/gcore/Mesh.h"
#include "Model.h" #include "Model.h"
#include "boost/thread.hpp" #include "boost/thread.hpp"
#include "Rail.h"
#include "LevelObject.h"
enum GizmoType{ enum GizmoType{
Move,Rotate,Scale Move,Rotate,Scale
@ -22,14 +24,14 @@ class MainViewport : public Graphics::ViewportWidget {
public: public:
MainViewport(); MainViewport();
Graphics::Shader shader;
glm::vec3 camPos = glm::vec3(0,0,0); glm::vec3 camPos = glm::vec3(0,0,0);
glm::vec2 camrot = glm::vec2(0,0); glm::vec2 camrot = glm::vec2(0,0);
float shadowArea = 750.0f;
float fov = 90.0f; float fov = 90.0f;
std::vector<std::vector<unsigned int>> PixelToObjNum; //std::vector<std::vector<unsigned int>> PixelToObjNum;
float speed = 100.0f; float speed = 100.0f;
bool drawAllAreas = false; bool drawAllAreas = false;
@ -42,12 +44,23 @@ private:
std::map<std::string,Model> MdlFromObj; std::map<std::string,Model> MdlFromObj;
float FarClippingPlane = 10000.0f;
float NearClippingPlane = 0.1f;
glm::mat4 VP; glm::mat4 VP;
glm::vec3 LightDir = {1,1,1};
float ShadingEffectiveness = 0.5f;
void RenderRail(Rail* rail);
//Graphics::Mesh ObjMesh; //Graphics::Mesh ObjMesh;
glm::vec2 CalcGizmoDir(glm::vec3 dir); glm::vec2 CalcGizmoDir(glm::vec3 dir);
glm::vec3 ScreenSpaceToRay(glm::vec2); glm::vec3 ScreenSpaceToRay(glm::vec2);
void DrawOver() override; void DrawOver() override;
std::unique_ptr<Graphics::Framebuffer> SunCam;
public: public:
void HandleInput(InputEvent event) override; void HandleInput(InputEvent event) override;

View file

@ -3,7 +3,7 @@
#include "ObjectSelectWidget.h" #include "ObjectSelectWidget.h"
#include "RailSelectWidget.h" #include "RailSelectWidget.h"
#include "MainViewport.h" #include "MainViewport.h"
#include <virintox/gcore/FileSelectDialog.h> #include <virintox/gcore/gui/FileSelectDialog.h>
#include <virintox/gcore/Graphics.h> #include <virintox/gcore/Graphics.h>
#include<imgui.h> #include<imgui.h>
#include <IconsFontAwesome6.h> #include <IconsFontAwesome6.h>
@ -85,6 +85,16 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
MainWindowInst->WidgetByName.find("Properties")->second->Active ^= true; MainWindowInst->WidgetByName.find("Properties")->second->Active ^= true;
}); });
AddMenu("Game");
AddMenuItem("Game", "Gambit(1)", [&](){
gameSetting = GameMode::Gambit;
});
AddMenuItem("Game", "Blitz(2)", [&](){
gameSetting = GameMode::Blitz;
});
AddMenuItem("Game", "Thunder(3)", [&](){
gameSetting = GameMode::Thunder;
});
AddMenu("Object"); AddMenu("Object");
@ -108,6 +118,16 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
ObjCpy.TF.Rotation = {0, 0, 0}; ObjCpy.TF.Rotation = {0, 0, 0};
ObjCpy.TF.Position = {0, 0, 0}; ObjCpy.TF.Position = {0, 0, 0};
for(long &param: ObjCpy.Parameters){
param = -99;
}
for(float &param: ObjCpy.FloatParameters){
param = -99.0f;
}
ObjCpy.Layer = Common;
ExportObj(ObjCpy); ExportObj(ObjCpy);
} }
} }
@ -127,6 +147,17 @@ MainWindow::MainWindow(): Graphics::Window("SpoonEdit") {
LevelObject ObjCpy = LevelObject(obj); LevelObject ObjCpy = LevelObject(obj);
ObjCpy.Name = ObjCpy.Type; ObjCpy.Name = ObjCpy.Type;
ObjCpy.Links = std::vector<Link>(); ObjCpy.Links = std::vector<Link>();
for(long &param: ObjCpy.Parameters){
param = -99;
}
for(float &param: ObjCpy.FloatParameters){
param = -99.0f;
}
ObjCpy.Layer = Common;
ObjCpy.TF.Scale = {1, 1, 1}; ObjCpy.TF.Scale = {1, 1, 1};
ObjCpy.TF.Rotation = {0, 0, 0}; ObjCpy.TF.Rotation = {0, 0, 0};
ObjCpy.TF.Position = {0, 0, 0}; ObjCpy.TF.Position = {0, 0, 0};
@ -146,6 +177,11 @@ void MainWindow::Update() {
} }
void MainWindow::MenuExtraRender() {
ImGui::SetCursorPosX(ImGui::GetWindowWidth() - ImGui::CalcTextSize(("Game: " + GameMode::ToString(gameSetting) + " ").c_str()).x);
ImGui::Text("%s", ("Game: " + GameMode::ToString(gameSetting)).c_str());
}
MainWindow* GetMainWindow(){ MainWindow* GetMainWindow(){
return MainWindowInst; return MainWindowInst;
} }

View file

@ -5,8 +5,30 @@
#ifndef SPOONTOOL_MAINWINDOW_H #ifndef SPOONTOOL_MAINWINDOW_H
#define SPOONTOOL_MAINWINDOW_H #define SPOONTOOL_MAINWINDOW_H
#include<virintox/gcore/Window.h> #include<virintox/gcore/gui/Window.h>
#include<Map.h> #include<Map.h>
namespace GameMode {
enum GameMode {
Gambit,
Blitz,
Thunder
};
inline std::string ToString(GameMode gameMode){
switch(gameMode){
case Gambit:
return "Gambit";
case Blitz:
return "Blitz";
case Thunder:
return "Thunder";
default:
return "Invalid";
}
}
inline std::array<GameMode,3> gameModes = {Gambit, Blitz, Thunder};
}
class MainWindow : public Graphics::Window { class MainWindow : public Graphics::Window {
@ -18,6 +40,10 @@ public:
void Update() override; void Update() override;
Element* selectedElem = nullptr; Element* selectedElem = nullptr;
GameMode::GameMode gameSetting = GameMode::Gambit;
protected:
void MenuExtraRender() override;
}; };
MainWindow* GetMainWindow(); MainWindow* GetMainWindow();

View file

@ -9,8 +9,17 @@
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#include <virintox/gcore/Graphics.h> #include <virintox/gcore/Graphics.h>
#include "Transform.h" #include "Transform.h"
#include<glm/mat4x4.hpp>
#include "glm/ext/vector_float3.hpp"
#include "glm/ext/matrix_transform.hpp"
#include<glm/mat3x2.hpp>
#include<glm/mat3x3.hpp>
#include<glm/vec3.hpp>
#include<glm/vec2.hpp>
Model::Model(std::string modelname) { Model::Model(std::string modelname) {
CopyCount = new unsigned(1);
auto modeltoload = boost::filesystem::current_path() / "Models" / modelname / (modelname + ".dae"); auto modeltoload = boost::filesystem::current_path() / "Models" / modelname / (modelname + ".dae");
Assimp::Importer importer; Assimp::Importer importer;
@ -19,6 +28,7 @@ Model::Model(std::string modelname) {
aiProcess_Triangulate | aiProcess_Triangulate |
aiProcess_JoinIdenticalVertices | aiProcess_JoinIdenticalVertices |
// aiProcess_Debone | // aiProcess_Debone |
aiProcess_GenNormals |
aiProcess_FlipUVs | aiProcess_FlipUVs |
aiProcess_SortByPType); aiProcess_SortByPType);
@ -32,38 +42,33 @@ Model::Model(std::string modelname) {
auto mesh = scene->mMeshes[i]; auto mesh = scene->mMeshes[i];
auto mat = scene->mMaterials[mesh->mMaterialIndex]; auto mat = scene->mMaterials[mesh->mMaterialIndex];
std::string firsttex; Materials.push_back(new Graphics::Material(mat,boost::filesystem::current_path() / "Models" / modelname));
for(unsigned int currenttex = 0; currenttex < mat->GetTextureCount(aiTextureType_DIFFUSE); currenttex++){
aiString string;
mat->GetTexture(aiTextureType_DIFFUSE, 0, &string);
if(firsttex == "")
firsttex = string.C_Str();
else
Graphics::window->msgBoxes.push_back(new Graphics::MessageBox("SUS ඞ",Graphics::ErrorSeverity::Error));
Textures.emplace_back((boost::filesystem::current_path() / "Models" / modelname / string.C_Str()));
}
if(firsttex == ""){
Textures.emplace_back((boost::filesystem::current_path() / "Models" / "Missing.png"));
}
auto vertices = std::vector<glm::vec3>(); auto vertices = std::vector<glm::vec3>();
auto texcoords = std::vector<glm::vec2>(); auto texcoords = std::vector<glm::vec2>();
auto normals = std::vector<glm::vec3>();
auto tangents = std::vector<glm::vec3>();
auto bitangents = std::vector<glm::vec3>();
auto indices = std::vector<GLuint>(); auto indices = std::vector<GLuint>();
for(unsigned int verticienum = 0; verticienum < mesh->mNumVertices; verticienum++){ for(unsigned int verticienum = 0; verticienum < mesh->mNumVertices; verticienum++){
vertices.emplace_back(mesh->mVertices[verticienum].x,mesh->mVertices[verticienum].y,mesh->mVertices[verticienum].z); vertices.emplace_back(mesh->mVertices[verticienum].x,mesh->mVertices[verticienum].y,mesh->mVertices[verticienum].z);
normals.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
if (mesh->HasTextureCoords(0)) // Only slot [0] is in question. if (mesh->HasTextureCoords(0)) // Only slot [0] is in question.
{ {
texcoords.emplace_back(mesh->mTextureCoords[0][verticienum].x,mesh->mTextureCoords[0][verticienum].y); texcoords.emplace_back(mesh->mTextureCoords[0][verticienum].x,mesh->mTextureCoords[0][verticienum].y);
tangents.emplace_back(mesh->mTangents[verticienum].x,mesh->mTangents[verticienum].y,mesh->mTangents[verticienum].z);
bitangents.emplace_back(mesh->mBitangents[verticienum].x,mesh->mBitangents[verticienum].y,mesh->mBitangents[verticienum].z);
} }
else else {
texcoords.emplace_back(0.0f, 0.0f); texcoords.emplace_back(0.0f, 0.0f);
tangents.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
bitangents.emplace_back(mesh->mNormals[verticienum].x,mesh->mNormals[verticienum].y,mesh->mNormals[verticienum].z);
}
} }
for (unsigned int i3 = 0; i3 < mesh->mNumFaces; ++i3) { for (unsigned int i3 = 0; i3 < mesh->mNumFaces; ++i3) {
@ -73,40 +78,84 @@ Model::Model(std::string modelname) {
indices.push_back(mesh->mFaces[i3].mIndices[i4]); indices.push_back(mesh->mFaces[i3].mIndices[i4]);
} }
Meshes.emplace_back(vertices,indices,texcoords,GetMainViewport()->shader); Meshes.push_back(new Graphics::Mesh(vertices,indices,texcoords,normals,tangents,bitangents));
} }
} }
void Model::Draw(Transform tf) { void Model::Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP) {
unsigned int texnum = 0; unsigned int texnum = 0;
for(auto mesh: Meshes){ for(auto& mesh: Meshes){
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z); glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,-tf.Rotation.Z); glm::vec3 rot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 normalRot(tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z); glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
mesh.Draw(Textures[texnum],pos,scale,rot); glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 translationNoYInvertMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 nrmRotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(normalRot.z), glm::vec3(0,0,1));
glm::mat4 nrmRotationMatrixY = glm::rotate(nrmRotationMatrixZ,glm::radians(normalRot.y), glm::vec3(0,1,0));
glm::mat4 nrmRotationMatrix = glm::rotate(nrmRotationMatrixY,glm::radians(normalRot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 ModelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * nrmRotationMatrix * scaleMatrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint ModelMatrixID = shader.getUniformLocation("ModelMatrix");
glUniformMatrix4fv(ModelMatrixID,1,GL_FALSE,&ModelMatrix[0][0]);
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
GLuint RotationMatrixID = shader.getUniformLocation("NormalRotationMatrix");
glUniformMatrix4fv(RotationMatrixID,1,GL_FALSE,&nrmRotationMatrix[0][0]);
mesh->Draw(Materials[texnum]);
texnum++; texnum++;
} }
} }
void Model::DrawSelection(Transform tf) { void Model::DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP) {
unsigned int texnum = 0; unsigned int texnum = 0;
static Graphics::Texture selectionTex = Graphics::Texture((boost::filesystem::current_path() / "Models" / "selected.png")); static Graphics::Texture selectionTex = Graphics::Texture((boost::filesystem::current_path() / "Models" / "selected.png"));
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
for(auto mesh: Meshes){ for(auto &mesh: Meshes){
glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z); glm::vec3 pos(tf.Position.X,tf.Position.Y,tf.Position.Z);
glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z); glm::vec3 rot(-tf.Rotation.X,tf.Rotation.Y,tf.Rotation.Z);
glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z); glm::vec3 scale(tf.Scale.X,tf.Scale.Y,tf.Scale.Z);
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,-pos.y,pos.z));
glm::mat4 translationNoYInvertMatrix = glm::translate(glm::mat4(1),glm::vec3(pos.x,pos.y,pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(rot.y), glm::vec3(0,1,0));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),scale);
glm::mat4 matrix = VP * translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * rotationMatrix * scaleMatrix;
GLuint MatrixID = shader.getUniformLocation("MVP");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint MatrixNoYInvID = shader.getUniformLocation("TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
mesh.Draw(selectionTex,pos,scale,rot);
mesh->Draw(Materials[texnum]);
texnum++; texnum++;
} }
@ -115,4 +164,20 @@ void Model::DrawSelection(Transform tf) {
} }
Model::~Model() {
(*CopyCount)--;
if((*CopyCount) == 0) {
for (Graphics::Material *mat: Materials)
delete mat;
for (Graphics::Mesh *mesh: Meshes)
delete mesh;
}
}
Model::Model(const Model &mdl): CopyCount(mdl.CopyCount), Meshes(mdl.Meshes), Materials(mdl.Materials) {
(*CopyCount)++;
}

View file

@ -10,17 +10,24 @@
#include<map> #include<map>
#include "virintox/gcore/Mesh.h" #include "virintox/gcore/Mesh.h"
#include "Transform.h" #include "Transform.h"
#include "virintox/gcore/Material.h"
class Model { class Model {
public: public:
Model(std::string modelName); Model(std::string modelName);
void Draw(Transform tf); Model(const Model& mdl);
void DrawSelection(Transform tf); ~Model();
unsigned *CopyCount;
void Draw(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
void DrawSelection(Transform tf, Graphics::Shader &shader, glm::mat4 VP);
protected: protected:
std::vector<Graphics::Mesh> Meshes; std::list<Graphics::Mesh*> Meshes;
std::vector<Graphics::Texture> Textures; std::vector<Graphics::Material*> Materials;
//std::map<std::string,Graphics::Texture> TexturesForName; //std::map<std::string,Graphics::Texture> TexturesForName;
}; };

View file

@ -6,7 +6,7 @@
#define SPOONTOOL_OBJECTSELECTWIDGET_H #define SPOONTOOL_OBJECTSELECTWIDGET_H
#include "virintox/gcore/Widget.h" #include "virintox/gcore/gui/Widget.h"
class ObjectSelectWidget: public Graphics::Widget { class ObjectSelectWidget: public Graphics::Widget {
public: public:

View file

@ -110,6 +110,14 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
ImGuiDrawSelection("Link Type##" + std::to_string(i) + Id, link.Name, LinkTypes.begin(), LinkTypes.end(), ImGuiDrawSelection("Link Type##" + std::to_string(i) + Id, link.Name, LinkTypes.begin(), LinkTypes.end(),
[](std::string s) { return s; }); [](std::string s) { return s; });
ImGui::InputText(("Destination##PropWindLink" + std::to_string(i) + Id).c_str(), &link.Destination); ImGui::InputText(("Destination##PropWindLink" + std::to_string(i) + Id).c_str(), &link.Destination);
if(Element* gotoElem = GetMainWindow()->loadedMap.GetElementById(link.Destination)) {
ImGui::SameLine();
if (ImGui::Button(ICON_FA_CHEVRON_RIGHT)) {
GetMainWindow()->selectedElem = gotoElem;
}
}
ImGui::InputText(("Unit File##PropWindLink" + std::to_string(i) + Id).c_str(), &link.UnitFile); ImGui::InputText(("Unit File##PropWindLink" + std::to_string(i) + Id).c_str(), &link.UnitFile);
if(ImGui::Button((ICON_FA_TRASH "##PropWindLinkDelete" + std::to_string(i) + Id).c_str())) { if(ImGui::Button((ICON_FA_TRASH "##PropWindLinkDelete" + std::to_string(i) + Id).c_str())) {
elem->Links.erase(linkIter); elem->Links.erase(linkIter);
@ -188,9 +196,9 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
if(!elem->Parameters.empty()) { if(!elem->Parameters.empty()) {
if (ImGui::CollapsingHeader(("Parameters##" + Id).c_str())) { if (ImGui::CollapsingHeader(("Parameters##" + Id).c_str())) {
ImGui::Indent(); ImGui::Indent();
for (int i = 1; i <= elem->Parameters.size(); i++) { for (int i = 0; i < elem->Parameters.size(); i++) {
ImGui::InputInt(("Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(), ImGui::InputInt(("Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(),
(int *) &elem->Parameters[i - 1]); (int *) &elem->Parameters[i]);
} }
ImGui::Unindent(); ImGui::Unindent();
} }
@ -199,9 +207,9 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
if(!elem->FloatParameters.empty()) { if(!elem->FloatParameters.empty()) {
if (ImGui::CollapsingHeader(("Float Parameters##" + Id).c_str())) { if (ImGui::CollapsingHeader(("Float Parameters##" + Id).c_str())) {
ImGui::Indent(); ImGui::Indent();
for (int i = 1; i <= elem->FloatParameters.size(); i++) { for (int i = 0; i < elem->FloatParameters.size(); i++) {
ImGui::InputFloat(("Float Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(), ImGui::InputFloat(("Float Parameter " + std::to_string(i) + "##PropWind" + Id).c_str(),
&elem->FloatParameters[i - 1]); &elem->FloatParameters[i]);
} }
ImGui::Unindent(); ImGui::Unindent();
} }

View file

@ -6,7 +6,7 @@
#define SPOONTOOL_PROPERTIESWIDGET_H #define SPOONTOOL_PROPERTIESWIDGET_H
#include "virintox/gcore/Widget.h" #include "virintox/gcore/gui/Widget.h"
class PropertiesWidget : public Graphics::Widget { class PropertiesWidget : public Graphics::Widget {
public: public:

View file

@ -5,7 +5,7 @@
#ifndef SPOONTOOL_RAILSELECTWIDGET_H #ifndef SPOONTOOL_RAILSELECTWIDGET_H
#define SPOONTOOL_RAILSELECTWIDGET_H #define SPOONTOOL_RAILSELECTWIDGET_H
#include<virintox/gcore/Widget.h> #include<virintox/gcore/gui/Widget.h>
class RailSelectWidget: public Graphics::Widget { class RailSelectWidget: public Graphics::Widget {