Texture

vtkTexture - handles properties associated with a texture map

Description

vtkTexture is an object that handles loading and binding of texture
maps. It obtains its data from an input image data dataset type.
Thus you can create visualization pipelines to read, process, and
construct textures. Note that textures will only work if texture
coordinates are also defined, and if the rendering system supports
texture.

Instances of vtkTexture are associated with actors via the actor’s
SetTexture() method. Actors can share texture maps (this is encouraged
to save memory resources.)

.SECTION Caveats

If six inputs are provided this texture will be treated as
a cube texture.

See Also

vtkProp
vtkRenderer

Methods

Repeat

Turn on/off the repetition of the texture map when the texture
coords extend beyond the [0,1] range.

EdgeCLamp

Turn on/off the clamping of the texture map when the texture
coords extend beyond the [0,1] range.
Only used when Repeat is off, and edge clamping is supported by
the graphics card.

Interpolate

Turn on/off linear interpolation of the texture map when rendering.

Source

index.js
import macro from 'vtk.js/Sources/macro';

// ----------------------------------------------------------------------------
// vtkTexture methods
// ----------------------------------------------------------------------------

function vtkTexture(publicAPI, model) {
// Set our className
model.classHierarchy.push('vtkTexture');

publicAPI.imageLoaded = () => {
model.image.removeEventListener('load', publicAPI.imageLoaded);
model.imageLoaded = true;
publicAPI.modified();
};

publicAPI.setImage = (image) => {
if (model.image === image) {
return;
}

if (image !== null) {
publicAPI.setInputData(null);
publicAPI.setInputConnection(null);
}

model.image = image;
model.imageLoaded = false;

if (image.complete) {
publicAPI.imageLoaded();
} else {
image.addEventListener('load', publicAPI.imageLoaded);
}

publicAPI.modified();
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
repeat: false,
interpolate: false,
edgeClamp: false,
image: null,
imageLoaded: false,
};

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

// Build VTK API
macro.obj(publicAPI, model);
macro.algo(publicAPI, model, 6, 0);

macro.get(publicAPI, model, ['imageLoaded']);

macro.setGet(publicAPI, model, [
'repeat',
'edgeClamp',
'interpolate',
'image',
]);

vtkTexture(publicAPI, model);
}

// ----------------------------------------------------------------------------

export const newInstance = macro.newInstance(extend, 'vtkTexture');

// ----------------------------------------------------------------------------

export default { newInstance, extend };