trying to compile
This commit is contained in:
parent
f8c38a8a37
commit
2455f90550
19 changed files with 999 additions and 1890 deletions
34
Sketch3D/public/FrameBuffer.hpp
Normal file
34
Sketch3D/public/FrameBuffer.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Rect.hpp"
|
||||
#include "Color.hpp"
|
||||
|
||||
namespace tp {
|
||||
class RenderBuffer {
|
||||
public:
|
||||
RenderBuffer(const Vec2F& size);
|
||||
RenderBuffer(const Vec2F& size, tp::uint1 samples);
|
||||
~RenderBuffer();
|
||||
|
||||
void beginDraw();
|
||||
void setViewport(const RectF& viewport);
|
||||
void clear();
|
||||
void endDraw();
|
||||
|
||||
uint4 texId() const;
|
||||
uint4 buffId() const;
|
||||
|
||||
const Vec2F& getSize() const;
|
||||
|
||||
public:
|
||||
RGBA mClearCol = 0.f;
|
||||
|
||||
private:
|
||||
uint4 mFrameBufferID = 0; // regroups 0, 1, or more textures, and 0 or 1 depth buffer.
|
||||
uint4 mTextureId = 0; // texture we're going to render to ( colour attachement #0 )
|
||||
uint4 mDepthBufferID = 0;
|
||||
uint4 mDrawBuffers[1];
|
||||
Vec2F mSize;
|
||||
};
|
||||
};
|
||||
19
Sketch3D/public/GraphicsApi.hpp
Normal file
19
Sketch3D/public/GraphicsApi.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Environment.hpp"
|
||||
|
||||
#ifdef ENV_OS_ANDROID
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl32.h>
|
||||
#else
|
||||
#include "GL/glew.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENV_OS_ANDROID
|
||||
#define GLW_CONTEXT_DEPTH_BITS 16
|
||||
#define GLW_CONTEXT_DEPTH_COMPONENT GL_DEPTH_COMPONENT16
|
||||
#else
|
||||
#define GLW_CONTEXT_DEPTH_BITS 32
|
||||
#define GLW_CONTEXT_DEPTH_COMPONENT GL_DEPTH_COMPONENT32
|
||||
#endif
|
||||
31
Sketch3D/public/Shader.hpp
Normal file
31
Sketch3D/public/Shader.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
namespace tp {
|
||||
class RenderShader {
|
||||
public:
|
||||
RenderShader();
|
||||
RenderShader(const char* vertid, const char* geomid, const char* fragid, bool paths = true);
|
||||
~RenderShader();
|
||||
|
||||
void vert_bind_source(const char* vert_src);
|
||||
void frag_bind_source(const char* frag_src);
|
||||
void geom_bind_source(const char* geom_src);
|
||||
|
||||
void compile();
|
||||
|
||||
void bind();
|
||||
uint4 getu(const char* uid);
|
||||
void unbind();
|
||||
|
||||
private:
|
||||
bool compile_shader(const char* ShaderCode, uint4 ShaderID);
|
||||
void load(const char* vert, const char* geom, const char* frag, bool paths);
|
||||
|
||||
private:
|
||||
uint4 programm;
|
||||
uint4 VertexShaderID;
|
||||
uint4 FragmentShaderID;
|
||||
uint4 GeometryShaderID;
|
||||
};
|
||||
};
|
||||
227
Sketch3D/public/Sketch3D.hpp
Normal file
227
Sketch3D/public/Sketch3D.hpp
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
|
||||
#include "Buffer.hpp"
|
||||
#include "List.hpp"
|
||||
#include "Map.hpp"
|
||||
#include "Topology.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Strings.hpp"
|
||||
|
||||
#include "GraphicsApi.hpp"
|
||||
#include "FrameBuffer.hpp"
|
||||
#include "Shader.hpp"
|
||||
|
||||
namespace strokes {
|
||||
|
||||
class Renderer;
|
||||
class Project;
|
||||
|
||||
class Stroke {
|
||||
|
||||
friend Renderer;
|
||||
|
||||
public:
|
||||
struct Point {
|
||||
tp::Vec3F pos;
|
||||
tp::halnf thickness = NULL;
|
||||
};
|
||||
|
||||
tp::Buffer<Point> mPoints;
|
||||
tp::RGBA mCol;
|
||||
|
||||
private:
|
||||
struct GLHandles {
|
||||
GLuint VertexArrayID = 0;
|
||||
GLuint vertexbuffer = 0;
|
||||
GLuint vbo_len = 0;
|
||||
GLHandles();
|
||||
void sendDataToGPU(tp::Buffer<Point>* mPoints);
|
||||
~GLHandles();
|
||||
} mGl;
|
||||
|
||||
public:
|
||||
|
||||
Stroke();
|
||||
|
||||
void denoisePos(tp::halni passes);
|
||||
void denoiseThickness(tp::halni passes);
|
||||
void compress(tp::halnf factor);
|
||||
void subdiv(tp::halnf precition, tp::Camera* cam, tp::halni passes = 1);
|
||||
|
||||
void updateGpuBuffers();
|
||||
|
||||
tp::Buffer<Point>& buff();
|
||||
};
|
||||
|
||||
class Brush {
|
||||
public:
|
||||
tp::String mType = "equal";
|
||||
Brush() {}
|
||||
virtual void sample(Project* proj, tp::Vec2F crs, tp::halnf pressure) {}
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) {}
|
||||
virtual ~Brush() {}
|
||||
};
|
||||
|
||||
class PencilBrush : public Brush {
|
||||
|
||||
tp::halnf mPrecision = 0.001f;
|
||||
|
||||
tp::halni mDenoisePassesPos = 1;
|
||||
tp::halni mDenoisePassesThick = 3;
|
||||
tp::halnf mCompressionFactor = 0.0001f;
|
||||
tp::halni mSubdivPasses = 3;
|
||||
bool mEnableCompression = true;
|
||||
|
||||
tp::halni mMaxPoints = 100;
|
||||
|
||||
Stroke* mStroke = NULL;
|
||||
Stroke mShowStroke;
|
||||
|
||||
void unsureReady(Stroke* stroke, tp::Camera* cam, bool debug = false);
|
||||
|
||||
public:
|
||||
|
||||
tp::RGBA mCol = tp::RGBA(1.0f);
|
||||
tp::halnf mSize = 0.01f;
|
||||
|
||||
PencilBrush();
|
||||
virtual void sample(Project* proj, tp::Vec2F crs, tp::halnf pressure) override;
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) override;
|
||||
virtual ~PencilBrush();
|
||||
};
|
||||
|
||||
struct EraserBrush : public Brush {
|
||||
EraserBrush() { mType = "eraser"; }
|
||||
virtual void sample(Project* proj, tp::Vec2F crs, tp::halnf pressure) override {}
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) override {}
|
||||
virtual ~EraserBrush() {}
|
||||
};
|
||||
|
||||
class Project {
|
||||
|
||||
public:
|
||||
|
||||
struct Layer {
|
||||
tp::String name = "new layer";
|
||||
tp::List<Stroke*> strokes;
|
||||
bool enabled = true;
|
||||
~Layer();
|
||||
};
|
||||
|
||||
tp::Buffer<Layer*> mLayers;
|
||||
tp::halni mActiveLayer = -1;
|
||||
|
||||
tp::Camera mCamera;
|
||||
tp::RGBA mBackgroundColor = { 0.22f, 0.22f, 0.25f, 1.f };
|
||||
|
||||
tp::Map<tp::String, Brush*> mBrushes;
|
||||
tp::String mActiveBrush;
|
||||
|
||||
Project();
|
||||
~Project();
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
tp::RenderBuffer mBufferDowncast;
|
||||
tp::RenderBuffer mBuffer;
|
||||
tp::RenderShader mShader;
|
||||
|
||||
// shader uniforms
|
||||
GLuint mMatrixUniform = 0;
|
||||
GLuint mColorUniform = 0;
|
||||
GLuint mRatioUniform = 0;
|
||||
GLuint mTargetUniform = 0;
|
||||
GLuint mBGColUniform = 0;
|
||||
|
||||
public:
|
||||
Renderer(tp::Vec2F size);
|
||||
|
||||
void renderBegin();
|
||||
void setViewport(tp::RectF viewport);
|
||||
void drawStroke(Stroke* str, tp::Camera* camera);
|
||||
void renderEnd();
|
||||
|
||||
void setClearCol(tp::RGBA col);
|
||||
tp::uhalni getTextudeId();
|
||||
tp::RenderBuffer* getBuff();
|
||||
|
||||
~Renderer();
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
void Project::save(tp::File& file) {
|
||||
file.write<tp::Camera>(&mCamera);
|
||||
file.write<tp::rgba>(&mBackgroundColor);
|
||||
file.write<tp::halni>(&mActiveLayer);
|
||||
|
||||
tp::alni lay_len = mLayers.length();
|
||||
file.write<tp::alni>(&lay_len);
|
||||
for (auto layer : mLayers) {
|
||||
layer.data()->name.save(&file);
|
||||
|
||||
file.write<bool>(&layer.data()->enabled);
|
||||
|
||||
tp::alni len = layer.data()->strokes.length();
|
||||
file.write<tp::alni>(&len);
|
||||
for (auto stiter : layer.data()->strokes) {
|
||||
stiter->save(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Project::load(tp::File& file) {
|
||||
file.read<tp::Camera>(&mCamera);
|
||||
file.read<tp::rgba>(&mBackgroundColor);
|
||||
file.read<tp::halni>(&mActiveLayer);
|
||||
|
||||
tp::alni layers_len;
|
||||
file.read<tp::alni>(&layers_len);
|
||||
mLayers.reserve(layers_len);
|
||||
|
||||
for (tp::alni idx = 0; idx < layers_len; idx++) {
|
||||
|
||||
tp::string key; key.load(&file);
|
||||
auto layer = new Layer();
|
||||
layer->name = key;
|
||||
mLayers[idx] = layer;
|
||||
|
||||
file.read<bool>(&layer->enabled);
|
||||
|
||||
tp::alni len;
|
||||
file.read<tp::alni>(&len);
|
||||
|
||||
for (tp::alni str_idx = 0; str_idx < len; str_idx++) {
|
||||
auto str = new Stroke();
|
||||
layer->strokes.pushBack(str);
|
||||
layer->strokes.last()->data->load(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
void Stroke::save(tp::File& file) {
|
||||
file.write<tp::rgba>(&mCol);
|
||||
|
||||
tp::alni length = mPoints.length();
|
||||
file.write<tp::alni>(&length);
|
||||
for (auto piter : mPoints) {
|
||||
file.write<Point>(&piter.data());
|
||||
}
|
||||
}
|
||||
|
||||
void Stroke::load(tp::File& file) {
|
||||
tp::rgba color;
|
||||
file.read<tp::rgba>(&color);
|
||||
|
||||
tp::alni p_len;
|
||||
file.read<tp::alni>(&p_len);
|
||||
|
||||
mPoints.reserve(p_len);
|
||||
for (auto piter : mPoints) {
|
||||
file.read<Point>(&piter.data());
|
||||
}
|
||||
|
||||
updateGpuBuffers();
|
||||
}
|
||||
*/
|
||||
87
Sketch3D/public/Sketch3DWidget.hpp
Normal file
87
Sketch3D/public/Sketch3DWidget.hpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
|
||||
// #include "Fram.h"
|
||||
|
||||
class Widget {
|
||||
void destructor(StrokesWidget* self) {
|
||||
self->mRenderer.~Renderer();
|
||||
self->mImage.free(self->mDrawer);
|
||||
self->mImage.~ImageHandle();
|
||||
}
|
||||
|
||||
void procInputs(StrokesWidget* self, nd::GUIInputs* inputs) {
|
||||
auto proj = self->getTargetProject();
|
||||
if (!proj) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto rec = self->getRect();
|
||||
proj->mCamera.set_ratio(rec.w / rec.z);
|
||||
|
||||
auto col_obj_bg = self->getMember<obj::ColorObject>("bg_color");
|
||||
if (col_obj_bg) {
|
||||
proj->mBackgroundColor = col_obj_bg->mCol;
|
||||
}
|
||||
|
||||
if (!rec.inside(inputs->mCrsPrev)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto pressure = inputs->mPressure;
|
||||
if (!inputs->Anticipating()) {
|
||||
pressure = 0.f;
|
||||
}
|
||||
|
||||
auto idx = proj->mBrushes.presents(proj->mActiveBrush);
|
||||
if (idx) {
|
||||
auto brush = proj->mBrushes.getSlotVal(idx);
|
||||
auto crs = (inputs->mCrs - rec.pos);
|
||||
crs.x /= rec.z;
|
||||
crs.y /= rec.w;
|
||||
crs = (crs - 0.5) * 2;
|
||||
|
||||
if (brush->mType == "pencil") {
|
||||
auto col_obj = self->getMember<obj::ColorObject>("draw_color");
|
||||
if (col_obj) {
|
||||
((strokes::PencilBrush*) brush)->mCol = col_obj->mCol;
|
||||
}
|
||||
}
|
||||
|
||||
brush->sample(proj, crs, pressure);
|
||||
}
|
||||
}
|
||||
|
||||
void presentOutput(StrokesWidget* self, nd::GUIdrawer* drawer) {
|
||||
auto proj = self->getTargetProject();
|
||||
if (!proj) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self->mImage.mId) {
|
||||
self->mDrawer = drawer;
|
||||
self->mImage.createFromBuff(self->mRenderer.getBuff(), drawer);
|
||||
}
|
||||
|
||||
auto rec = self->getRect();
|
||||
self->mRenderer.setViewport({ 0, 0, rec.z, rec.w });
|
||||
self->mRenderer.setClearCol(proj->mBackgroundColor);
|
||||
self->mRenderer.renderBegin();
|
||||
|
||||
for (auto lay : proj->mLayers) {
|
||||
if (lay.data()->enabled) {
|
||||
for (auto str : lay.data()->strokes) {
|
||||
self->mRenderer.drawStroke(str.data(), &proj->mCamera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto idx = proj->mBrushes.presents(proj->mActiveBrush);
|
||||
if (idx) {
|
||||
auto brush = proj->mBrushes.getSlotVal(idx);
|
||||
brush->draw(&self->mRenderer, &proj->mCamera);
|
||||
}
|
||||
|
||||
self->mRenderer.renderEnd();
|
||||
|
||||
drawer->drawImage(rec, &self->mImage, 0, 1, 12);
|
||||
}
|
||||
};
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
#include "gui/Widgets.h"
|
||||
|
||||
#include "nodes.h"
|
||||
#include "StrokesObject.h"
|
||||
|
||||
namespace nd {
|
||||
struct StrokesWidget : Widget {
|
||||
static obj::ObjectType TypeData;
|
||||
static struct Vtable : Widget::Vtable {} vtable;
|
||||
|
||||
strokes::Renderer mRenderer;
|
||||
nd::GUIdrawer::ImageHandle mImage;
|
||||
nd::GUIdrawer* mDrawer = NULL;
|
||||
|
||||
static void constructor(StrokesWidget* self);
|
||||
static void destructor(StrokesWidget* self);
|
||||
static void copy(Widget* self, const Widget* in);
|
||||
static void procInputs(StrokesWidget* self, nd::GUIInputs* inputs);
|
||||
static void presentOutput(StrokesWidget* self, nd::GUIdrawer* drawer);
|
||||
|
||||
strokes::Project* getTargetProject();
|
||||
|
||||
static void OpsInit();
|
||||
static void OpsUnInit();
|
||||
|
||||
static void addShortcuts(nd::NodesCore* core);
|
||||
};
|
||||
};
|
||||
29
Sketch3D/public/Texture.hpp
Normal file
29
Sketch3D/public/Texture.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Buffer2D.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Vec.hpp"
|
||||
|
||||
namespace tp {
|
||||
class RenderTexture {
|
||||
public:
|
||||
RenderTexture();
|
||||
~RenderTexture();
|
||||
|
||||
uint4 getid();
|
||||
|
||||
void update(const Buffer2D<RGBA>& buff);
|
||||
void draw(const uint4& out = 0);
|
||||
|
||||
public:
|
||||
static void init();
|
||||
static void deinit();
|
||||
static void draw_texture(uint4 out, uint4 in);
|
||||
static uint4 get_tex(const char* TexId);
|
||||
static void drawCurcle(Vec2F pos, double radius, RGBA col);
|
||||
|
||||
private:
|
||||
uint4 id;
|
||||
};
|
||||
};
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
|
||||
#include "Buffer.hpp"
|
||||
#include "List.hpp"
|
||||
#include "Map.hpp"
|
||||
#include "Topology.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Strings.hpp"
|
||||
|
||||
namespace strokes {
|
||||
|
||||
class Renderer;
|
||||
class Project;
|
||||
|
||||
class Stroke {
|
||||
|
||||
friend Renderer;
|
||||
|
||||
public:
|
||||
struct Point {
|
||||
tp::vec3f pos;
|
||||
tp::halnf thickness = NULL;
|
||||
};
|
||||
|
||||
tp::Array<Point> mPoints;
|
||||
tp::rgba mCol;
|
||||
|
||||
private:
|
||||
struct GLHandles {
|
||||
GLuint VertexArrayID = 0;
|
||||
GLuint vertexbuffer = 0;
|
||||
GLuint vbo_len = 0;
|
||||
GLHandles();
|
||||
void sendDataToGPU(tp::Array<Point>* mPoints);
|
||||
~GLHandles();
|
||||
} mGl;
|
||||
|
||||
public:
|
||||
|
||||
Stroke();
|
||||
|
||||
void denoisePos(tp::halni passes);
|
||||
void denoiseThickness(tp::halni passes);
|
||||
void compress(tp::halnf factor);
|
||||
void subdiv(tp::halnf precition, tp::Camera* cam, tp::halni passes = 1);
|
||||
|
||||
void updateGpuBuffers();
|
||||
|
||||
tp::Array<Point>& buff();
|
||||
|
||||
tp::halni saveSize();
|
||||
void save(tp::File& file);
|
||||
void load(tp::File& file);
|
||||
};
|
||||
|
||||
class Brush {
|
||||
public:
|
||||
tp::string mType = "equal";
|
||||
Brush() {}
|
||||
virtual void sample(Project* proj, tp::vec2f crs, tp::halnf pressure) {}
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) {}
|
||||
virtual ~Brush() {}
|
||||
};
|
||||
|
||||
class PencilBrush : public Brush {
|
||||
|
||||
tp::halnf mPrecision = 0.001f;
|
||||
|
||||
tp::halni mDenoisePassesPos = 1;
|
||||
tp::halni mDenoisePassesThick = 3;
|
||||
tp::halnf mCompressionFactor = 0.0001f;
|
||||
tp::halni mSubdivPasses = 3;
|
||||
bool mEnableCompression = true;
|
||||
|
||||
tp::halni mMaxPoints = 100;
|
||||
|
||||
Stroke* mStroke = NULL;
|
||||
Stroke mShowStroke;
|
||||
|
||||
void unsureReady(Stroke* stroke, tp::Camera* cam, bool debug = false);
|
||||
|
||||
public:
|
||||
|
||||
tp::rgba mCol = tp::rgba(1.0f);
|
||||
tp::halnf mSize = 0.01f;
|
||||
|
||||
PencilBrush();
|
||||
virtual void sample(Project* proj, tp::vec2f crs, tp::halnf pressure) override;
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) override;
|
||||
virtual ~PencilBrush();
|
||||
};
|
||||
|
||||
struct EraserBrush : public Brush {
|
||||
EraserBrush() { mType = "eraser"; }
|
||||
virtual void sample(Project* proj, tp::vec2f crs, tp::halnf pressure) override {}
|
||||
virtual void draw(Renderer* render, tp::Camera* camera) override {}
|
||||
virtual ~EraserBrush() {}
|
||||
};
|
||||
|
||||
class Project {
|
||||
|
||||
public:
|
||||
|
||||
struct Layer {
|
||||
tp::string name = "new layer";
|
||||
tp::List<Stroke*> strokes;
|
||||
bool enabled = true;
|
||||
~Layer();
|
||||
};
|
||||
|
||||
tp::Array<Layer*> mLayers;
|
||||
tp::halni mActiveLayer = -1;
|
||||
|
||||
tp::Camera mCamera;
|
||||
tp::rgba mBackgroundColor = { 0.22f, 0.22f, 0.25f, 1.f };
|
||||
|
||||
tp::HashMap<Brush*, tp::string> mBrushes;
|
||||
tp::string mActiveBrush;
|
||||
|
||||
Project();
|
||||
~Project();
|
||||
|
||||
tp::alni saveSize();
|
||||
void save(tp::File& file);
|
||||
void load(tp::File& file);
|
||||
};
|
||||
|
||||
class Renderer {
|
||||
tp::ogl::fbuffer mBufferDowncast;
|
||||
tp::ogl::fbuffer mBuffer;
|
||||
tp::ogl::shader mShader;
|
||||
|
||||
// shader uniforms
|
||||
GLuint mMatrixUniform = 0;
|
||||
GLuint mColorUniform = 0;
|
||||
GLuint mRatioUniform = 0;
|
||||
GLuint mTargetUniform = 0;
|
||||
GLuint mBGColUniform = 0;
|
||||
|
||||
public:
|
||||
Renderer(tp::vec2f size);
|
||||
|
||||
void renderBegin();
|
||||
void setViewport(tp::rectf viewport);
|
||||
void drawStroke(Stroke* str, tp::Camera* camera);
|
||||
void renderEnd();
|
||||
|
||||
void setClearCol(tp::rgba col);
|
||||
tp::uhalni getTextudeId();
|
||||
tp::ogl::fbuffer* getBuff();
|
||||
|
||||
~Renderer();
|
||||
};
|
||||
};
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "strokes.h"
|
||||
|
||||
struct ProjectInfo {
|
||||
char name[10] = {0};
|
||||
char version[10] = {0};
|
||||
|
||||
void init(tp::alni v) {
|
||||
tp::string version_s(v);
|
||||
tp::memcp(name, "strokes", tp::slen("strokes"));
|
||||
tp::memcp(version, version_s.cstr(), version_s.size());
|
||||
}
|
||||
};
|
||||
|
||||
namespace StrokesVersion0 {
|
||||
|
||||
tp::alni save_size(strokes_project* proj) {
|
||||
tp::alni out = 0;
|
||||
out += sizeof(tp::Camera);
|
||||
out += sizeof(tp::rgba);
|
||||
|
||||
out += sizeof(tp::alni);
|
||||
for (auto layer : proj->layers) {
|
||||
for (auto stiter : layer->strokes) {
|
||||
stroke* str = &stiter.data();
|
||||
|
||||
out += sizeof(tp::rgba);
|
||||
|
||||
out += sizeof(tp::alni);
|
||||
out += str->points.length() * sizeof(stroke_point);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void save(tp::File& file, strokes_project* proj) {
|
||||
|
||||
file.write<tp::Camera>(&proj->cam);
|
||||
file.write<tp::rgba>(&proj->canvas_color);
|
||||
|
||||
drawlayer base_layer;
|
||||
proj->append_layers(&base_layer);
|
||||
|
||||
tp::alni len = base_layer.strokes.length();
|
||||
file.write<tp::alni>(&len);
|
||||
for (auto stiter : base_layer.strokes) {
|
||||
stroke* str = &stiter.data();
|
||||
|
||||
tp::alni length = str->points.length();
|
||||
file.write<tp::alni>(&length);
|
||||
file.write<tp::rgba>(&str->mesh.color);
|
||||
|
||||
for (auto piter : str->points) {
|
||||
file.write<stroke_point>(&piter.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load(tp::File& file, strokes_project* proj) {
|
||||
file.read<tp::Camera>(&proj->cam);
|
||||
|
||||
file.read<tp::rgba>(&proj->canvas_color);
|
||||
|
||||
drawlayer* base = proj->get_base_layer();
|
||||
|
||||
tp::alni len;
|
||||
file.read<tp::alni>(&len);
|
||||
|
||||
for (tp::alni str_idx = 0; str_idx < len; str_idx++) {
|
||||
stroke str = stroke();
|
||||
|
||||
tp::alni p_len; file.read<tp::alni>(&p_len);
|
||||
tp::rgba color; file.read<tp::rgba>(&color);
|
||||
|
||||
str.points.reserve(p_len);
|
||||
for (auto piter : str.points) {
|
||||
file.read<stroke_point>(&piter.data());
|
||||
}
|
||||
|
||||
str.mesh.color = color;
|
||||
base->add_stroke(str);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace StrokesVersion1 {
|
||||
|
||||
tp::alni save_size(strokes_project* proj) {
|
||||
tp::alni out = 0;
|
||||
out += sizeof(tp::Camera);
|
||||
out += sizeof(tp::halnf);
|
||||
out += sizeof(tp::halnf);
|
||||
out += sizeof(tp::rgba);
|
||||
|
||||
out += sizeof(tp::alni);
|
||||
for (auto layer : proj->layers) {
|
||||
out += layer->name.save_size();
|
||||
out += sizeof(bool);
|
||||
out += sizeof(tp::alni);
|
||||
for (auto stiter : layer->strokes) {
|
||||
stroke* str = &stiter.data();
|
||||
out += sizeof(tp::rgba);
|
||||
out += sizeof(tp::alni);
|
||||
out += str->points.length() * sizeof(stroke_point);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void save(tp::File& file, strokes_project* proj) {
|
||||
|
||||
file.write<tp::Camera>(&proj->cam);
|
||||
file.write<tp::halnf>(&proj->sampler.eraser_size);
|
||||
file.write<tp::halnf>(&proj->sampler.screen_thikness);
|
||||
file.write<tp::rgba>(&proj->canvas_color);
|
||||
|
||||
tp::alni lay_len = proj->layers.length();
|
||||
file.write<tp::alni>(&lay_len);
|
||||
for (auto layer : proj->layers) {
|
||||
layer->name.save(&file);
|
||||
|
||||
file.write<bool>(&layer->hiden);
|
||||
|
||||
tp::alni len = layer->strokes.length();
|
||||
file.write<tp::alni>(&len);
|
||||
for (auto stiter : layer->strokes) {
|
||||
stroke* str = &stiter.data();
|
||||
|
||||
file.write<tp::rgba>(&str->mesh.color);
|
||||
|
||||
tp::alni length = str->points.length();
|
||||
file.write<tp::alni>(&length);
|
||||
for (auto piter : str->points) {
|
||||
file.write<stroke_point>(&piter.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load(tp::File& file, strokes_project* proj) {
|
||||
file.read<tp::Camera>(&proj->cam);
|
||||
|
||||
file.read<tp::halnf>(&proj->sampler.eraser_size);
|
||||
file.read<tp::halnf>(&proj->sampler.screen_thikness);
|
||||
file.read<tp::rgba>(&proj->canvas_color);
|
||||
|
||||
tp::alni layers_len;
|
||||
file.read<tp::alni>(&layers_len);
|
||||
for (tp::alni str_idx = 0; str_idx < layers_len; str_idx++) {
|
||||
|
||||
tp::string key; key.load(&file);
|
||||
drawlayer* layer = new drawlayer();
|
||||
layer->name = key;
|
||||
proj->layers.pushBack(layer);
|
||||
|
||||
file.read<bool>(&layer->hiden);
|
||||
|
||||
tp::alni len;
|
||||
file.read<tp::alni>(&len);
|
||||
|
||||
for (tp::alni str_idx = 0; str_idx < len; str_idx++) {
|
||||
stroke str = stroke();
|
||||
|
||||
tp::rgba color; file.read<tp::rgba>(&color);
|
||||
|
||||
tp::alni p_len; file.read<tp::alni>(&p_len);
|
||||
str.points.reserve(p_len);
|
||||
for (auto piter : str.points) {
|
||||
file.read<stroke_point>(&piter.data());
|
||||
}
|
||||
|
||||
str.mesh.color = color;
|
||||
layer->add_stroke(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue