Skip to content

Commit

Permalink
Merge pull request #1 from metrica-sports/fran/allow-rendering-in-web…
Browse files Browse the repository at this point in the history
…workers

Allow rendering in web-workers
  • Loading branch information
FranCarrascosaMS authored Oct 3, 2023
2 parents 5266f19 + 18ae87c commit e1034c2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.48.1",
"version": "1.0.0",
"command": {
"version": {
"conventionalCommits": true
Expand Down
4 changes: 2 additions & 2 deletions packages/troika-2d/src/HitTestContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* whether an Object2DFacade is under the mouse cursor, by passing this as the context
* to its render() method.
*/

const hitTestContext = document.createElement('canvas').getContext('2d')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
const hitTestContext = canvas.getContext('2d')
hitTestContext.save()

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-3d/src/facade/WorldTextureProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function makeWorldTextureProvider(WrappedFacadeClass) {
}
if (newWorldConfig) {
this.worldTexture.dispose()
const canvas = document.createElement('canvas')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
canvas.width = newWorldConfig.width
canvas.height = newWorldConfig.height
this.worldTexture = new CanvasTexture(canvas)
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-animation/src/Interpolators.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const colorValueToNumber = (function() {

// 2D canvas for evaluating string values
if (!colorCanvas) {
colorCanvas = document.createElement('canvas')
colorCanvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
colorCanvasCtx = colorCanvas.getContext('2d')
}

Expand Down
17 changes: 14 additions & 3 deletions packages/troika-three-text/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
{
"name": "troika-three-text",
"version": "0.48.1",
"description": "SDF-based text rendering for Three.js",
"author": "Jason Johnston <jason.johnston@protectwise.com>",
"version": "1.0.0",
"author": {
"name": "Metrica Sports",
"email": "info@metrica-sports.com"
},
"versionForked": "0.48.1",
"authorForked": {
"name": "Jason Johnston",
"email": "jason.johnston@protectwise.com"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"repository": {
"type": "git",
"url": "https://github.com/protectwise/troika.git",
"url": "https://github.com/metrica-sports/troika.git",
"directory": "packages/troika-three-text"
},
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/troika-three-text/src/TextBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function getTextRenderInfo(args, callback) {
const glyphsPerRow = (textureWidth / sdfGlyphSize * 4)
let atlas = atlases[sdfGlyphSize]
if (!atlas) {
const canvas = document.createElement('canvas')
const canvas = typeof document === 'undefined' ? new OffscreenCanvas() : document.createElement('canvas')
canvas.width = textureWidth
canvas.height = sdfGlyphSize * 256 / glyphsPerRow // start tall enough to fit 256 glyphs
atlas = atlases[sdfGlyphSize] = {
Expand Down

0 comments on commit e1034c2

Please sign in to comment.