Skip to content

Commit

Permalink
Simplified shapes and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
goossens committed Apr 28, 2024
1 parent 1b6f3b5 commit da79640
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 228 deletions.
1 change: 1 addition & 0 deletions deps/assimp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(ASSIMP_BUILD_BLEND_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_FBX_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_GLTF_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_OBJ_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_STL_IMPORTER ON CACHE BOOL "" FORCE)
set(ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(ASSIMP_INSTALL OFF CACHE BOOL "" FORCE)
set(ASSIMP_INJECT_DEBUG_POSTFIX OFF CACHE BOOL "" FORCE)
Expand Down
112 changes: 96 additions & 16 deletions examples/scenes/text/assets/text.otn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
"from": 2873823255,
"id": 2160878527,
"to": 3195650876
},
{
"from": 4048718069,
"id": 2920632154,
"to": 729637025
},
{
"from": 3521990454,
"id": 2178711956,
"to": 2381672726
},
{
"from": 2547115557,
"id": 1069569191,
"to": 3761969199
},
{
"from": 143155056,
"id": 3271718652,
"to": 605994486
}
],
"metadata": {},
Expand All @@ -34,6 +54,54 @@
"x": 67.0,
"y": 77.0
},
{
"id": 1509100340,
"inputs": [],
"outputs": [
{
"id": 4048718069,
"name": "Value",
"type": "float"
}
],
"title": "Size",
"type": "Float Input",
"value": 12.0,
"x": 69.0,
"y": 246.0
},
{
"id": 240854171,
"inputs": [],
"outputs": [
{
"id": 3521990454,
"name": "Value",
"type": "string"
}
],
"title": "Text",
"type": "String Input",
"value": "Test",
"x": 69.0,
"y": 160.0
},
{
"id": 2590841629,
"inputs": [],
"outputs": [
{
"id": 143155056,
"name": "Value",
"type": "bool"
}
],
"title": "Center",
"type": "Boolean Input",
"value": true,
"x": 71.0,
"y": 328.0
},
{
"id": 325703201,
"inputs": [
Expand All @@ -45,14 +113,17 @@
{
"id": 2381672726,
"name": "Text",
"type": "string",
"value": "Test"
"type": "string"
},
{
"id": 729637025,
"name": "Size",
"type": "float",
"value": 12.0
"type": "float"
},
{
"id": 605994486,
"name": "Center",
"type": "bool"
}
],
"outputs": [
Expand All @@ -67,6 +138,22 @@
"x": 408.0,
"y": 52.0
},
{
"id": 1210579916,
"inputs": [],
"outputs": [
{
"id": 2547115557,
"name": "Value",
"type": "float"
}
],
"title": "Depth",
"type": "Float Input",
"value": 3.0,
"x": 72.0,
"y": 410.0
},
{
"id": 3232750156,
"inputs": [
Expand All @@ -78,14 +165,7 @@
{
"id": 3761969199,
"name": "Depth",
"type": "float",
"value": 3.0
},
{
"id": 4124497261,
"name": "Segments",
"type": "int",
"value": 400
"type": "float"
}
],
"outputs": [
Expand All @@ -97,8 +177,8 @@
],
"title": "Extrude Shape",
"type": "Extrude Shape",
"x": 667.0,
"y": 27.0
"x": 665.0,
"y": 174.0
},
{
"id": 2601550030,
Expand All @@ -118,8 +198,8 @@
"outputs": [],
"title": "Save Geometry To Virtual",
"type": "Save Geometry To Virtual",
"x": 929.0,
"y": 28.0
"x": 925.0,
"y": 174.0
}
]
}
14 changes: 13 additions & 1 deletion examples/scenes/text/text.ots
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
1.0
],
"translation": [
-9.0,
0.0,
-6.630000114440918,
-3.2200000286102295
]
Expand Down Expand Up @@ -135,6 +135,18 @@
"component": "Nodes",
"path": "assets/text.otn",
"settings": {
"1210579916": {
"value": 3.0
},
"1509100340": {
"value": 12.0
},
"240854171": {
"value": "Test"
},
"2590841629": {
"value": true
},
"2625173197": {
"path": "assets/roboto.ttf"
}
Expand Down
5 changes: 3 additions & 2 deletions gfx/shapes/OtCubicBezierSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
// Include files
//

#include "OtShapeSegment.h"
#include "OtCurveSegment.h"


//
// OtCubicBezierSegment
//

class OtCubicBezierSegment : public OtShapeSegment {
class OtCubicBezierSegment : public OtCurveSegment {
public:
// constructor
inline OtCubicBezierSegment(const glm::vec2& v1, const glm::vec2& v2, const glm::vec2& v3, const glm::vec2& v4) {
p1 = v1;
p2 = v2;
p3 = v3;
p4 = v4;
calculateLength();
}

// get a point in the segment at curve parameter t [0, 1]
Expand Down
55 changes: 55 additions & 0 deletions gfx/shapes/OtCurveSegment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ObjectTalk Scripting Language
// Copyright (c) 1993-2024 Johan A. Goossens. All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.


#pragma once


//
// Include files
//

#include "glm/glm.hpp"

#include "OtShapeSegment.h"


//
// OtCurveSegment
//

class OtCurveSegment : public OtShapeSegment {
// get length of segment
float getLength() override {return length; };

// get points on segment
void getPoints(std::vector<glm::vec2>& result) override {
// determine point count based on size
int points = int(length / 0.1f);

for (auto i = 1; i <= points; i++) {
result.push_back(getPoint((float) i / (float) points));
}
}

protected:
// get a point in the segment at curve parameter t [0, 1]
virtual glm::vec2 getPoint(float t) = 0;

// calculate length of segment
inline void calculateLength(size_t division=100) {
glm::vec2 last = getPoint(0.0f);

for (auto i = 1; i <= division; i++) {
glm::vec2 current = getPoint((float) i / (float) division);
length += glm::distance(current, last);
last = current;
}
}

// total segment length
float length = 0.0f;
};
24 changes: 5 additions & 19 deletions gfx/shapes/OtLineSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,16 @@ class OtLineSegment : public OtShapeSegment {
p2 = v2;
}

// get a point in the segment at curve parameter t [0, 1]
inline glm::vec2 getPoint(float t) override {
return glm::mix(p1, p2, t);
}

// get a point in the segment at arc length u [0, 1]
inline glm::vec2 getPointAtArcLength(float u) override {
return getPoint(u);
}

// get a unit vector tangent at t [0, 1]
inline glm::vec2 getTangent(float t) override {
return glm::normalize(p2 - p1);
}

virtual inline glm::vec2 getTangentAt(float u) override {
return getTangent(u);
}

// get the length of the segment
inline float getLength() override {
return glm::distance(p1, p2);
}

// get points on segment
virtual void getPoints(std::vector<glm::vec2>& result) override {
result.push_back(p2);
}

// convert segment to string representation
inline std::string toString() override {
return fmt::format("l {} {}\n", p2.x, p2.y);
Expand Down
5 changes: 3 additions & 2 deletions gfx/shapes/OtQuadraticBezierSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
// Include files
//

#include "OtShapeSegment.h"
#include "OtCurveSegment.h"


//
// OtQuadraticBezierSegment
//

class OtQuadraticBezierSegment : public OtShapeSegment {
class OtQuadraticBezierSegment : public OtCurveSegment {
public:
// constructor
inline OtQuadraticBezierSegment(const glm::vec2& v1, const glm::vec2& v2, const glm::vec2& v3) {
p1 = v1;
p2 = v2;
p3 = v3;
calculateLength();
}

// get a point in the segment at curve parameter t [0, 1]
Expand Down
Loading

0 comments on commit da79640

Please sign in to comment.