Implemented SelectionService

This commit is contained in:
Vulpovile
2023-11-05 22:39:06 -08:00
parent ebfbade283
commit b58161cf81
9 changed files with 22073 additions and 62 deletions

View File

@@ -303,24 +303,12 @@
<Filter
Name="DataModelV2"
Filter="">
<File
RelativePath=".\src\include\DataModelV2\BaseButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\BaseGuiInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\DataModelInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\GroupInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\GuiRootInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\ImageButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\Instance.h">
</File>
@@ -345,21 +333,37 @@
<File
RelativePath=".\src\include\DataModelV2\SoundService.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\TextButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\ThumbnailGeneratorInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\ToggleImageButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\WorkspaceInstance.h">
</File>
<File
RelativePath=".\src\include\XplicitNgine\XplicitNgine.h">
</File>
<Filter
Name="Gui"
Filter="">
<File
RelativePath=".\src\include\DataModelV2\BaseButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\BaseGuiInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\GuiRootInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\ImageButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\TextButtonInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV2\ToggleImageButtonInstance.h">
</File>
</Filter>
</Filter>
<Filter
Name="Helpers">
@@ -401,12 +405,18 @@
<File
RelativePath=".\src\include\DataModelV3\LevelInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV3\LightingInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV3\PartInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV3\PVInstance.h">
</File>
<File
RelativePath=".\src\include\DataModelV3\SelectionService.h">
</File>
<File
RelativePath=".\src\include\DataModelV3\WorkspaceInstance.h">
</File>
@@ -684,12 +694,42 @@
<File
RelativePath=".\src\source\DataModelV3\LevelInstance.cpp">
</File>
<File
RelativePath=".\src\source\DataModelV3\LightingInstance.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\source\DataModelV3\PartInstance.cpp">
</File>
<File
RelativePath=".\src\source\DataModelV3\PVInstance.cpp">
</File>
<File
RelativePath=".\src\source\DataModelV3\SelectionService.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\source\DataModelV3\WorkspaceInstance.cpp">
</File>

File diff suppressed because it is too large Load Diff

View File

@@ -4,15 +4,15 @@ using namespace B3D;
#pragma once
// Instances
//#include "WorkspaceInstance.h"
#include "WorkspaceInstance.h"
#include "LevelInstance.h"
#include "PartInstance.h"
//#include "SelectionService.h"
#include "SelectionService.h"
//#include "GuiRootInstance.h"
//#include "ThumbnailGeneratorInstance.h"
#include "XplicitNgine/XplicitNgine.h"
//#include "SoundService.h"
//#include "LightingInstance.h"
#include "LightingInstance.h"
// Libraries
//#include "rapidxml/rapidxml.hpp"
@@ -28,36 +28,35 @@ namespace B3D {
void drawMessage(RenderDevice*);
// Instance getters
// WorkspaceInstance* getWorkspace();
WorkspaceInstance* getWorkspace();
LevelInstance* getLevel();
XplicitNgine* getEngine();
// ThumbnailGeneratorInstance* getThumbnailGenerator();
// SoundService* getSoundService();
// LightingInstance* getLighting();
LightingInstance* getLighting();
std::string message;
bool showMessage;
//Should probably not be here???
G3D::GFontRef font;
// GuiRootInstance* getGuiRoot();
// SelectionService* getSelectionService();
// PartInstance* makePart();
SelectionService* getSelectionService();
void clearLevel();
void toggleRun();
bool isRunning();
// void resetEngine();
void resetEngine();
private:
bool isBrickCount;
Color3 DataModelInstance::bcToRGB(short bc);
// Instances
// WorkspaceInstance* workspace;
WorkspaceInstance* workspace;
LevelInstance* level;
// GuiRootInstance* guiRoot;
// SelectionService* selectionService;
SelectionService* selectionService;
// ThumbnailGeneratorInstance* thumbnailGenerator;
XplicitNgine* xplicitNgine;
// SoundService* soundService;
// LightingInstance* lightingInstance;
LightingInstance* lightingInstance;
bool running;
};

View File

@@ -0,0 +1,41 @@
#pragma once
#include "Instance.h"
namespace B3D
{
class LightingInstance : public Instance
{
public:
LightingInstance(void);
~LightingInstance(void);
// Getters
G3D::Color3 getTopAmbient();
G3D::Color3 getBottomAmbient();
G3D::Color3 getSpotLight();
G3D::Color4 getClearColor();
G3D::SkyRef getSky();
G3D::LightingParameters getLightingParameters();
// Setters
void setTopAmbient(G3D::Color3 newValue);
void setBottomAmbient(G3D::Color3 newValue);
void setSpotLight(G3D::Color3 newValue);
void setClearColor(G3D::Color3 clearColor);
// Functions
void drawSky(RenderDevice* rd);
void suppressSky(bool doSuppress);
void update(RenderDevice* rd);
void drawEffects(RenderDevice* rd);
private:
Reflection::ReflectionProperty<G3D::Color3> topAmbient;
Reflection::ReflectionProperty<G3D::Color3> bottomAmbient;
Reflection::ReflectionProperty<G3D::Color3> spotLight;
Reflection::ReflectionProperty<G3D::Color4> clearColor;
G3D::SkyRef sky;
G3D::LightingParameters lighting;
bool _hideSky;
};
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "Instance.h"
// TODO Port PropertyWindow
//#include "PropertyWindow.h"
namespace B3D{
class SelectionService : public Instance
{
public:
SelectionService(void);
~SelectionService(void);
SelectionService(const SelectionService &oinst);
std::vector<Instance *> getSelection();
void clearSelection();
bool isSelected(Instance * instance);
void addSelected(Instance * instance);
void removeSelected(Instance * instance);
void addSelected(const std::vector<Instance *> &instances);
// TODO Port PropertyWindow
//void setPropertyWindow(PropertyWindow * propertyWindow);
void render(RenderDevice * rd);
private:
void drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, Vector3 size, Vector3 pos, CoordinateFrame c);
std::vector<Instance *> selection;
int mode;
// TODO Port PropertyWindow
//PropertyWindow * propertyWindow;
};
}

View File

@@ -17,14 +17,16 @@ namespace B3D{
};
enum ReflectionType {
TYPE_INT = 0,
TYPE_FLOAT = 1,
TYPE_STRING = 2,
TYPE_VECTOR3 = 3,
TYPE_COLOR3 = 4,
TYPE_CFRAME = 5,
TYPE_BOOLEAN = 6,
TYPE_ENUM = 7
TYPE_INT,
TYPE_FLOAT,
TYPE_STRING,
TYPE_VECTOR3,
TYPE_COLOR3,
TYPE_COLOR4,
TYPE_CFRAME,
TYPE_BOOLEAN,
TYPE_ENUM,
LENGTH
};
}
}

View File

