very basic ThumbnailGenerator

This commit is contained in:
Modnark
2022-10-06 12:18:35 -04:00
parent 71fda54338
commit c1118489e3
11 changed files with 135 additions and 118 deletions

View File

@@ -497,6 +497,10 @@
RelativePath=".\src\source\DataModel\SelectionService.cpp" RelativePath=".\src\source\DataModel\SelectionService.cpp"
> >
</File> </File>
<File
RelativePath=".\ThumbnailGeneratorInstance.cpp"
>
</File>
<File <File
RelativePath=".\src\source\DataModelV2\WorkspaceInstance.cpp" RelativePath=".\src\source\DataModelV2\WorkspaceInstance.cpp"
> >
@@ -862,6 +866,10 @@
RelativePath=".\src\include\DataModelV2\SelectionService.h" RelativePath=".\src\include\DataModelV2\SelectionService.h"
> >
</File> </File>
<File
RelativePath=".\src\include\DataModelV2\ThumbnailGeneratorInstance.h"
>
</File>
<File <File
RelativePath=".\src\include\DataModelV2\WorkspaceInstance.h" RelativePath=".\src\include\DataModelV2\WorkspaceInstance.h"
> >

View File

@@ -0,0 +1,43 @@
#include "DataModelV2/ThumbnailGeneratorInstance.h"
#include "Application.h"
#include "Globals.h"
#include <fstream>
ThumbnailGeneratorInstance::ThumbnailGeneratorInstance(void)
{
Instance::Instance();
name = "ThumbnailGenerator";
className = "ThumbnailGenerator";
canDelete = false;
}
ThumbnailGeneratorInstance::~ThumbnailGeneratorInstance(void) {}
std::string ThumbnailGeneratorInstance::click(std::string fileType, int cx, int cy, bool hideSky)
{
const G3D::GImage::Format format = G3D::GImage::stringToFormat(fileType);
RenderDevice* rd = g_usableApp->getRenderDevice();
// Disable the sky
if(hideSky)
g_usableApp->toggleSky();
// Update graphics
g_usableApp->onGraphics(rd);
// Sky SHOULD be gone now, and alpha channel should be present
G3D::GImage imgBuffer(cx, cy, 4);
rd->screenshotPic(imgBuffer, true, hideSky);
G3D::BinaryOutput binOut;
imgBuffer.encode(format, binOut);
// Temporary file saving
std::string fileSave = "./click_output." + fileType;
std::ofstream out(fileSave.c_str(), std::ios::out | std::ios::binary);
out.write(reinterpret_cast<const char*>(binOut.getCArray()), binOut.length());
return "boop!";
}

BIN
click_output.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

View File

