I am attempting to create a reusable functional component in order to minimize code duplication. The purpose of this component is to render an SVG, translate it, and then return the translated SVG to be added to the scene individually. The reusability portion of the function produces the desired results, but every time the function is called all the individually rendered THREE.Group
(s) are all translated to the same position, meaning the last ran function is where all of the THREE.Group
(s) will be positioned. It is my understanding that Groups are for translating multiple meshes together (which is working as expected), but I figured that Groups added to an array could be translated individually by their index. I have tried several iterations, but all producing the same results.
let svgArray = [];
for(let i =0; i <= 3; i++){
svgArray[i] = new THREE.Group();
}
renderSVG(state, state.svg0Url, svgArray, 0);
renderSVG(state, state.svg1Url, svgArray, 1);
renderSVG(state, state.svg2Url, svgArray, 2);
renderSVG(state, state.svg3Url, svgArray, 3);
… inside the renderSVG(state, url, svgArray, location) function …
...
{
...
extrudedGeometry.computeBoundingBox();
extrudedGeometry.computeVertexNormals();
extrudedGeometry.center();
extrudedGeometry.translate(0, -state.svgMiddleY, 33.2);
extrudedGeometry.rotateY( svgRotation );
const mesh = new THREE.Mesh( extrudedGeometry, material );
// svgArray[location].add( mesh ); // same results
svg.add( mesh );
}
svgArray[location] = svg;
return svgArray[location] != null ? { ...svgArray[location] } : '';
Any insight as to why the THREE.Group
(s) are being translated as one unit instead of individually?