@@ -8,44 +8,45 @@ DataModelInstance::DataModelInstance(void)
name = "Level";
parentDataModel = this;
//workspace = new WorkspaceInstance();
workspace = new WorkspaceInstance();
//guiRoot = new GuiRootInstance();
level = new LevelInstance();
//thumbnailGenerator = new ThumbnailGeneratorInstance();
//soundService = new SoundService();
//lightingInstance = new LightingInstance();
lightingInstance = new LightingInstance();
//selectionService = new SelectionService();
selectionService = new SelectionService();
//TODO change how property window is either passed or accessed
//selectionService->setPropertyWindow(g_usableApp->_propWindow);
showMessage = false;
canDelete = false;
// Parent stuff
//workspace->setParent(this);
workspace->setParent(this);
level->setParent(this);
//soundService->setParent(this);
//lightingInstance->setParent(this);
lightingInstance->setParent(this);
running = false;
//xplicitNgine = NULL;
//resetEngine();
xplicitNgine = NULL;
resetEngine();
}
//TODO implement
/*
void DataModelInstance::resetEngine()
{
if(xplicitNgine != NULL)
delete xplicitNgine;
xplicitNgine = new XplicitNgine();
g_xplicitNgine = xplicitNgine;
for(size_t i = 0; i < getWorkspace()->partObjects.size(); i++)
{
PartInstance* partInstance = getWorkspace()->partObjects[i];
partInstance->physBody = NULL;
}
}
*/
XplicitNgine * DataModelInstance::getEngine()
{
@@ -57,8 +58,8 @@ void DataModelInstance::toggleRun()
running = !running;
//TODO implement (in RunService!!!)
//if(!running)
//resetEngine();
if(!running)
resetEngine();
}
bool DataModelInstance::isRunning()
@@ -68,8 +69,8 @@ bool DataModelInstance::isRunning()
DataModelInstance::~DataModelInstance(void)
{
//TODO implement
//delete xplicitNgine;
//TODO implement in run service
delete xplicitNgine;
}
void DataModelInstance::clearLevel()
@@ -88,6 +89,7 @@ void DataModelInstance::clearLevel()
workspace->clearChildren();*/
}
//TODO move elsewhere
Color3 DataModelInstance::bcToRGB(short bc)
{
switch(bc)
@@ -261,8 +263,7 @@ void DataModelInstance::setMessageBrickCount()
void DataModelInstance::drawMessage(RenderDevice* rd)
{
//TODO implement
/*if(isBrickCount)
if(isBrickCount)
{
int brickCount = 0;
int instCount = 0;
@@ -295,14 +296,13 @@ void DataModelInstance::drawMessage(RenderDevice* rd)
int height = width / 3;
Draw::box(Box(Vector3(x-(width/2), y-(height/2), 0), Vector3(x+(width/2), y+(height/2), 0)), rd, Color4::fromARGB(0x55B2B2B2), Color3::fromARGB(0xB2B2B2));
font->draw2D(rd, message, Vector2(x,y), height/8, Color3::white(), Color4::clear(), GFont::XALIGN_CENTER, GFont::YALIGN_CENTER);
}*/
}
}
//TODO implement
/*WorkspaceInstance* DataModelInstance::getWorkspace()
WorkspaceInstance* DataModelInstance::getWorkspace()
{
return workspace;
}*/
}
//TODO implement
/*GuiRootInstance* DataModelInstance::getGuiRoot()
@@ -310,11 +310,10 @@ void DataModelInstance::drawMessage(RenderDevice* rd)
return guiRoot;
}*/
//TODO implement
/*SelectionService* DataModelInstance::getSelectionService()
SelectionService* DataModelInstance::getSelectionService()
{
return selectionService;
}*/
}
LevelInstance* DataModelInstance::getLevel()
{
@@ -334,7 +333,7 @@ LevelInstance* DataModelInstance::getLevel()
}*/
//TODO implement
/*LightingInstance* DataModelInstance::getLighting()
LightingInstance* DataModelInstance::getLighting()
{
return lightingInstance;
}*/
}

View File

