-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ef5e5f
Showing
8 changed files
with
247 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Node | ||
*.log | ||
*.log.* | ||
node_modules | ||
|
||
out/ | ||
dist/ | ||
code.js |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2025 Hybroid Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,15 @@ | ||
# Meshify | ||
|
||
A Figma extension for converting Figma's vector objects into PPL meshes. | ||
|
||
## Development build | ||
|
||
```sh | ||
bun dev | ||
``` | ||
|
||
Bun must be installed as it is used for bundling. | ||
|
||
## License | ||
|
||
MIT |
Binary file not shown.
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,130 @@ | ||
interface Mesh { | ||
vertexes: number[][] | ||
segments: number[][] | ||
colors?: number[] | ||
} | ||
|
||
const rgbaFloatToInt = (r: number, g: number, b: number, a: number) => | ||
new Uint32Array([ | ||
(Math.round(r * 255) << 24) | | ||
(Math.round(g * 255) << 16) | | ||
(Math.round(b * 255) << 8) | | ||
Math.round(a * 255), | ||
])[0] | ||
|
||
const nodes: readonly SceneNode[] = figma.currentPage.selection | ||
|
||
console.log(nodes) | ||
if (nodes.length === 0 || nodes.length > 1) { | ||
figma.notify("⚠️ Please select one layer") | ||
figma.closePlugin() | ||
} else { | ||
if (nodes[0].type === "VECTOR") { | ||
const workingNode = nodes[0] as VectorNode | ||
// console.log(workingNode) | ||
console.log("works") | ||
const mesh: Mesh = { | ||
vertexes: [], | ||
segments: [], | ||
colors: workingNode.strokes && workingNode.strokes[0].type === "SOLID" ? [] : undefined, | ||
} | ||
|
||
workingNode.vectorNetwork.vertices.forEach((vertex) => { | ||
mesh.vertexes.push([workingNode.x + vertex.x, workingNode.y + (workingNode.height-vertex.y)]) | ||
}) | ||
if ( | ||
workingNode.strokes && | ||
mesh.colors && | ||
workingNode.strokes.length > 0 && | ||
workingNode.strokes[0].type === "SOLID" | ||
) { | ||
for (const _ of workingNode.vectorNetwork.vertices) { | ||
mesh.colors.push( | ||
rgbaFloatToInt( | ||
workingNode.strokes[0].color.r, | ||
workingNode.strokes[0].color.g, | ||
workingNode.strokes[0].color.b, | ||
workingNode.strokes[0].opacity ? workingNode.strokes[0].opacity : 1 | ||
) | ||
) | ||
} | ||
} | ||
|
||
const segments = workingNode.vectorNetwork.segments | ||
let start = -1 | ||
let end = -1 | ||
let workingSegment: number[] = []; | ||
|
||
for (let i = 0; i < segments.length; i++) { | ||
let segment = segments[i] | ||
|
||
if (i === 0) { | ||
// Start: 0, End: 1 => 0 -> 1 | ||
workingSegment.push(segment.start, segment.end) | ||
|
||
start = segment.start | ||
end = segment.end | ||
|
||
continue | ||
} | ||
|
||
if (segment.start === end) { | ||
start = segment.start | ||
end = segment.end | ||
// Start: 0, End: 1 -> | ||
// Start: 1, End: 2 => 0 -> 1 -> 2 | ||
workingSegment.push(segment.end); | ||
} else { | ||
start = segment.start | ||
end = segment.end | ||
mesh.segments.push(workingSegment); | ||
workingSegment = []; | ||
|
||
// Start: 0, End: 1 => 0 -> 1 | ||
workingSegment.push(start, end); | ||
} | ||
|
||
if (i === segments.length - 1) { | ||
mesh.segments.push(workingSegment); | ||
} | ||
} | ||
|
||
console.log(mesh) | ||
const luaTable = `meshes={${JSON.stringify(mesh) | ||
.replaceAll("[", "{") | ||
.replaceAll("]", "}") | ||
.replaceAll(":", "=") | ||
.replaceAll('"', "")}}` | ||
|
||
figma.showUI( | ||
` | ||
<script> | ||
function handleCopy(id) { | ||
// Get the text field | ||
var copyText = document.getElementById("code") | ||
// Select the text field | ||
copyText.select() | ||
copyText.setSelectionRange(0, 99999) // For mobile devices | ||
// Copy the text inside the text field | ||
// navigator.clipboard.writeText(copyText.value) | ||
document.execCommand('copy') | ||
} | ||
</script> | ||
<div> | ||
<textarea id="code" readonly>${luaTable}</textarea> | ||
<button onclick="handleCopy()">Copy to clipboard</button> | ||
</div> | ||
`, | ||
{ | ||
width: 480, | ||
height: 320, | ||
title: "Meshify - Mesh output", | ||
} | ||
) | ||
} else { | ||
figma.notify("⚠️ Please select a vector node") | ||
figma.closePlugin() | ||
} | ||
} |
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,17 @@ | ||
{ | ||
"name": "meshify", | ||
"id": "1455653320022555478", | ||
"api": "1.0.0", | ||
"main": "out/index.js", | ||
"capabilities": [], | ||
"enableProposedApi": false, | ||
"documentAccess": "dynamic-page", | ||
"editorType": [ | ||
"figma" | ||
], | ||
"networkAccess": { | ||
"allowedDomains": [ | ||
"none" | ||
] | ||
} | ||
} |
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,45 @@ | ||
{ | ||
"name": "meshify", | ||
"version": "1.0.0", | ||
"description": "Convert Figma vectors to PewPew Live meshes with ease!", | ||
"main": "code.js", | ||
"scripts": { | ||
"build": "tsc -p tsconfig.json", | ||
"lint": "eslint --ext .ts,.tsx --ignore-pattern node_modules .", | ||
"lint:fix": "eslint --ext .ts,.tsx --ignore-pattern node_modules --fix .", | ||
"watch": "npm run build -- --watch", | ||
"dev": "bun build ./index.ts --outdir ./out --watch" | ||
}, | ||
"author": "", | ||
"license": "", | ||
"devDependencies": { | ||
"@figma/eslint-plugin-figma-plugins": "*", | ||
"@figma/plugin-typings": "^1.106.0", | ||
"@typescript-eslint/eslint-plugin": "^6.12.0", | ||
"@typescript-eslint/parser": "^6.12.0", | ||
"eslint": "^8.54.0", | ||
"typescript": "^5.3.2" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@figma/figma-plugins/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"root": true, | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_", | ||
"caughtErrorsIgnorePattern": "^_" | ||
} | ||
] | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"lib": ["es6", "es2021"], | ||
"strict": true, | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./node_modules/@figma" | ||
] | ||
} | ||
} |