The MaterialAPI provides a set of methods for creating and managing materials in a webvis context. It allows you to:
Create materials and assign them to specific nodes in a scene.
Edit and update existing materials.
Retrieve all materials at once.
Request detailed material data for a specific material.
Remove materials when they are no longer needed.
Quick Start
The fastest way to get familiar with the MaterialAPI is by creating a material and assigning it to a node. The material can then be updated later and removed when it is no longer needed:
// Get the webvis contextconstcontext = webvis.getContext();// Create a node to assign the material to and enable the resource to make it visibleconstnodeId = context.add({dataURI:"urn:x-i3d:shape:box", initialProperties: {enabled:true}});// Create a materialconstmaterialId = context.createMaterial({baseColor: [1, 0, 0],opacity:1,roughness:0.5,metallic:0,name:"Red Material",});// Create an appearance URI which can be used to assign the material to a nodeconstappearanceURI = `urn:X-l3d:material:${materialId}`;// Assign the material to the previously added node via the APPEARANCE_URI propertyawaitcontext.setProperty(nodeId, webvis.Property.APPEARANCE_URI, appearanceURI);// Change the base color and the name of the materialcontext.changeMaterial(materialId, {baseColor: [0, 1, 0],name:"Green Material" });// Unassign the material from the nodeawaitcontext.setProperty(nodeId, webvis.Property.APPEARANCE_URI, null);// Remove the material if no longer requiredcontext.removeMaterial(materialId);
Events
The following events are associated with the MaterialAPI:
MaterialAPI
Overview
The MaterialAPI provides a set of methods for creating and managing materials in a webvis context. It allows you to:
Quick Start
The fastest way to get familiar with the MaterialAPI is by creating a material and assigning it to a node. The material can then be updated later and removed when it is no longer needed:
Events
The following events are associated with the MaterialAPI: