akbartus / a-frame-component-gltf-manipulator Goto Github PK
View Code? Open in Web Editor NEWThis is A-Frame component for editing GLTF/GLB files.
Home Page: https://gltf-manipulator.glitch.me/
License: MIT License
This is A-Frame component for editing GLTF/GLB files.
Home Page: https://gltf-manipulator.glitch.me/
License: MIT License
Thanks for sharing this example.
I did something similar in a project to override some material properties only, but using multiple components. Like this:
AFRAME.registerComponent("material-values", {
multiple: true,
schema: {
materialName: { type: "string", default: "" },
color: { type: "color", default: "" },
map: { type: "string", default: "" },
metalness: { type: "number", default: -1, min: 0, max: 1 },
roughness: { type: "number", default: -1, min: 0, max: 1 },
opacity: { type: "number", default: 1, min: 0, max: 1 }
},
events: {
"model-loaded": function () {
this.update();
},
},
init() {
this.rendererSystem = this.el.sceneEl.systems.renderer;
},
update: function () {
const mesh = this.el.getObject3D("mesh");
if (!mesh) return;
const materialName = this.data.materialName;
const color = this.data.color;
const map = this.data.map;
const metalness = this.data.metalness;
const roughness = this.data.roughness;
const opacity = this.data.opacity;
const materialSeen = new Set();
mesh.traverse((node) => {
if (node.material && node.material.name === materialName) {
if (materialSeen.has(node.material.name)) return;
if (color !== "") {
node.material.color.set(color);
// The following line calls node.material.color.convertSRGBToLinear() when <a-scene renderer="colorManagement:true">
this.rendererSystem.applyColorCorrection(node.material.color);
} else {
this.data.color = "#" + node.material.color.getHexString();
}
if (metalness !== -1) {
node.material.metalness = metalness;
} else {
this.data.metalness = node.material.metalness;
}
if (roughness !== -1) {
node.material.roughness = roughness;
} else {
this.data.roughness = node.material.roughness;
}
if (map) {
const imageSrc = map;
const loader = new THREE.TextureLoader();
loader.load(
imageSrc,
function (texture) {
if (node.material.map) {
texture.encoding = node.material.map.encoding;
texture.flipY = node.material.map.flipY;
texture.offset.copy(node.material.map.offset);
texture.repeat.copy(node.material.map.repeat);
texture.wrapS = node.material.map.wrapS;
texture.wrapT = node.material.map.wrapT;
node.material.map.dispose();
}
node.material.map = texture;
texture.needsUpdate = true;
node.material.needsUpdate = true;
},
undefined,
function () {
console.error(`Error loading ${imageSrc}`);
}
);
}
node.material.opacity = opacity;
// if opacity is 1, keep the current transparent value, that may be true
if (opacity < 1) {
node.material.transparent = opacity < 1;
}
node.material.needsUpdate = true;
node.visible = opacity !== 0;
materialSeen.add(node.material.name);
}
});
materialSeen.clear();
},
});
and using it like this:
<a-entity
material-values__glass="materialName:glass;metalness:0.882;roughness:0.055;opacity:0.9"
material-values__body="materialName:body_color;color:#ad050f;metalness:0.85;roughness:0.25"
gltf-model="car.glb"
></a-entity>
If I don't specify a property, for example roughness, it defaults to -1, and I don't set it.
Also this way you can use the inspector and have a color picker to change the color.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.