@@ -48,6 +48,7 @@ class Application { // : public GApp {
void setFocus(bool isFocused); void setFocus(bool isFocused);
int getMode(); int getMode();
void unSetMode(); void unSetMode();
void toggleSky();
CameraController cameraController; CameraController cameraController;
UserInput* userInput; UserInput* userInput;
PropertyWindow* _propWindow; PropertyWindow* _propWindow;
@@ -55,6 +56,7 @@ class Application { // : public GApp {
RenderDevice* getRenderDevice(); RenderDevice* getRenderDevice();
void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow); void selectInstance(Instance* selectedInstance,PropertyWindow* propWindow);
void setMode(int mode); void setMode(int mode);
SkyRef getSky();
Tool * tool; Tool * tool;
void changeTool(Tool *); void changeTool(Tool *);
@@ -82,6 +84,7 @@ class Application { // : public GApp {
GAppSettings _settings; GAppSettings _settings;
double lightProjX, lightProjY, lightProjNear, lightProjFar; double lightProjX, lightProjY, lightProjNear, lightProjFar;
IEBrowser* webBrowser; IEBrowser* webBrowser;
bool _hideSky;
protected: protected:
Stopwatch m_graphicsWatch; Stopwatch m_graphicsWatch;
Stopwatch m_logicWatch; Stopwatch m_logicWatch;

View File

@@ -2,6 +2,7 @@
#include "WorkspaceInstance.h" #include "WorkspaceInstance.h"
#include "LevelInstance.h" #include "LevelInstance.h"
#include "PartInstance.h" #include "PartInstance.h"
#include "ThumbnailGeneratorInstance.h"
#include "SelectionService.h" #include "SelectionService.h"
#include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml.hpp"
#include "GuiRootInstance.h" #include "GuiRootInstance.h"
@@ -23,9 +24,12 @@ public:
bool load(const char* filename,bool clearObjects); bool load(const char* filename,bool clearObjects);
bool readXMLFileStream(std::ifstream* file); bool readXMLFileStream(std::ifstream* file);
void drawMessage(RenderDevice*); void drawMessage(RenderDevice*);
WorkspaceInstance* getWorkspace();
LevelInstance * getLevel(); WorkspaceInstance* getWorkspace();
XplicitNgine * getEngine(); LevelInstance* getLevel();
XplicitNgine* getEngine();
ThumbnailGeneratorInstance* getThumbnailGenerator();
std::string message; std::string message;
std::string _loadedFileName; std::string _loadedFileName;
bool showMessage; bool showMessage;
@@ -50,9 +54,10 @@ private:
bool _legacyLoad; bool _legacyLoad;
float _modY; float _modY;
WorkspaceInstance* workspace; WorkspaceInstance* workspace;
LevelInstance * level; LevelInstance* level;
GuiRootInstance* guiRoot; GuiRootInstance* guiRoot;
SelectionService* selectionService; SelectionService* selectionService;
ThumbnailGeneratorInstance * thumbnailGenerator;
bool running; bool running;
XplicitNgine * xplicitNgine; XplicitNgine * xplicitNgine;
}; };

View File

@@ -0,0 +1,14 @@
#pragma once
#include "instance.h"
class ThumbnailGeneratorInstance :
public Instance
{
public:
// Constructor / Destructor
ThumbnailGeneratorInstance(void);
~ThumbnailGeneratorInstance(void);
// Functions
std::string click(std::string fileType, int cx, int cy, bool hideSky);
};

View File

@@ -29,6 +29,8 @@ extern bool running;
extern DataModelInstance* g_dataModel; extern DataModelInstance* g_dataModel;
extern XplicitNgine* g_xplicitNgine; extern XplicitNgine* g_xplicitNgine;
extern Application* g_usableApp; extern Application* g_usableApp;
extern SkyRef g_sky;
extern RenderDevice g_renderDevice;
extern GFontRef g_fntdominant; extern GFontRef g_fntdominant;
extern GFontRef g_fntlighttrek; extern GFontRef g_fntlighttrek;

View File

