-
-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(renderer): renderer package #595
Closed
therealtimhawkins
wants to merge
12
commits into
motion-canvas:main
from
therealtimhawkins:renderer-package
+193
−3
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
617fdd0
feat(renderer): adds renderer package setup
therealtimhawkins 7725ed5
feat(renderer): updates renderer package to use virtual module
therealtimhawkins 70a625f
feat(renderer): adds render process to renderer main.ts
therealtimhawkins 0a9033e
feat(renderer): allows project name to be passed as command line arg
therealtimhawkins d670f2c
feat(renderer): allows user to select whether to install renderer on …
therealtimhawkins 2b5936f
feat(renderer): adds window onRenderComplete type
therealtimhawkins c3b9d56
feat(renderer): moves rendering complete message to render
therealtimhawkins 4fdacb1
Merge branch 'main' into renderer-package
therealtimhawkins b416314
fix(renderer): removes changes to create package for another PR
therealtimhawkins 6631828
fix(renderer): merges in main
therealtimhawkins 5244a85
fix(renderer): updates package-lock to remove renderer package from c…
therealtimhawkins b841b89
fix(renderer): updates renderer package.json to inlude puppeteer
therealtimhawkins File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ module.exports = { | |
'examples', | ||
'legacy', | ||
'player', | ||
'renderer', | ||
'ui', | ||
'vite-plugin', | ||
], | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `renderer` | ||
|
||
> TODO: description | ||
|
||
## Usage | ||
|
||
``` | ||
const renderer = require('renderer'); | ||
|
||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@motion-canvas/renderer", | ||
"version": "3.3.4", | ||
"description": "A headless renderer for Motion Canvas", | ||
"homepage": "https://motioncanvas.io/", | ||
"license": "MIT", | ||
"main": "dist/main.js", | ||
"type": "module", | ||
"directories": { | ||
"dist": "dist", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/motion-canvas/motion-canvas.git" | ||
}, | ||
"scripts": { | ||
"build": "ttsc", | ||
"watch": "ttsc -w", | ||
"render": "node ./dist/render.js" | ||
}, | ||
"devDependencies": { | ||
"@motion-canvas/core": "*", | ||
"@motion-canvas/vite-plugin": "*", | ||
"puppeteer": "^19.3.0" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/motion-canvas/motion-canvas/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Motion Canvas Renderer</title> | ||
<link | ||
rel="icon" | ||
type="image/png" | ||
sizes="16x16" | ||
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAOwAAADsAEnxA+tAAABKklEQVQ4jcWTvUoDURCFv/y0A2tnZ95AW7FZwQdQSO9aRLAJbp0mPkGCTSCBmPQW8Q1SuKTU4AvkEeQO2K6MuSFmN+pCCg9cLhdmzpwzh1tK05RdUN6p+yeCftKK+kmrW4SguvGaNc3PGGRUVEE18x4Dl9dlheP76OZxMQUCIOzVa++/W2jENYaV7oqEWTMETMmhv7fi+w4i4IVhxaaeAq+9es0aL4CJqoaqOsmSrGNsxCZ16ideMeiMVPVrJyISqerC7IhIsN3CoGMeTfYceKARn6/sqOozcADkktmMcU3y5KeZrQQ4ARxwpqpts5O3kIEvGvnJ1vwB7PuquYgc5RVs4tZHeAe8WbOIlIA9r3IJU/DXcc61nXOpcy7I1hb9C5aOLTeHf/6NwCdua48fJxuYPgAAAABJRU5ErkJggg==" | ||
/> | ||
</head> | ||
<body> | ||
<h1>RENDERING!</h1> | ||
<script type="module" src="{{source}}"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type {Project} from '@motion-canvas/core'; | ||
import {Renderer} from '@motion-canvas/core'; | ||
|
||
declare global { | ||
interface Window { | ||
onRenderComplete: () => void; | ||
} | ||
} | ||
|
||
export const render = async (project: Project) => { | ||
try { | ||
const renderer = new Renderer(project); | ||
await renderer.render({ | ||
...project.meta.getFullRenderingSettings(), | ||
name: project.name, | ||
}); | ||
} finally { | ||
window.onRenderComplete(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import fs from 'fs'; | ||
import * as path from 'path'; | ||
import puppeteer from 'puppeteer'; | ||
import {createServer} from 'vite'; | ||
import {fileURLToPath} from 'url'; | ||
|
||
const Root = fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
(async () => { | ||
console.log('Rendering...'); | ||
|
||
const project = process.argv[2]; | ||
const metaPath = `${Root}/../../template/src/${project}.meta`; | ||
if (!fs.existsSync(metaPath)) | ||
return console.log(`Project couldn't be found.`); | ||
|
||
const [browser, server] = await Promise.all([ | ||
puppeteer.launch({headless: true}), | ||
createServer({ | ||
root: Root, | ||
configFile: path.resolve(Root, '../vite.config.ts'), | ||
server: { | ||
port: 9000, | ||
}, | ||
}).then(server => server.listen()), | ||
]); | ||
|
||
const page = await browser.newPage(); | ||
await page.goto(`http://localhost:9000/${project}/renderer`); | ||
|
||
await page.exposeFunction('onRenderComplete', async () => { | ||
await Promise.all([browser.close(), server.close()]); | ||
console.log('Rendering complete.'); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "src", | ||
"outDir": "dist", | ||
"strict": true, | ||
"module": "esnext", | ||
"esModuleInterop": true, | ||
"target": "esnext", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"allowSyntheticDefaultImports": true, | ||
"plugins": [ | ||
{ | ||
"transform": "@motion-canvas/internal/transformers/markdown-literals.js" | ||
} | ||
] | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {defineConfig} from 'vite'; | ||
import motionCanvas from '@motion-canvas/vite-plugin'; | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
motionCanvas.default({ | ||
project: [`@motion-canvas/template/src/${process.argv[2]}.ts`], | ||
editor: '@motion-canvas/renderer', | ||
editorFileName: '../renderer.html', | ||
}), | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this port number be configurable?
Not exactly sure if this is related, but I noticed that running
npm run serve
offers the following convenience: will start on port9000
, and if it's not available, use the next available e.g.9001
.Perhaps the port number here could follow a similar approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choosing the next available port is a Vite functionality. It will do it automatically.
Tho it may be a good idea to actually check what port Vite picked using:
and redirect Puppeteer there.
Right now we're using a hardcoded
9000
which will work most of the time but will fail if something is already running on9000
.