Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/jobs/test_install_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- script: |
sudo apt-get update
sudo apt-get install libjavascriptcoregtk-4.0-dev libgl1-mesa-dev libcurl4-openssl-dev
sudo apt-get install libjavascriptcoregtk-4.0-dev libgl1-mesa-dev libcurl4-openssl-dev libwayland-dev
displayName: 'Install packages'

- script: |
Expand Down
20 changes: 19 additions & 1 deletion Apps/Playground/Scripts/experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ CreateBoxAsync(scene).then(function () {
context.font = "bold 60px monospace";
context.fillText("Gradient Text!", 10, 420);


context.lineWidth = 5;
// Rounded rectangle with zero radius (specified as a number)
context.strokeStyle = "red";
Expand Down Expand Up @@ -214,6 +213,25 @@ CreateBoxAsync(scene).then(function () {
context.roundRect(400, 350, -200, 100, [0, 30, 50, 60]);
context.stroke();

// Path 2D stroke
context.strokeStyle = "black";
context.lineWidth = 2;
let heartPath = new engine.createCanvasPath2D("M390,30 A 20, 20 0, 0, 1 430, 30 A 20, 20 0, 0, 1 470, 30 Q 470, 60 430, 90 Q 390, 60 390, 30 z");
let squarePath = new engine.createCanvasPath2D("M380, 10 h100 v100 h-100 Z");
heartPath.addPath(squarePath, { a: 1, b: 0, c: 0, d: 1, e: 0, f: -5 }); // push square 5px up to center heart.
context.stroke(heartPath);

// Path 2D fill
context.fillStyle = "yellow";
let diamondPath = new engine.createCanvasPath2D();
diamondPath.moveTo(350, 200); // Start at the center
diamondPath.lineTo(375, 175); // Move to the top point
diamondPath.lineTo(400, 200); // Move to the right point
diamondPath.lineTo(375, 225); // Move to the bottom point
diamondPath.lineTo(350, 200); // Close back to the starting point
context.fill(diamondPath);


// Draw clipped round rect
// TODO: this is currently broken, clipping area does not have round corners
context.beginPath();
Expand Down
86 changes: 43 additions & 43 deletions Apps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Apps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"getNightly": "node scripts/getNightly.js"
},
"dependencies": {
"babylonjs": "^7.48.3",
"babylonjs-gltf2interface": "^7.48.3",
"babylonjs-gui": "^7.48.3",
"babylonjs-loaders": "^7.48.3",
"babylonjs-materials": "^7.48.3",
"babylonjs": "^7.54.0",
"babylonjs-gltf2interface": "^7.54.0",
"babylonjs-gui": "^7.54.0",
"babylonjs-loaders": "^7.54.0",
"babylonjs-materials": "^7.54.0",
"chai": "^4.3.4",
"jsc-android": "^241213.1.0",
"mocha": "^9.2.2",
Expand Down
5 changes: 5 additions & 0 deletions Install/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ if(TARGET AppRuntime)
install_include_for_targets(AppRuntime)
endif()

if(TARGET Scheduling)
install_targets(Scheduling)
install_include_for_targets(Scheduling)
endif()

if(TARGET ScriptLoader)
install_targets(ScriptLoader)
install_include_for_targets(ScriptLoader)
Expand Down
1 change: 1 addition & 0 deletions Install/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ target_link_libraries(TestInstall
openxr_loader
OSDependent
ScriptLoader
Scheduling
spirv-cross-core
spirv-cross-hlsl
SPIRV
Expand Down
137 changes: 73 additions & 64 deletions Polyfills/Canvas/Source/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,16 @@ namespace Babylon::Polyfills::Internal
SetDirty();
}

void Context::Fill(const Napi::CallbackInfo&)
void Context::Fill(const Napi::CallbackInfo& info)
{
// draw Path2D if exists
const NativeCanvasPath2D* path = info.Length() == 1 ? NativeCanvasPath2D::Unwrap(info[0].As<Napi::Object>()) : nullptr;
if (path != nullptr)
{
PlayPath2D(path);
SetDirty();
}

nvgFill(*m_nvg);
SetDirty();
}
Expand Down Expand Up @@ -419,75 +427,76 @@ namespace Babylon::Polyfills::Internal
SetDirty();
}

void Context::PlayPath2D(const NativeCanvasPath2D* path)
{
nvgBeginPath(*m_nvg);
for (const auto& command : *path)
{
const auto args = command.args;
bool setDirty = true;
switch (command.type)
{
case P2D_CLOSE:
nvgClosePath(*m_nvg);
break;
case P2D_MOVETO:
nvgMoveTo(*m_nvg, args.moveTo.x, args.moveTo.y);
break;
case P2D_LINETO:
nvgLineTo(*m_nvg, args.lineTo.x, args.lineTo.y);
break;
case P2D_BEZIERTO:
nvgBezierTo(*m_nvg, args.bezierTo.cp1x, args.bezierTo.cp1y,
args.bezierTo.cp2x, args.bezierTo.cp2y,
args.bezierTo.x, args.bezierTo.y);
break;
case P2D_QUADTO:
nvgQuadTo(*m_nvg, args.quadTo.cpx, args.quadTo.cpy,
args.quadTo.x, args.quadTo.y);
break;
case P2D_ARC:
nvgArc(*m_nvg, args.arc.x, args.arc.y, args.arc.radius,
args.arc.startAngle, args.arc.endAngle,
args.arc.counterclockwise ? NVG_CCW : NVG_CW);
break;
case P2D_ARCTO:
nvgArcTo(*m_nvg, args.arcTo.x1, args.arcTo.y1,
args.arcTo.x2, args.arcTo.y2,
args.arcTo.radius);
break;
case P2D_ELLIPSE:
// TODO: handle clockwise for nvgElipse (args.ellipse.counterclockwise)
nvgEllipse(*m_nvg, args.ellipse.x, args.ellipse.y,
args.ellipse.radiusX, args.ellipse.radiusY);
break;
case P2D_RECT:
nvgRect(*m_nvg, args.rect.x, args.rect.y,
args.rect.width, args.rect.height);
break;
case P2D_ROUNDRECT:
nvgRoundedRect(*m_nvg, args.roundRect.x, args.roundRect.y,
args.roundRect.width, args.roundRect.height,
args.roundRect.radii);
break;
case P2D_TRANSFORM:
nvgTransform(*m_nvg,
args.transform.a, args.transform.b, args.transform.c,
args.transform.d, args.transform.e, args.transform.f);
break;
default:
break;
}
}
}

void Context::Stroke(const Napi::CallbackInfo& info)
{
// draw Path2D if exists
const NativeCanvasPath2D* path = info.Length() == 1 ? NativeCanvasPath2D::Unwrap(info[0].As<Napi::Object>()) : nullptr;
if (path != nullptr)
{
nvgBeginPath(*m_nvg);
for (const auto& command : *path)
{
const auto args = command.args;
bool setDirty = true;
switch (command.type)
{
case P2D_CLOSE:
nvgClosePath(*m_nvg);
break;
case P2D_MOVETO:
nvgMoveTo(*m_nvg, args.moveTo.x, args.moveTo.y);
break;
case P2D_LINETO:
nvgLineTo(*m_nvg, args.lineTo.x, args.lineTo.y);
break;
case P2D_BEZIERTO:
nvgBezierTo(*m_nvg, args.bezierTo.cp1x, args.bezierTo.cp1y,
args.bezierTo.cp2x, args.bezierTo.cp2y,
args.bezierTo.x, args.bezierTo.y);
break;
case P2D_QUADTO:
nvgQuadTo(*m_nvg, args.quadTo.cpx, args.quadTo.cpy,
args.quadTo.x, args.quadTo.y);
break;
case P2D_ARC:
nvgArc(*m_nvg, args.arc.x, args.arc.y, args.arc.radius,
args.arc.startAngle, args.arc.endAngle,
args.arc.counterclockwise ? NVG_CCW : NVG_CW);
break;
case P2D_ARCTO:
nvgArcTo(*m_nvg, args.arcTo.x1, args.arcTo.y1,
args.arcTo.x2, args.arcTo.y2,
args.arcTo.radius);
break;
case P2D_ELLIPSE:
// TODO: handle clockwise for nvgElipse (args.ellipse.counterclockwise)
nvgEllipse(*m_nvg, args.ellipse.x, args.ellipse.y,
args.ellipse.radiusX, args.ellipse.radiusY);
break;
case P2D_RECT:
nvgRect(*m_nvg, args.rect.x, args.rect.y,
args.rect.width, args.rect.height);
break;
case P2D_ROUNDRECT:
nvgRoundedRect(*m_nvg, args.roundRect.x, args.roundRect.y,
args.roundRect.width, args.roundRect.height,
args.roundRect.radii);
break;
case P2D_TRANSFORM:
nvgTransform(*m_nvg,
args.transform.a, args.transform.b, args.transform.c,
args.transform.d, args.transform.e, args.transform.f);
break;
default:
setDirty = false; // noop
break;
}
if (setDirty)
{
SetDirty();
}
}
PlayPath2D(path);
SetDirty();
}

nvgStroke(*m_nvg);
Expand Down
2 changes: 2 additions & 0 deletions Polyfills/Canvas/Source/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Babylon/JsRuntimeScheduler.h>
#include <Babylon/Graphics/DeviceContext.h>
#include "Image.h"
#include "Path2D.h"

struct NVGcontext;

Expand Down Expand Up @@ -119,6 +120,7 @@ namespace Babylon::Polyfills::Internal
std::unordered_map<const NativeCanvasImage*, int> m_nvgImageIndices;
void BindFillStyle(const Napi::CallbackInfo& info, float left, float top, float width, float height);
void FlushGraphicResources() override;
void PlayPath2D(const NativeCanvasPath2D* path);

friend class Canvas;
};
Expand Down
Loading