@@ -117,8 +117,10 @@ Application::Application(HWND parentWindow) : _propWindow(NULL) { //: GApp(setti
quit=false; quit=false;
rightButtonHolding=false; rightButtonHolding=false;
mouseOnScreen=false; mouseOnScreen=false;
// GApp replacement // GApp replacement
renderDevice = new RenderDevice(); renderDevice = new RenderDevice();
if (window != NULL) { if (window != NULL) {
renderDevice->init(window, NULL); renderDevice->init(window, NULL);
} }
@@ -194,6 +196,7 @@ void Application::onInit() {
_dataModel->setName("undefined"); _dataModel->setName("undefined");
_dataModel->font = g_fntdominant; _dataModel->font = g_fntdominant;
g_dataModel = _dataModel; g_dataModel = _dataModel;
_hideSky = false;
#ifdef LEGACY_LOAD_G3DFUN_LEVEL #ifdef LEGACY_LOAD_G3DFUN_LEVEL
// Anchored this baseplate for XplicitNgine tests // Anchored this baseplate for XplicitNgine tests
@@ -503,9 +506,6 @@ void Application::exitApplication()
//endProgram = true; //endProgram = true;
} }
void Application::onGraphics(RenderDevice* rd) { void Application::onGraphics(RenderDevice* rd) {
G3D::uint8 num = 0; G3D::uint8 num = 0;
@@ -514,27 +514,17 @@ void Application::onGraphics(RenderDevice* rd) {
if (GetCursorPos(&mousepos)) if (GetCursorPos(&mousepos))
{ {
POINT pointm = mousepos; POINT pointm = mousepos;
if (ScreenToClient(_hWndMain, &mousepos)) if (ScreenToClient(_hWndMain, &mousepos))
{
//mouseOnScreen = true;
//POINT pointm;
///GetCursorPos(&pointm);
if(_hwndRenderer != WindowFromPoint(pointm)) //OLD: mousepos.x < 1 || mousepos.y < 1 || mousepos.x >= rd->getViewport().width()-1 || mousepos.y >= rd->getViewport().height()-1
{ {
mouseOnScreen = false; if(_hwndRenderer != WindowFromPoint(pointm))
//ShowCursor(true); {
//_window->setMouseVisible(true); mouseOnScreen = false;
//rd->window()->setInputCaptureCount(0); }
else
{
mouseOnScreen = true;
}
} }
else
{
mouseOnScreen = true;
//SetCursor(NULL);
//_window->setMouseVisible(false);
//rd->window()->setInputCaptureCount(1);
}
}
} }
if(Globals::useMousePoint) if(Globals::useMousePoint)
@@ -547,13 +537,17 @@ void Application::onGraphics(RenderDevice* rd) {
lighting.ambient = Color3(0.6F,0.6F,0.6F); lighting.ambient = Color3(0.6F,0.6F,0.6F);
renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera()); renderDevice->setProjectionAndCameraMatrix(*cameraController.getCamera());
// Cyan background // TODO: stick this into its own rendering thing
//renderDevice->setColorClearValue(Color3(0.0f, 0.5f, 1.0f)); if(!_hideSky) {
renderDevice->clear(sky.isNull(), true, true);
if (sky.notNull()) sky->render(renderDevice, lighting);
} else {
printf("ThumbnailGenerator::click\n");
renderDevice->clear(sky.isNull(), true, true); rd->setColorClearValue(Color4(0.0f, 0.0f, 0.0f, 0.0f));
if (sky.notNull()) { renderDevice->clear(true, true, true);
sky->render(renderDevice, lighting); toggleSky();
} }
// Setup lighting // Setup lighting
renderDevice->enableLighting(); renderDevice->enableLighting();
@@ -564,115 +558,47 @@ void Application::onGraphics(RenderDevice* rd) {
renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor, true, true)); renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor, true, true));
renderDevice->setAmbientLightColor(lighting.ambient); renderDevice->setAmbientLightColor(lighting.ambient);
//renderDevice->setBlendFunc(RenderDevice::BLEND_ONE, RenderDevice::BLEND_ONE);
renderDevice->setShininess(70); renderDevice->setShininess(70);
renderDevice->setSpecularCoefficient(Color3(0.1F, 0.1F, 0.1F)); renderDevice->setSpecularCoefficient(Color3(0.1F, 0.1F, 0.1F));
//float lightAmbient[] = { 0.5F, 0.6F, 0.9F, 1.0F };
//float lightDiffuse[] = { 0.6F, 0.4F, 0.9F, 1.0F };
//float lightSpecular[] = { 0.8F, 0.6F, 1.0F, 1.0F };
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, lightAmbient);
//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, lightDiffuse);
//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, lightSpecular);
//glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 70);
rd->beforePrimitive(); rd->beforePrimitive();
CoordinateFrame forDraw = rd->getObjectToWorldMatrix(); CoordinateFrame forDraw = rd->getObjectToWorldMatrix();
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
//if(_dataModel->getWorkspace() != NULL)
_dataModel->getWorkspace()->render(rd); _dataModel->getWorkspace()->render(rd);
//else throw std::exception("Workspace not found");
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_NORMAL_ARRAY);
rd->setObjectToWorldMatrix(forDraw); rd->setObjectToWorldMatrix(forDraw);
rd->afterPrimitive(); rd->afterPrimitive();
//Draw::box(G3D::Box(mouse.getPosition()-Vector3(2,0.5F,1),mouse.getPosition()+Vector3(2,0.5F,1)), rd, Color3::cyan(), Color4::clear());
for(size_t i = 0; i < _dataModel->getSelectionService()->getSelection().size(); i++) for(size_t i = 0; i < _dataModel->getSelectionService()->getSelection().size(); i++)
{ {
if(PartInstance* part = dynamic_cast<PartInstance*>(g_dataModel->getSelectionService()->getSelection()[i])) if(PartInstance* part = dynamic_cast<PartInstance*>(g_dataModel->getSelectionService()->getSelection()[i]))
{ {
Vector3 size = part->getSize(); Vector3 size = part->getSize();
Vector3 pos = part->getPosition(); 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, lighting, Vector3(size.x/2, size.y/2, size.z/2), Vector3(pos.x, pos.y, pos.z), part->getCFrame()); 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,
lighting,
Vector3(size.x/2, size.y/2, size.z/2),
Vector3(pos.x, pos.y, pos.z), part->getCFrame()
);
} }
} }
//Vector3 gamepoint = Vector3(0, 5, 0);
//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 < 50 && distance > -50)
//{
// if(distance < 0)
// distance = distance*-1;
// fntdominant->draw3D(rd, "Testing", CoordinateFrame(rd->getCameraToWorldMatrix().rotation, gamepoint), 0.04*distance, Color3::yellow(), Color3::black(), G3D::GFont::XALIGN_CENTER, G3D::GFont::YALIGN_CENTER);
//}
renderDevice->disableLighting(); renderDevice->disableLighting();
if (sky.notNull()) { if (sky.notNull()) {
sky->renderLensFlare(renderDevice, lighting); sky->renderLensFlare(renderDevice, lighting);
} }
renderDevice->push2D(); renderDevice->push2D();
_dataModel->getGuiRoot()->renderGUI(renderDevice, m_graphicsWatch.FPS()); _dataModel->getGuiRoot()->renderGUI(renderDevice, m_graphicsWatch.FPS());
/*rd->pushState();
rd->beforePrimitive();
if(Globals::showMouse && mouseOnScreen)
{
glEnable( GL_TEXTURE_2D );
glEnable(GL_BLEND);// you enable blending function
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/*
std::vector<Instance*> instances = _dataModel->getWorkspace()->getAllChildren();
currentcursorid = cursorid;
for(size_t i = 0; i < instances.size(); i++)
{
if(PartInstance* test = dynamic_cast<PartInstance*>(instances.at(i)))
{
float time = cameraController.getCamera()->worldRay(_dataModel->mousex, _dataModel->mousey, renderDevice->getViewport()).intersectionTime(test->getBox());
//float time = testRay.intersectionTime(test->getBox());
if (time != inf())
{
currentcursorid = cursorOvrid;
break;
}
}
}
*/
/*glBindTexture( GL_TEXTURE_2D, tool->getCursorId());
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f(mousepos.x-64, mousepos.y-64);
glTexCoord2d( 1.0,0.0 );
glVertex2f(mousepos.x+64, mousepos.y-64);
glTexCoord2d(1.0,1.0 );
glVertex2f(mousepos.x+64, mousepos.y+64 );
glTexCoord2d( 0.0,1.0 );
glVertex2f( mousepos.x-64, mousepos.y+64 );
glEnd();
glDisable( GL_TEXTURE_2D );*/
//}
/*rd->afterPrimitive();
rd->popState();*/
renderDevice->pop2D(); renderDevice->pop2D();
} }
@@ -709,6 +635,16 @@ G3D::RenderDevice* Application::getRenderDevice()
return renderDevice; return renderDevice;
} }
G3D::SkyRef Application::getSky()
{
return sky;
}
void Application::toggleSky()
{
_hideSky = !_hideSky;
}
void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y) void Application::onMouseLeftUp(G3D::RenderDevice* renderDevice, int x, int y)
{ {
_dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y); _dataModel->getGuiRoot()->onMouseLeftUp(renderDevice, x, y);
@@ -731,7 +667,6 @@ void Application::onMouseMoved(int x,int y)
mouse.oldy = mouse.y; mouse.oldy = mouse.y;
mouse.x = x; mouse.x = x;
mouse.y = y; mouse.y = y;
//tool->onMouseMoved(mouse);
mouseMoveState = true; mouseMoveState = true;
} }

