Implement a renaming transform function? #1613
-
Please forgive my newness to this general space. If I wanted to implement a renaming transform function, is this a good place to do it? I'd like to allow our CAD designers to continue with their own convention, but implement some custom patterns (followed by a generic camel case fn) on the e.g. <group name="14ga_A3_baseFrame_RearLogoPlate_MotionBoxMount_MKIII_v11" /> The same with Is a custom Thank you for any advice! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @rosskevin! It should be no problem to rename nodes, materials, and meshes in glTF Transform, yes. The code could be written as a transform, or not, no meaningful difference except the syntax. I usually define an operation as a transform if it operates on the entire document and if its configuration can be described well by a single options declaration. For example, Example: // function
function renameProperties(properties: Property[], prefix: string) {
properties.forEach((property, index) => {
property.setName(`${prefix}_${index}`);
});
}
// transform
function rename(options) {
return async (document) => {
renameProperties(document.listNodes(), 'node');
renameProperties(document.listMaterials(), 'material');
};
}
const document = await io.read('path/to/scene.glb');
await document.transform(rename());
await io.write('path/to/output.glb', document); The transform is just syntax, this would have worked as well: const document = await io.read('path/to/scene.glb');
renameProperties(document.listNodes(), 'node');
renameProperties(document.listMaterials(), 'material');
await io.write('path/to/output.glb', document); |
Beta Was this translation helpful? Give feedback.
Hi @rosskevin! It should be no problem to rename nodes, materials, and meshes in glTF Transform, yes. The code could be written as a transform, or not, no meaningful difference except the syntax. I usually define an operation as a transform if it operates on the entire document and if its configuration can be described well by a single options declaration. For example,
joinPrimitives(prims)
is a function that merges a given list ofPrimitives
, andjoin()
is a transform that usesjoinPrimitives
to combine all compatible primitives throughout the document.Example: