Skip to content

Commit

Permalink
upd: labPBR support / Material presets (#3)
Browse files Browse the repository at this point in the history
* refactor: Split into multiple files

- Added registry, setups, and teardowns to control plugin actions

* feat: Reset exposure Action

- Added messages to baking failures
- Added reset exposure button
- Added changelog build script

* feat: labPBR output Action

* feat: Decode labPBR channels

* chore: Remove unused code

- Revert normal map usage in PbrMaterial.getMaterial()

* fix: labPBR specular map logic

- Fixed bug in alpha channel
- Added better specular and normal export names

* feat: Material brush presets

* feat: Channel assignment panel

- Created panel to list current channel assignments

* upd: Channel component cleanup

* upd: Style channel list

* feat: Material brush presets library

- Created Dialog for editing, saving and loading material brush presets

* upd: Change Action icon

- Changed material brush Action icon

* upd: Channel assignment condition
  • Loading branch information
jasonjgardner authored Jun 5, 2024
1 parent 9942879 commit 0aba465
Show file tree
Hide file tree
Showing 32 changed files with 3,878 additions and 2,306 deletions.
200 changes: 199 additions & 1 deletion plugins/pbr_preview/pbr_preview.js

Large diffs are not rendered by default.

108 changes: 108 additions & 0 deletions src/pbr_preview/changelog.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import readline from "node:readline/promises";
import { writeFile, readFile } from "node:fs/promises";

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const changelog = "./plugins/pbr_preview/changelog.json";

function createChangelog(version, changes, author, title = null, date = null) {
const changelog = {
[version.toString()]: {
title: title ?? `Version ${version}`,
date: date || new Date().toISOString().split("T")[0],
author,
categories: [],
},
};

for (const change of changes) {
changelog[version].categories.push({
title: "",
list: [],
...change,
});
}

return changelog;
}

async function amendChangelog(
version,
changes,
author,
title = null,
date = null,
) {
const data = JSON.parse(await readFile(changelog, "utf-8"));
const newChangelog = createChangelog(version, changes, author, title, date);
const mergedChangelog = { ...data, ...newChangelog };

await writeFile(changelog, JSON.stringify(mergedChangelog, null, 4));
}

async function main() {
const version = await rl.question("Enter the version number: ");
const author = await rl.question("Enter the author: ");
const title = await rl.question(
"Enter the title (leave blank for default): ",
);

const changes = [];
let makingChanges = true;
let writingDescriptions = false;

while (makingChanges) {
const change = await rl.question(
"Enter a change title (leave blank to exit): ",
);

makingChanges = change.length > 0;

if (!makingChanges) {
break;
}

const descriptions = [];
writingDescriptions = true;

while (writingDescriptions) {
const description = await rl.question(
"Enter a description (leave blank to finish): ",
);

writingDescriptions = description.length > 0;

if (!writingDescriptions) {
break;
}

descriptions.push(description);
}

changes.push({
title: change,
list: descriptions,
});
}

await amendChangelog(
version,
changes,
author,
title ?? `Version ${version}`,
new Date().toISOString().split("T")[0],
);
}

main()
.then(() => {
console.log("Changelog updated!");
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/pbr_preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "esbuild src/index.ts --bundle --minify --outfile=../../plugins/pbr_preview/pbr_preview.js",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "esbuild src/index.ts --bundle --sourcemap --outfile=../../plugins/pbr_preview/pbr_preview.js --watch",
"format": "prettier --write src/**/*.ts",
"format": "prettier --write src/**/*.ts ./*.mjs",
"dist": "npm run format && npm run build"
},
"keywords": [
Expand Down
71 changes: 71 additions & 0 deletions src/pbr_preview/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { IChannel, IRegistry } from "./types";
import { three as THREE } from "./deps";

export const NA_CHANNEL = "_NONE_";
export const CHANNELS: Record<IChannel["id"], IChannel> = {
albedo: {
id: "albedo",
label: "Albedo",
description: "The color of the material",
map: "map",
icon: "tonality",
default: new THREE.Color(0xffffff),
},
metalness: {
id: "metalness",
label: "Metalness",
description: "The material's metalness map",
map: "metalnessMap",
icon: "brightness_6",
default: new THREE.Color(0),
},
emissive: {
id: "emissive",
label: "Emissive",
description: "The material's emissive map",
map: "emissiveMap",
icon: "wb_twilight",
default: new THREE.Color(0),
},
roughness: {
id: "roughness",
label: "Roughness",
description: "The material's roughness map",
map: "roughnessMap",
icon: "grain",
default: new THREE.Color(0xffffff),
},
height: {
id: "height",
label: "Height",
description: "The material's height map",
map: "bumpMap",
icon: "landscape",
default: new THREE.Color(0xffffff),
},
normal: {
id: "normal",
label: "Normal",
description: "The material's normal map",
map: "normalMap",
icon: "looks",
default: new THREE.Color("rgb(128, 128, 255)"),
},
ao: {
id: "ao",
label: "Ambient Occlusion",
description: "The material's ambient occlusion map",
map: "aoMap",
icon: "motion_mode",
default: new THREE.Color(0xffffff),
},
};

/**
* Collection of registered Blockbench UI elements
* Used for component communication as well as to simplify cleanup
*/
export const registry: Partial<IRegistry> = {};

export const setups: Array<() => void> = [];
export const teardowns: Array<() => void> = [];
7 changes: 7 additions & 0 deletions src/pbr_preview/src/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-expect-error THREE UMD is OK
const three = THREE;
// @ts-expect-error Vue UMD is OK
const vue = Vue;
const bb = Blockbench;

export { three, bb, vue };
Loading

0 comments on commit 0aba465

Please sign in to comment.