@@ -0,0 +1,106 @@
#include "DataModelV3/LightingInstance.h"
#include "DataModelV3/DataModelInstance.h"
#include "StringFunctions.h"
//#include "Listener/ModeSelectionListener.h"
using namespace B3D;
LightingInstance::LightingInstance(void)
{
Instance::Instance("Lighting");
name = "Lighting";
canDelete = false;
_hideSky = false;
topAmbient = Reflection::ReflectionProperty<Color3>("TopAmbient", Color3(0.5F, 0.5F, 0.5F), TYPE_COLOR3, this->dataTable);
bottomAmbient = Reflection::ReflectionProperty<Color3>("BottomAmbient", Color3(0.8F, 0.8F, 0.8F), TYPE_COLOR3, this->dataTable);
spotLight = Reflection::ReflectionProperty<Color3>("SpotLight", Color3(0.5F, 0.5F, 0.5F), TYPE_COLOR3, this->dataTable);
clearColor = Reflection::ReflectionProperty<Color4>("ClearColor", Color4(0.0F, 0.0F, 0.0F, 0.0F), TYPE_COLOR4, this->dataTable);
lighting.setTime(G3D::toSeconds(2, 00, 00, PM));
// Maybe this is Top and Bottom Ambient?
lighting.ambient = topAmbient.getValue();
lighting.lightColor = bottomAmbient.getValue();
sky = Sky::create(NULL, ExePath() + "/content/sky/");
}
LightingInstance::~LightingInstance(void)
{
sky->~Sky();
}
// Getters
G3D::SkyRef LightingInstance::getSky()
{
return sky;
}
G3D::LightingParameters LightingInstance::getLightingParameters()
{
return lighting;
}
// Functions
void LightingInstance::suppressSky(bool doSuppress)
{
_hideSky = doSuppress;
}
void LightingInstance::update(RenderDevice* rd)
{
if(!_hideSky) {
rd->clear(sky.isNull(), true, true);
if (sky.notNull()) sky->render(rd, lighting);
} else {
rd->setColorClearValue(clearColor.getValue());
rd->clear(true, true, true);
suppressSky(false);
}
// Setup lighting
rd->enableLighting();
rd->setShadeMode(RenderDevice::SHADE_SMOOTH);
rd->setAmbientLightColor(Color3(1,1,1));
rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor, true, true));
rd->setAmbientLightColor(lighting.ambient);
rd->beforePrimitive();
CoordinateFrame forDraw = rd->getObjectToWorldMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
parentDataModel->getWorkspace()->render(rd);
parentDataModel->getWorkspace()->renderName(rd);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
rd->setObjectToWorldMatrix(forDraw);
rd->afterPrimitive();
// TODO implement
//parentDataModel->getSelectionService()->render(rd);
// TODO Mouse and tool will be handled by datamodel
//g_usableApp->tool->render(rd, g_usableApp->mouse);
rd->disableLighting();
drawEffects(rd);
}
void LightingInstance::drawEffects(RenderDevice* rd)
{
if (sky.notNull()) {
sky->renderLensFlare(rd, lighting);
}
}

View File

