From 6aa655f3f11dab68940809ce567f7499c40f4f49 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Wed, 2 Sep 2020 03:46:17 -0700 Subject: [PATCH] Add painting system --- CMakeLists.txt | 2 +- src/game/bootloader.cpp | 6 + src/game/components/brush-component.hpp | 32 +++ src/game/game-context.hpp | 2 + src/game/states/play-state.cpp | 4 +- src/game/systems/painting-system.cpp | 272 ++++++++++++++++++++++ src/game/systems/painting-system.hpp | 84 +++++++ src/game/systems/tracking-system.cpp | 17 -- src/game/systems/tracking-system.hpp | 6 +- src/renderer/material-flags.hpp | 2 + src/renderer/passes/material-pass.cpp | 37 ++- src/renderer/passes/outline-pass.cpp | 7 +- src/resources/entity-archetype-loader.cpp | 16 ++ src/scene/model-instance.hpp | 3 +- 14 files changed, 459 insertions(+), 31 deletions(-) create mode 100644 src/game/components/brush-component.hpp create mode 100644 src/game/systems/painting-system.cpp create mode 100644 src/game/systems/painting-system.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6fdd6..1405aa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") + # Determine dependencies set(STATIC_LIBS dr_wav @@ -27,7 +28,6 @@ set(STATIC_LIBS set(SHARED_LIBS ${OPENGL_gl_LIBRARY}) - # Generate configuration header file configure_file(${PROJECT_SOURCE_DIR}/src/configuration.hpp.in ${PROJECT_BINARY_DIR}/src/configuration.hpp) diff --git a/src/game/bootloader.cpp b/src/game/bootloader.cpp index 713bcff..a0c7687 100644 --- a/src/game/bootloader.cpp +++ b/src/game/bootloader.cpp @@ -77,6 +77,7 @@ #include "game/systems/vegetation-system.hpp" #include "game/systems/spatial-system.hpp" #include "game/systems/tracking-system.hpp" +#include "game/systems/painting-system.hpp" #include "game/components/marker-component.hpp" #include "game/entity-commands.hpp" #include "utility/paths.hpp" @@ -841,6 +842,10 @@ void setup_systems(game_context* ctx) ctx->tracking_system = new tracking_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager); ctx->tracking_system->set_scene(ctx->overworld_scene); + // Setup painting system + ctx->painting_system = new painting_system(*ctx->ecs_registry, event_dispatcher, ctx->resource_manager); + ctx->painting_system->set_scene(ctx->overworld_scene); + // Setup render system ctx->render_system = new ::render_system(*ctx->ecs_registry); ctx->render_system->add_layer(ctx->overworld_scene); @@ -1189,6 +1194,7 @@ void setup_callbacks(game_context* ctx) ctx->spatial_system->update(t, dt); ctx->constraint_system->update(t, dt); ctx->tracking_system->update(t, dt); + ctx->painting_system->update(t, dt); //(*ctx->focal_point_tween)[1] = ctx->orbit_cam->get_focal_point(); diff --git a/src/game/components/brush-component.hpp b/src/game/components/brush-component.hpp new file mode 100644 index 0000000..c54f91d --- /dev/null +++ b/src/game/components/brush-component.hpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2020 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_ECS_BRUSH_COMPONENT_HPP +#define ANTKEEPER_ECS_BRUSH_COMPONENT_HPP + +namespace ecs { + +struct brush_component +{ + float radius; +}; + +} // namespace ecs + +#endif // ANTKEEPER_ECS_BRUSH_COMPONENT_HPP diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index cdcb105..b793b0e 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -85,6 +85,7 @@ class input_mapper; class cli; class outline_pass; class tracking_system; +class painting_system; template class animation; template class material_property; template class tween; @@ -237,6 +238,7 @@ struct game_context vegetation_system* vegetation_system; spatial_system* spatial_system; tracking_system* tracking_system; + painting_system* painting_system; // Debug cli* cli; diff --git a/src/game/states/play-state.cpp b/src/game/states/play-state.cpp index e8f78ba..73fa9b3 100644 --- a/src/game/states/play-state.cpp +++ b/src/game/states/play-state.cpp @@ -125,8 +125,8 @@ void play_state_enter(game_context* ctx) ec::assign_render_layers(ecs_registry, ctx->container_entity, 0); ec::assign_render_layers(ecs_registry, ctx->twig_entity, 0); - // Activate lens tool - ctx->tool_system->set_active_tool(ctx->lens_entity); + // Activate brush tool + ctx->tool_system->set_active_tool(ctx->brush_entity); // Create ant-hill auto ant_hill_entity = ant_hill_archetype->create(ecs_registry); diff --git a/src/game/systems/painting-system.cpp b/src/game/systems/painting-system.cpp new file mode 100644 index 0000000..c57a8e2 --- /dev/null +++ b/src/game/systems/painting-system.cpp @@ -0,0 +1,272 @@ +/* + * Copyright (C) 2020 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#include "painting-system.hpp" +#include "game/components/transform-component.hpp" +#include "game/components/brush-component.hpp" +#include "event/event-dispatcher.hpp" +#include "resources/resource-manager.hpp" +#include "scene/scene.hpp" +#include "scene/model-instance.hpp" +#include "math/math.hpp" +#include "renderer/material.hpp" +#include "renderer/model.hpp" +#include "utility/fundamental-types.hpp" +#include "game/entity-commands.hpp" +#include "game/components/collision-component.hpp" +#include "game/components/transform-component.hpp" +#include "rasterizer/vertex-buffer.hpp" +#include "rasterizer/vertex-attribute-type.hpp" +#include "renderer/vertex-attributes.hpp" +#include + +using namespace ecs; + +painting_system::painting_system(entt::registry& registry, ::event_dispatcher* event_dispatcher, ::resource_manager* resource_manager): + entity_system(registry), + event_dispatcher(event_dispatcher), + resource_manager(resource_manager), + scene(nullptr), + painting(false) +{ + event_dispatcher->subscribe(this); + event_dispatcher->subscribe(this); + + max_miter_angle = math::radians(135.0f); + stroke_width = 1.0f; + min_stroke_length = 1.0f; + min_stroke_length_squared = min_stroke_length * min_stroke_length; + max_stroke_segments = 4096; + current_stroke_segment = 0; + std::size_t vertex_size = 4; + std::size_t vertex_stride = sizeof(float) * vertex_size; + std::size_t vertex_count = max_stroke_segments * 6; + + // Create stroke model + stroke_model = new model(); + stroke_model_group = stroke_model->add_group(); + stroke_model_group->set_material(resource_manager->load("brushstroke.mtl")); + + // Setup stroke vbo and vao + stroke_vbo = stroke_model->get_vertex_buffer(); + stroke_vbo->repurpose(sizeof(float) * vertex_size * vertex_count, nullptr, buffer_usage::dynamic_draw); + stroke_model->get_vertex_array()->bind_attribute(VERTEX_POSITION_LOCATION, *stroke_vbo, 4, vertex_attribute_type::float_32, vertex_stride, 0); + + // Create stroke model instance + stroke_model_instance = new model_instance(); + stroke_model_instance->set_model(stroke_model); + stroke_model_instance->update_tweens(); + + stroke_bounds_min.x = std::numeric_limits::infinity(); + stroke_bounds_min.y = std::numeric_limits::infinity(); + stroke_bounds_min.z = std::numeric_limits::infinity(); + stroke_bounds_max.x = -std::numeric_limits::infinity(); + stroke_bounds_max.y = -std::numeric_limits::infinity(); + stroke_bounds_max.z = -std::numeric_limits::infinity(); + + midstroke = false; +} + +painting_system::~painting_system() +{ + event_dispatcher->unsubscribe(this); + event_dispatcher->unsubscribe(this); +} + +void painting_system::update(double t, double dt) +{ + if (painting) + { + auto cast_result = cast_ray(ec::get_world_transform(registry, brush_entity).translation); + if (cast_result.has_value()) + { + float3 p2 = + stroke_end = cast_result.value(); + + float3 segment_difference = stroke_end - stroke_start; + float segment_length_squared = math::dot(segment_difference, segment_difference); + if (segment_length_squared >= min_stroke_length_squared) + { + float segment_length = std::sqrt(segment_length_squared); + + + float3 segment_forward = segment_difference / segment_length; + float3 segment_right = math::normalize(math::cross(segment_forward, float3{0, 1, 0})); + float3 segment_up = math::cross(segment_right, segment_forward); + + float3 segment_center = (stroke_start + stroke_end) * 0.5f; + + float3 p1 = stroke_start; + float3 p2 = stroke_end; + + // Find miter + float3 tangent = math::normalize(math::normalize(p2 - p1) + math::normalize(p1 - p0)); + float2 miter = float2{-tangent.z, tangent.x}; + float2 normal = float2{segment_right.x, segment_right.z}; + float miter_length = stroke_width / math::dot(miter, normal); + + float3 a = p0a; + float3 b = p0b; + float3 c = p1 - segment_right * stroke_width * 0.5f; + float3 d = p1 + segment_right * stroke_width * 0.5f; + float3 e = p2 - segment_right * stroke_width * 0.5f; + float3 f = p2 + segment_right * stroke_width * 0.5f; + + // Adjust c and d + bool mitered = false; + if (midstroke) + { + float angle = std::acos(math::dot(math::normalize(p2 - p1), math::normalize(p1 - p0))); + if (angle < max_miter_angle) + { + mitered = true; + c = p1 - float3{miter.x, 0.0f, miter.y} * miter_length * 0.5f; + d = p1 + float3{miter.x, 0.0f, miter.y} * miter_length * 0.5f; + } + } + + float4 segment_vertices[12]; + float w = static_cast(t); + + segment_vertices[0] = {a.x, a.y, a.z, w}; + segment_vertices[1] = {b.x, b.y, b.z, w}; + segment_vertices[2] = {c.x, c.y, c.z, w}; + segment_vertices[3] = {c.x, c.y, c.z, w}; + segment_vertices[4] = {b.x, b.y, b.z, w}; + segment_vertices[5] = {d.x, d.y, d.z, w}; + segment_vertices[6] = {c.x, c.y, c.z, w}; + segment_vertices[7] = {d.x, d.y, d.z, w}; + segment_vertices[8] = {e.x, e.y, e.z, w}; + segment_vertices[9] = {e.x, e.y, e.z, w}; + segment_vertices[10] = {d.x, d.y, d.z, w}; + segment_vertices[11] = {f.x, f.y, f.z, w}; + + std::size_t segment_size = sizeof(float) * 4 * 6; + if (mitered) + { + stroke_vbo->update((current_stroke_segment - 1) * segment_size, segment_size * 2, &segment_vertices[0][0]); + } + else + { + stroke_vbo->update(current_stroke_segment * segment_size, segment_size, &segment_vertices[6][0]); + } + + ++current_stroke_segment; + + stroke_model_group->set_index_count(current_stroke_segment * 6); + + // Update stroke bounds + stroke_bounds_min.x = std::min(stroke_bounds_min.x, std::min(c.x, std::min(d.x, std::min(e.x, f.x)))); + stroke_bounds_min.y = std::min(stroke_bounds_min.y, std::min(c.y, std::min(d.y, std::min(e.y, f.y)))); + stroke_bounds_min.z = std::min(stroke_bounds_min.z, std::min(c.z, std::min(d.z, std::min(e.z, f.z)))); + stroke_bounds_max.x = std::max(stroke_bounds_max.x, std::max(c.x, std::max(d.x, std::max(e.x, f.x)))); + stroke_bounds_max.y = std::max(stroke_bounds_max.y, std::max(c.y, std::max(d.y, std::max(e.y, f.y)))); + stroke_bounds_max.z = std::max(stroke_bounds_max.z, std::max(c.z, std::max(d.z, std::max(e.z, f.z)))); + stroke_model->set_bounds(aabb{stroke_bounds_min, stroke_bounds_max}); + stroke_model_instance->update_bounds(); + + p0 = stroke_start; + p0a = c; + p0b = d; + stroke_start = stroke_end; + midstroke = true; + } + } + } +} + +void painting_system::set_scene(::scene* scene) +{ + this->scene = scene; + scene->add_object(stroke_model_instance); +} + +void painting_system::handle_event(const tool_pressed_event& event) +{ + if (registry.has(event.entity)) + { + auto cast_result = cast_ray(ec::get_world_transform(registry, event.entity).translation); + + if (cast_result.has_value()) + { + brush_entity = event.entity; + painting = true; + stroke_start = cast_result.value(); + stroke_end = stroke_start; + p0 = stroke_start; + p0a = p0; + p0b = p0; + midstroke = false; + } + } +} + +void painting_system::handle_event(const tool_released_event& event) +{ + if (registry.has(event.entity)) + { + auto cast_result = cast_ray(ec::get_world_transform(registry, event.entity).translation); + + if (cast_result.has_value()) + { + stroke_end = cast_result.value(); + } + + brush_entity = entt::null; + painting = false; + } +} + +std::optional painting_system::cast_ray(const float3& position) const +{ + std::optional result; + + ray untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}}; + float min_distance = std::numeric_limits::infinity(); + + registry.view().each( + [&](auto entity, auto& collision_transform, auto& collision) + { + // Transform ray into local space of collision component + math::transform inverse_transform = math::inverse(collision_transform.local); + float3 origin = inverse_transform * untransformed_ray.origin; + float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * untransformed_ray.direction); + ray transformed_ray = {origin, direction}; + + // Broad phase AABB test + auto aabb_result = ray_aabb_intersection(transformed_ray, collision.bounds); + if (!std::get<0>(aabb_result)) + { + return; + } + + // Narrow phase mesh test + auto mesh_result = collision.mesh_accelerator.query_nearest(transformed_ray); + if (mesh_result) + { + if (mesh_result->t < min_distance) + { + min_distance = mesh_result->t; + result = untransformed_ray.extrapolate(min_distance); + } + } + }); + + return result; +} diff --git a/src/game/systems/painting-system.hpp b/src/game/systems/painting-system.hpp new file mode 100644 index 0000000..7544da6 --- /dev/null +++ b/src/game/systems/painting-system.hpp @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2020 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_PAINTING_SYSTEM_HPP +#define ANTKEEPER_PAINTING_SYSTEM_HPP + +#include "entity-system.hpp" +#include "event/event-handler.hpp" +#include "game/events/tool-events.hpp" +#include "utility/fundamental-types.hpp" +#include +#include + +class material; +class event_dispatcher; +class resource_manager; +class scene; +class model; +class model_instance; +class model_group; +class vertex_buffer; + +class painting_system: public entity_system, + public event_handler, + public event_handler +{ +public: + painting_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager); + virtual ~painting_system(); + virtual void update(double t, double dt); + + void set_scene(scene* scene); + +private: + virtual void handle_event(const tool_pressed_event& event); + virtual void handle_event(const tool_released_event& event); + + std::optional cast_ray(const float3& position) const; + + event_dispatcher* event_dispatcher; + resource_manager* resource_manager; + scene* scene; + + bool painting; + entt::entity brush_entity; + float3 stroke_start; + float3 stroke_end; + float min_stroke_length; + float min_stroke_length_squared; + float stroke_width; + int max_stroke_segments; + int current_stroke_segment; + float max_miter_angle; + float3 stroke_bounds_min; + float3 stroke_bounds_max; + float3 p0; + float3 p0a; + float3 p0b; + + model* stroke_model; + model_group* stroke_model_group; + vertex_buffer* stroke_vbo; + bool midstroke; + + model_instance* stroke_model_instance; +}; + +#endif // ANTKEEPER_PAINTING_SYSTEM_HPP diff --git a/src/game/systems/tracking-system.cpp b/src/game/systems/tracking-system.cpp index 3b2cdda..ce4987b 100644 --- a/src/game/systems/tracking-system.cpp +++ b/src/game/systems/tracking-system.cpp @@ -22,18 +22,13 @@ #include "game/components/marker-component.hpp" #include "event/event-dispatcher.hpp" #include "resources/resource-manager.hpp" -#include "scene/billboard.hpp" #include "scene/scene.hpp" #include "scene/model-instance.hpp" #include "math/math.hpp" #include "renderer/material.hpp" -#include "renderer/material-flags.hpp" #include "renderer/model.hpp" -#include "rasterizer/texture-2d.hpp" -#include "rasterizer/shader-program.hpp" #include "utility/fundamental-types.hpp" #include "game/entity-commands.hpp" -#include using namespace ecs; @@ -64,14 +59,12 @@ tracking_system::tracking_system(entt::registry& registry, ::event_dispatcher* e event_dispatcher->subscribe(this); event_dispatcher->subscribe(this); - event_dispatcher->subscribe(this); } tracking_system::~tracking_system() { event_dispatcher->unsubscribe(this); event_dispatcher->unsubscribe(this); - event_dispatcher->unsubscribe(this); for (auto it = trackers.begin(); it != trackers.end(); ++it) { @@ -104,11 +97,6 @@ void tracking_system::set_scene(::scene* scene) this->scene = scene; } -void tracking_system::set_viewport(const float4& viewport) -{ - this->viewport = viewport; -} - void tracking_system::on_component_construct(entt::registry& registry, entt::entity entity, trackable_component& component) { @@ -167,8 +155,3 @@ void tracking_system::handle_event(const tool_released_event& event) { } - -void tracking_system::handle_event(const window_resized_event& event) -{ - set_viewport({0.0f, 0.0f, static_cast(event.w), static_cast(event.h)}); -} diff --git a/src/game/systems/tracking-system.hpp b/src/game/systems/tracking-system.hpp index 0663ced..b14e1f5 100644 --- a/src/game/systems/tracking-system.hpp +++ b/src/game/systems/tracking-system.hpp @@ -23,7 +23,6 @@ #include "entity-system.hpp" #include "game/components/trackable-component.hpp" #include "event/event-handler.hpp" -#include "event/window-events.hpp" #include "game/events/tool-events.hpp" #include @@ -36,8 +35,7 @@ class model_instance; class tracking_system: public entity_system, public event_handler, - public event_handler, - public event_handler + public event_handler { public: tracking_system(entt::registry& registry, event_dispatcher* event_dispatcher, resource_manager* resource_manager); @@ -52,12 +50,10 @@ private: void on_component_destroy(entt::registry& registry, entt::entity entity); virtual void handle_event(const tool_pressed_event& event); virtual void handle_event(const tool_released_event& event); - virtual void handle_event(const window_resized_event& event); event_dispatcher* event_dispatcher; resource_manager* resource_manager; scene* scene; - float4 viewport; model* tracker_model; model* paint_ball_model; material** paint_ball_materials; diff --git a/src/renderer/material-flags.hpp b/src/renderer/material-flags.hpp index cd174a0..0c464ae 100644 --- a/src/renderer/material-flags.hpp +++ b/src/renderer/material-flags.hpp @@ -31,6 +31,8 @@ #define MATERIAL_FLAG_OUTLINE 0x20 #define MATERIAL_FLAG_VEGETATION 0x40 #define MATERIAL_FLAG_REFRACTIVE 0x80 +#define MATERIAL_FLAG_DECAL 0x100 +#define MATERIAL_FLAG_DECAL_SURFACE 0x200 #define MATERIAL_FLAG_WIREFRAME 0x80000000 #endif // ANTKEEPER_MATERIAL_FLAGS_HPP diff --git a/src/renderer/passes/material-pass.cpp b/src/renderer/passes/material-pass.cpp index e0d22aa..7fb239c 100644 --- a/src/renderer/passes/material-pass.cpp +++ b/src/renderer/passes/material-pass.cpp @@ -327,6 +327,39 @@ void material_pass::render(render_context* context) const } } + if ((material_flags & MATERIAL_FLAG_DECAL_SURFACE) != (active_material_flags & MATERIAL_FLAG_DECAL_SURFACE)) + { + if (material_flags & MATERIAL_FLAG_DECAL_SURFACE) + { + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 1, ~0); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + glStencilMask(~0); + } + else + { + glDisable(GL_STENCIL_TEST); + glStencilMask(0); + } + } + + if ((material_flags & MATERIAL_FLAG_DECAL) != (active_material_flags & MATERIAL_FLAG_DECAL)) + { + if (material_flags & MATERIAL_FLAG_DECAL) + { + glDisable(GL_DEPTH_TEST); + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_EQUAL, 1, ~0); + glStencilMask(0); + } + else + { + glEnable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + glStencilMask(0); + } + } + /* if ((material_flags & MATERIAL_FLAG_OUTLINE) != (active_material_flags & MATERIAL_FLAG_OUTLINE)) { @@ -334,7 +367,7 @@ void material_pass::render(render_context* context) const { glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xFF); + glStencilFunc(GL_ALWAYS, 2, 0xFF); glStencilMask(0xFF); } else @@ -514,6 +547,8 @@ bool operation_compare(const render_operation& a, const render_operation& b) else if (!b.material) return true; + + bool xray_a = a.material->get_flags() & MATERIAL_FLAG_X_RAY; bool xray_b = b.material->get_flags() & MATERIAL_FLAG_X_RAY; diff --git a/src/renderer/passes/outline-pass.cpp b/src/renderer/passes/outline-pass.cpp index ca8de9c..8550b8e 100644 --- a/src/renderer/passes/outline-pass.cpp +++ b/src/renderer/passes/outline-pass.cpp @@ -72,13 +72,13 @@ void outline_pass::render(render_context* context) const glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glDisable(GL_DEPTH_TEST); + glEnable(GL_STENCIL_TEST); // Render fill { glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xFF); + glStencilFunc(GL_ALWAYS, 2, 0xFF); glStencilMask(0xFF); glDisable(GL_BLEND); @@ -113,8 +113,7 @@ void outline_pass::render(render_context* context) const glDisable(GL_BLEND); } - glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_NOTEQUAL, 1, 0xFF); + glStencilFunc(GL_NOTEQUAL, 2, 0xFF); glStencilMask(0x00); // Setup stroke shader diff --git a/src/resources/entity-archetype-loader.cpp b/src/resources/entity-archetype-loader.cpp index 4bd4314..d3dcfb1 100644 --- a/src/resources/entity-archetype-loader.cpp +++ b/src/resources/entity-archetype-loader.cpp @@ -29,6 +29,7 @@ #include "game/components/nest-component.hpp" #include "game/components/tool-component.hpp" #include "game/components/marker-component.hpp" +#include "game/components/brush-component.hpp" #include "entity/archetype.hpp" #include "game/behavior/ebt.hpp" #include @@ -123,6 +124,20 @@ static bool load_marker_component(archetype& archetype, const std::vector& parameters) +{ + if (parameters.size() != 2) + { + throw std::runtime_error("load_brush_component(): Invalid parameter count."); + } + + brush_component component; + component.radius = std::stof(parameters[1]); + archetype.set(component); + + return true; +} + static bool load_terrain_component(archetype& archetype, const std::vector& parameters) { if (parameters.size() != 4) @@ -199,6 +214,7 @@ static bool load_component(archetype& archetype, resource_manager& resource_mana if (parameters[0] == "tool") return load_tool_component(archetype, parameters); if (parameters[0] == "transform") return load_transform_component(archetype, parameters); if (parameters[0] == "marker") return load_marker_component(archetype, parameters); + if (parameters[0] == "brush") return load_brush_component(archetype, parameters); std::string message = std::string("load_component(): Unknown component type \"") + parameters[0] + std::string("\""); throw std::runtime_error(message); diff --git a/src/scene/model-instance.hpp b/src/scene/model-instance.hpp index 45d7787..926f33c 100644 --- a/src/scene/model-instance.hpp +++ b/src/scene/model-instance.hpp @@ -76,8 +76,9 @@ public: virtual void update_tweens(); -private: void update_bounds(); + +private: virtual void transformed(); model* model;