The colormass configurator can be used to render custom fabric designs, which are provided as color images. Internally, the configuator embeds those images into a scanned, high-quality base material. This material contributes to the overall appearance and makes your design look like wool, cotton or linen.
Examples
The following images were created using this sample code and these two images as input:
Setting the scene
For this example, we set up a test scene on the colormass platform. It consists of a chair and uses a wool-like base material. The Overlay Material Color node takes care of replacing the color information of this material and scales your pattern to the desired width and height.
While the base material is fixed, the overlay image as well as the width and height are transferred to the configurator via the corresponding input node (image input and number input).
Adding the markup
Once the scene has been prepared, the configurator component can be added to the page.
We use the ‘setParameters’ API, which is provided by the configurator component, to transfer the input data to the renderer. You can find a detailed explanation in our guide on setting parameters.
// wait for the configurator component to be availablecustomElements.whenDefined("cm-configurator-main").then(() => { cmConfigurator =document.querySelector("cm-configurator-main")})// pass the width input to the configuratorasyncfunctionupdateWidth(width) {cmConfigurator.setParameter("width","number",Number(width))}// pass the height input to the configuratorasyncfunctionupdateHeight(height) {cmConfigurator.setParameter("height","number",Number(height))}// pass the image input to the configuratorasyncfunctionupdateOverlayImage(files) {constfile= files[0]constbyteLoader=newFileReader()byteLoader.onload=asyncfunction(e) { buffer =newUint8Array(e.target.result);constimageParamData= { id:crypto.randomUUID(), contentType:file.type, data: buffer, }awaitcmConfigurator.setParameter("overlayImage","image", imageParamData) }byteLoader.readAsArrayBuffer(files[0])}
Putting it all together
The complete example code can also be found in our sample repository.