@@ -0,0 +1,163 @@
#include "DataModelV3/SelectionService.h"
#include "DataModelV3/PartInstance.h"
//This is absolutely disgusting, and will not last long
//#include "Application.h"
//#include "Globals.h"
#define CURSOR 0
#define ARROWS 1
#define RESIZE 2
using namespace B3D;
SelectionService::SelectionService(void){
Instance::Instance();
mode = CURSOR;
// TODO Port PropertyWindow
//propertyWindow = NULL;
}
SelectionService::~SelectionService(void){
}
SelectionService::SelectionService(const SelectionService &oinst){
Instance::Instance(oinst);
// TODO Port PropertyWindow
//propertyWindow = NULL;
}
std::vector<Instance *> SelectionService::getSelection(){
return this->selection;
}
void SelectionService::clearSelection(){
this->selection.clear();
// TODO Port PropertyWindow
/*if(propertyWindow != NULL)
propertyWindow->ClearProperties();*/
}
bool SelectionService::isSelected(Instance * instance){
return std::find(selection.begin(), selection.end(), instance) != selection.end();
}
void SelectionService::addSelected(Instance * instance){
if(!isSelected(instance))
this->selection.push_back(instance);
// TODO Port PropertyWindow
/*if(propertyWindow != NULL)
propertyWindow->UpdateSelected(selection);*/
}
void SelectionService::removeSelected(Instance * instance){
selection.erase(std::remove(selection.begin(), selection.end(), instance), selection.end());
// TODO Port PropertyWindow
/*if(propertyWindow != NULL)
propertyWindow->UpdateSelected(selection);*/
}
void SelectionService::addSelected(const std::vector<Instance *> &instances){
for(size_t i = 0; i < instances.size(); i++)
{
if(!isSelected(instances[i]))
this->selection.push_back(instances[i]);
}
// TODO Port PropertyWindow
/*if(propertyWindow != NULL)
propertyWindow->UpdateSelected(selection);*/
}
// TODO Port PropertyWindow
/*void SelectionService::setPropertyWindow(PropertyWindow * propertyWindow)
{
this->propertyWindow = propertyWindow;
if(propertyWindow != NULL)
propertyWindow->ClearProperties();
}*/
void SelectionService::render(RenderDevice * rd)
{
for(size_t i = 0; i < selection.size(); i++)
{
if(PartInstance* part = dynamic_cast<PartInstance*>(selection[i]))
{
Vector3 size = part->getSize();
Vector3 pos = part->getPosition();
drawOutline(Vector3(0+size.x/2, 0+size.y/2, 0+size.z/2) ,Vector3(0-size.x/2,0-size.y/2,0-size.z/2), rd, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x, pos.y, pos.z), part->getCFrame());
}
}
}
void SelectionService::drawOutline(Vector3 from, Vector3 to, RenderDevice* rd, Vector3 size, Vector3 pos, CoordinateFrame c)
{
Color3 outline = Color3::cyan();//Color3(0.098F,0.6F,1.0F);
float offsetSize = 0.1F;
//X
Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, from.y + offsetSize, from.z + offsetSize), Vector3(to.x + offsetSize, from.y - offsetSize, from.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, to.y + offsetSize, from.z + offsetSize), Vector3(to.x + offsetSize, to.y - offsetSize, from.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, to.y + offsetSize, to.z + offsetSize), Vector3(to.x + offsetSize, to.y - offsetSize, to.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x - offsetSize, from.y + offsetSize, to.z + offsetSize), Vector3(to.x + offsetSize, from.y - offsetSize, to.z - offsetSize))), rd, outline, Color4::clear());
//Y
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.2, from.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.2, from.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, from.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize - 0.2, from.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(to.x - offsetSize, to.y + offsetSize-0.1, to.z - offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y - offsetSize + 0.2, to.z + offsetSize), Vector3(from.x - offsetSize, to.y + offsetSize - 0.2, to.z - offsetSize))), rd, outline, Color4::clear());
//Z
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, from.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, from.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(from.x + offsetSize, to.y + offsetSize, from.z - offsetSize), Vector3(from.x - offsetSize, to.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, from.y + offsetSize, from.z - offsetSize), Vector3(to.x - offsetSize, from.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
Draw::box(c.toWorldSpace(Box(Vector3(to.x + offsetSize, to.y + offsetSize, from.z - offsetSize), Vector3(to.x - offsetSize, to.y - offsetSize, to.z + offsetSize))), rd, outline, Color4::clear());
if(mode == ARROWS)
{
AABox box;
c.toWorldSpace(Box(from, to)).getBounds(box);
float max = box.high().y - pos.y;
Draw::arrow(pos, Vector3(0, 1.5+max, 0), rd);
Draw::arrow(pos, Vector3(0, (-1.5)-max, 0), rd);
max = box.high().x - pos.x;
Draw::arrow(pos, Vector3(1.5+max, 0, 0), rd);
Draw::arrow(pos, Vector3((-1.5)-max, 0, 0), rd);
max = box.high().z - pos.z;
Draw::arrow(pos, Vector3(0, 0, 1.5+max), rd);
Draw::arrow(pos, Vector3(0, 0, (-1.5)-max), rd);
}
else if(mode == RESIZE)
{
Color3 sphereColor = outline;
Vector3 gamepoint = pos;
Vector3 camerapoint = rd->getCameraToWorldMatrix().translation;
float distance = pow(pow((double)gamepoint.x - (double)camerapoint.x, 2) + pow((double)gamepoint.y - (double)camerapoint.y, 2) + pow((double)gamepoint.z - (double)camerapoint.z, 2), 0.5);
if(distance < 200)
{
float multiplier = distance * 0.050F/2;
if(multiplier < 0.50F)
multiplier = 0.50F;
Vector3 position = pos + (c.lookVector()*((size.z)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.lookVector()*((size.z)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos + (c.rightVector()*((size.x)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.rightVector()*((size.x)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos + (c.upVector()*((size.y)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
position = pos - (c.upVector()*((size.y)+2));
Draw::sphere(Sphere(position, multiplier), rd, sphereColor, Color4::clear());
}
}
}