View File

@@ -2,6 +2,7 @@
#include "DataModelV2/GuiRootInstance.h" #include "DataModelV2/GuiRootInstance.h"
#include "DataModelV2/ToggleImageButtonInstance.h" #include "DataModelV2/ToggleImageButtonInstance.h"
#include "DataModelV2/DataModelInstance.h" #include "DataModelV2/DataModelInstance.h"
#include "DataModelV2/ThumbnailGeneratorInstance.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@@ -20,14 +21,11 @@ DataModelInstance::DataModelInstance(void)
workspace = new WorkspaceInstance(); workspace = new WorkspaceInstance();
guiRoot = new GuiRootInstance(); guiRoot = new GuiRootInstance();
level = new LevelInstance(); level = new LevelInstance();
thumbnailGenerator = new ThumbnailGeneratorInstance();
selectionService = new SelectionService(); selectionService = new SelectionService();
selectionService->setPropertyWindow(g_usableApp->_propWindow); selectionService->setPropertyWindow(g_usableApp->_propWindow);
//children.push_back(workspace);
//children.push_back(level);
className = "dataModel"; className = "dataModel";
//mousex = 0;
//mousey = 0;
//mouseButton1Down = false;
showMessage = false; showMessage = false;
canDelete = false; canDelete = false;
_modY=0; _modY=0;
@@ -652,3 +650,8 @@ LevelInstance* DataModelInstance::getLevel()
{ {
return level; return level;
} }
ThumbnailGeneratorInstance* DataModelInstance::getThumbnailGenerator()
{
return thumbnailGenerator;
}

View File

@@ -5,6 +5,7 @@ LevelInstance::LevelInstance(void)
{ {
Instance::Instance(); Instance::Instance();
name = "Level"; name = "Level";
className = "LevelService";
winMessage = "You Won!"; winMessage = "You Won!";
loseMessage = "You Lost. Try Again"; loseMessage = "You Lost. Try Again";
timer = 60.0F; timer = 60.0F;

View File

@@ -15,6 +15,7 @@ void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button)
AppendMenu(mainmenu, MF_STRING, 100, "New"); AppendMenu(mainmenu, MF_STRING, 100, "New");
AppendMenu(mainmenu, MF_STRING, 101, "Open..."); AppendMenu(mainmenu, MF_STRING, 101, "Open...");
AppendMenu(mainmenu, MF_STRING, 102, "Close"); AppendMenu(mainmenu, MF_STRING, 102, "Close");
AppendMenu(mainmenu, MF_STRING, 103, "ThumbnailGenerator::click");
AppendMenu(mainmenu, MF_SEPARATOR, 0, NULL); AppendMenu(mainmenu, MF_SEPARATOR, 0, NULL);
POINT p; POINT p;
GetCursorPos(&p); GetCursorPos(&p);
@@ -31,6 +32,8 @@ void MenuButtonListener::onButton1MouseClick(BaseButtonInstance* button)
case 102: case 102:
g_usableApp->QuitApp(); g_usableApp->QuitApp();
break; break;
case 103:
g_dataModel->getThumbnailGenerator()->click("PNG", 256, 256, true);
} }
} }
} }