API Reference

Class List

ContainerResource

Summary

Methods

applyMaterialVariant

Applies a material variant to an entity hierarchy.

applyMaterialVariantInstances

Applies a material variant to a set of mesh instances.

getMaterialVariants

Queries the list of available material variants.

instantiateModelEntity

Instantiates an entity with a model component.

instantiateRenderEntity

Instantiates an entity with a render component.

Details

Constructor

ContainerResource()

Container for a list of animations, textures, materials, renders and a model.

Methods

applyMaterialVariant(entity, [name])

Applies a material variant to an entity hierarchy.

// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", function (err, asset) {
    var entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);
    var materialVariants = asset.resource.getMaterialVariants();
    asset.resource.applyMaterialVariant(entity, materialVariants[0]);

Parameters

entityEntity

The entity root to which material variants will be applied

namestring

The name of the variant, as queried from getMaterialVariants, if null the variant will be reset to the default

applyMaterialVariantInstances(instances, [name])

Applies a material variant to a set of mesh instances. Compared to the applyMaterialVariant, this method allows for setting the variant on a specific set of mesh instances instead of the whole entity.

// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", function (err, asset) {
    var entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);
    var materialVariants = asset.resource.getMaterialVariants();
    var renders = entity.findComponents("render");
    for (var i = 0; i < renders.length; i++) {
        var renderComponent = renders[i];
        asset.resource.applyMaterialVariantInstances(renderComponent.meshInstances, materialVariants[0]);
    }

Parameters

instancesMeshInstance[]

An array of mesh instances

namestring

The the name of the variant, as quered from getMaterialVariants, if null the variant will be reset to the default

getMaterialVariants()

Queries the list of available material variants.

Returns

string[]

An array of variant names.

instantiateModelEntity([options])

Instantiates an entity with a model component.

// load a glb file and instantiate an entity with a model component based on it
app.assets.loadFromUrl("statue.glb", "container", function (err, asset) {
    var entity = asset.resource.instantiateModelEntity({
        castShadows: true
    });
    app.root.addChild(entity);
});

Parameters

optionsobject

The initialization data for the model component type ModelComponent.

Returns

Entity

A single entity with a model component. Model component internally contains a hierarchy based on GraphNode.

instantiateRenderEntity([options])

Instantiates an entity with a render component.

// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", function (err, asset) {
    var entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);

    // find all render components containing mesh instances, and change blend mode on their materials
    var renders = entity.findComponents("render");
    renders.forEach(function (render) {
        render.meshInstances.forEach(function (meshInstance) {
            meshInstance.material.blendType = pc.BLEND_MULTIPLICATIVE;
            meshInstance.material.update();
        });
    });
});

Parameters

optionsobject

The initialization data for the render component type RenderComponent.

Returns

Entity

A hierarchy of entities with render components on entities containing renderable geometry.