Property

Introduction

vtkProperty is an object that represents lighting and other surface
properties of a geometric object. The primary properties that can be set are
colors (overall, ambient, diffuse, specular, and edge color); specular power;
opacity of the object; the representation of the object (points, wireframe,
or surface); and the shading method to be used (flat, Gouraud, and Phong).
Also, some special graphics features like backface properties can be set and
manipulated with this object.

Methods

addShaderVariable

Not Implemented yet

computeCompositeColor

Not Implemented yet

extend

Method use to decorate a given object (publicAPI+model) with vtkProperty characteristics.

Argument Type Required Description
publicAPI Yes object on which methods will be bounds (public)
model Yes object on which data structure will be bounds (protected)
initialValues IPropertyInitialValues No (default: {})

getAmbient

Get the lighting coefficient.

getAmbientColor

Get the ambient surface color. Not all renderers support separate ambient
and diffuse colors. From a physical standpoint it really doesn’t make too
much sense to have both. For the rendering libraries that don’t support
both, the diffuse color is used.

getAmbientColorByReference

Get the ambient surface color.

getAmbientOcclusionTexture

Get the ambient occlusion texture.

getBackfaceCulling

getBaseIOR

Get the index of refraction.

getColor

Get the color of the object.the color of the object

getDiffuse

Get the diffuse lighting coefficient.

getDiffuseColor

Get the diffuse surface color.

getDiffuseColorByReference

getDiffuseTexture

Get the diffuse texture.

getEdgeColor

getEdgeColorByReference

getEdgeVisibility

getEmission

Get the emission coefficient.

getEmissionTexture

Get the emission texture.

getFrontfaceCulling

Get the fast culling of polygons based on orientation of normal
with respect to camera. If frontface culling is on, polygons facing
towards camera are not drawn.

getInterpolation

Get the shading interpolation method for an object.

getInterpolationAsString

Map the interpolation integer to the corresponding ShadingModel.

getLighting

Get lighting flag for an object.

getLineWidth

Get the width of a Line. The width is expressed in screen units.

getMetallic

Get the metallic coefficient.

getMetallicTexture

Get the metallic texture.

getNormalStrength

Get the strength of the normal map.

getNormalTexture

Get the normal texture.

getOpacity

Get the opacity of the object. Set/Get the object’s opacity.
1.0 is totally opaque and 0.0 is completely transparent.

getPointSize

Get the diameter of a point. The size is expressed in screen units.

getRepresentation

Get the surface geometry representation for the object.

getRepresentationAsString

Get the surface geometry representation for the object as string.

getRoughness

Get the roughness coefficient.

getRoughnessTexture

Get the roughness texture.

getSpecular

Get the specular lighting coefficient.

getSpecularColor

Get the specular surface color.

getSpecularColorByReference

Get the specular surface color.

getSpecularPower

Get the specular power.

newInstance

Method use to create a new instance of vtkProperty with object color, ambient color, diffuse color,
specular color, and edge color white; ambient coefficient=0; diffuse
coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
and surface representation. Backface and frontface culling are off.

Argument Type Required Description
initialValues IPropertyInitialValues No for pre-setting some of its content

setAmbient

Set the ambient lighting coefficient.

Argument Type Required Description
ambient Number Yes The ambient lighting coefficient.

setAmbientColor

Set the ambient surface color. Not all renderers support separate
ambient and diffuse colors. From a physical standpoint it really
doesn’t make too much sense to have both. For the rendering
libraries that don’t support both, the diffuse color is used.

Argument Type Required Description
ambientColor RGBColor Yes An Array of the RGB color.

setAmbientColor

Set the ambient surface color. Not all renderers support separate
ambient and diffuse colors. From a physical standpoint it really
doesn’t make too much sense to have both. For the rendering
libraries that don’t support both, the diffuse color is used.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1)
g Number Yes Defines the green component (between 0 and 1)
b Number Yes Defines the blue component (between 0 and 1)

setAmbientColorFrom

Set the ambient surface color from an RGB array

Argument Type Required Description
ambientColor RGBColor Yes An Array of the RGB color.

setAmbientOcclusionTexture

Set the ambient occlusion texture.

Argument Type Required Description
ambientOcclusionTexture vtkTexture Yes

setBackfaceCulling

Turn on/off fast culling of polygons based on orientation of normal
with respect to camera. If backface culling is on, polygons facing
away from camera are not drawn.

Argument Type Required Description
backfaceCulling Boolean Yes

setColor

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

Argument Type Required Description
color RGBColor Yes An Array of the RGB color.

setColor

Set the color of the object. Has the side effect of setting the
ambient diffuse and specular colors as well. This is basically
a quick overall color setting method.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1)
g Number Yes Defines the green component (between 0 and 1)
b Number Yes Defines the blue component (between 0 and 1)

setDiffuse

Set the diffuse lighting coefficient.

Argument Type Required Description
diffuse Number Yes The diffuse lighting coefficient.

setDiffuseColor

Set the diffuse surface color.

Argument Type Required Description
diffuseColor RGBColor Yes An Array of the RGB color.

setDiffuseColor

Set the diffuse surface color.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1)
g Number Yes Defines the green component (between 0 and 1)
b Number Yes Defines the blue component (between 0 and 1)

setDiffuseColorFrom

Set the diffuse surface color from an RGB array

Argument Type Required Description
diffuseColor RGBColor Yes An Array of the RGB color.

setDiffuseTexture

Set the diffuse texture.

Argument Type Required Description
diffuseTexture vtkTexture Yes

setEdgeColor

Set the color of primitive edges (if edge visibility is enabled).

Argument Type Required Description
edgeColor RGBColor Yes An Array of the RGB color.

setEdgeColor

Set the color of primitive edges (if edge visibility is enabled).

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1)
g Number Yes Defines the green component (between 0 and 1)
b Number Yes Defines the blue component (between 0 and 1)

setEdgeColorFrom

Set the color of primitive edges from an RGB array.

Argument Type Required Description
edgeColor RGBColor Yes An Array of the RGB color.

setEdgeVisibility

Turn on/off the visibility of edges. On some renderers it is
possible to render the edges of geometric primitives separately
from the interior.

Argument Type Required Description
edgeVisibility Boolean Yes

setEmission

Set the ambient occlusion map strength.

Argument Type Required Description
emission Boolean Yes

setEmissionTexture

Set the emission texture.

Argument Type Required Description
emissionTexture vtkTexture Yes

setFrontfaceCulling

Turn on/off fast culling of polygons based on orientation of normal
with respect to camera. If frontface culling is on, polygons facing
towards camera are not drawn.

Argument Type Required Description
frontfaceCulling Boolean Yes

setInterpolation

Set the shading interpolation method for an object.

Argument Type Required Description
interpolation Interpolation Yes

setInterpolationToFlat

Set interpolation to 0 means FLAT.

setInterpolationToGouraud

Set interpolation to 1 means GOURAUD.

setInterpolationToPhong

Set interpolation to 2 means PHONG.

setLighting

Set lighting flag for an object.

Argument Type Required Description
lighting Boolean Yes

setLineWidth

Set the width of a Line. The width is expressed in screen units.
!!! note
This is only implemented for OpenGL.

Argument Type Required Description
lineWidth Number Yes

setMetallicTexture

Set the metallic texture.

Argument Type Required Description
metallicTexture vtkTexture Yes

setNormalStrength

Set the normal map strength.

Argument Type Required Description
normal Boolean Yes

setNormalTexture

Set the normal texture.

Argument Type Required Description
normalTexture vtkTexture Yes

setOpacity

Set the object’s opacity. 1.0 is totally opaque and 0.0 is
completely transparent.

Argument Type Required Description
opacity Number Yes The opacity of the object.

setPointSize

Set the diameter of a point. The size is expressed in screen units.
!!! note
This is only implemented for OpenGL.

Argument Type Required Description
pointSize Number Yes

setRepresentation

Control the surface geometry representation for the object.

Argument Type Required Description
representation Representation Yes

setRepresentationToPoints

Set representation to 0 means POINT

setRepresentationToSurface

Set representation to 2 means SURFAC

setRepresentationToWireframe

Set representation to 1 means WIREFRAM

setRoughnessTexture

Set the roughness texture.

Argument Type Required Description
roughnessTexture vtkTexture Yes

setSpecular

Set the specular lighting coefficient.

Argument Type Required Description
specular Boolean Yes

setSpecularColor

Set the specular surface color from an RGB array

Argument Type Required Description
specularColor RGBColor Yes An Array of the RGB color.

setSpecularColor

Set the specular surface color.

Argument Type Required Description
r Number Yes Defines the red component (between 0 and 1)
g Number Yes Defines the green component (between 0 and 1)
b Number Yes Defines the blue component (between 0 and 1)

setSpecularColorFrom

Set the specular surface color from an RGB array

Argument Type Required Description
specularColor RGBColor Yes An Array of the RGB color.

setSpecularPower

Set the specular power.

Argument Type Required Description
specularPower Number Yes

Source

Constants.d.ts
export declare enum Shading {
FLAT = 0,
GOURAUD = 1,
PHONG = 2,
}

export declare enum Representation {
POINTS = 0,
WIREFRAME = 1,
SURFACE = 2,
}

export declare enum Interpolation {
FLAT = 0,
GOURAUD = 1,
PHONG = 2,
}

declare const _default: {
Shading: typeof Shading;
Representation: typeof Representation;
Interpolation: typeof Interpolation;
};
export default _default;
Constants.js
export const Shading = {
FLAT: 0,
GOURAUD: 1,
PHONG: 2,
};

export const Representation = {
POINTS: 0,
WIREFRAME: 1,
SURFACE: 2,
};

export const Interpolation = Shading;

export default {
Shading,
Representation,
Interpolation,
};
index.d.ts
import { vtkObject } from '../../../interfaces';
import { RGBColor } from '../../../types';
import { Interpolation, Representation, Shading } from './Constants';
import { vtkTexture } from '../../Core/Texture';

export interface IPropertyInitialValues {
color?: RGBColor;
ambientColor?: RGBColor;
diffuseColor?: RGBColor;
specularColor?: RGBColor;
diffuseTexture?: vtkTexture;
metallicTexture?: vtkTexture;
roughnessTexture?: vtkTexture;
normalTexture?: vtkTexture;
ambientOcclusionTexture?: vtkTexture;
emissionTexture?: vtkTexture;
edgeColor?: RGBColor;
ambient?: number;
diffuse?: number;
metallic?: number;
roughness?: number;
normalStrength?: number;
emission?: number;
baseIOR?: number;
specular?: number;
specularPower?: number;
opacity?: number;
edgeVisibility?: boolean;
backfaceCulling?: boolean;
frontfaceCulling?: boolean;
pointSize?: number;
lineWidth?: number;
lighting?: boolean;
shading?: boolean;
}

export interface vtkProperty extends vtkObject {
/**
* Not Implemented yet
*/
addShaderVariable(): any;

/**
* Not Implemented yet
*/
computeCompositeColor(): any;

/**
* Get the lighting coefficient.
* @default 0
*/
getAmbient(): number;

/**
* Get the ambient surface color. Not all renderers support separate ambient
* and diffuse colors. From a physical standpoint it really doesn't make too
* much sense to have both. For the rendering libraries that don't support
* both, the diffuse color is used.
* @return {RGBColor} Array of RGB color.
*/
getAmbientColor(): RGBColor;

/**
* Get the ambient surface color.
*/
getAmbientColorByReference(): RGBColor;

/**
*
*/
getBackfaceCulling(): boolean;

/**
* Get the color of the object.the color of the object
*/
getColor(): RGBColor;

/**
* Get the diffuse lighting coefficient.
* @default 1
*/
getDiffuse(): number;

/**
* Get the diffuse surface color.
* @return {RGBColor} Array of RGB color.
*/
getDiffuseColor(): RGBColor;
/**
*
*/
getDiffuseColorByReference(): RGBColor;

/**
*
*/
getEdgeColor(): RGBColor;

/**
*
*/
getEdgeColorByReference(): RGBColor;

/**
*
*/
getEdgeVisibility(): boolean;

/**
* Get the fast culling of polygons based on orientation of normal
* with respect to camera. If frontface culling is on, polygons facing
* towards camera are not drawn.
* @default false
*/
getFrontfaceCulling(): boolean;

/**
* Get the shading interpolation method for an object.
*/
getInterpolation(): Interpolation;

/**
* Map the interpolation integer to the corresponding ShadingModel.
*/
getInterpolationAsString(): string;

/**
* Get lighting flag for an object.
* @default true
*/
getLighting(): boolean;

/**
* Get the width of a Line. The width is expressed in screen units.
* @default 1.0
*/
getLineWidth(): number;

/**
* Get the opacity of the object. Set/Get the object's opacity.
* 1.0 is totally opaque and 0.0 is completely transparent.
* @default 1
*/
getOpacity(): number;

/**
* Get the diameter of a point. The size is expressed in screen units.
* @default 1.0
*/
getPointSize(): number;

/**
* Get the surface geometry representation for the object.
*/
getRepresentation(): Representation;

/**
* Get the surface geometry representation for the object as string.
* @return {String} Surface geometry representation for the object as string
*/
getRepresentationAsString(): string;

/**
* Get the specular lighting coefficient.
* @default 0
*/
getSpecular(): number;

/**
* Get the roughness coefficient.
* @default 1
*/
getRoughness(): number;

/**
* Get the metallic coefficient.
* @default 0
*/
getMetallic(): number;

/**
* Get the index of refraction.
* @default 0
*/
getBaseIOR(): number;

/**
* Get the strength of the normal map.
* @default 1
*/
getNormalStrength(): number;

/**
* Get the emission coefficient.
* @default 0
*/
getEmission(): number;

/**
* Get the specular surface color.
* @return {RGBColor} Array of RGB color.
*/
getSpecularColor(): RGBColor;

/**
* Get the specular surface color.
*/
getSpecularColorByReference(): RGBColor;

/**
* Get the specular power.
* @default 1
*/
getSpecularPower(): number;

/**
* Get the diffuse texture.
*/
getDiffuseTexture(): vtkTexture;

/**
* Get the metallic texture.
*/
getMetallicTexture(): vtkTexture;

/**
* Get the roughness texture.
*/
getRoughnessTexture(): vtkTexture;

/**
* Get the normal texture.
*/
getNormalTexture(): vtkTexture;

/**
* Get the ambient occlusion texture.
*/
getAmbientOcclusionTexture(): vtkTexture;

/**
* Get the emission texture.
*/
getEmissionTexture(): vtkTexture;

/**
* Set the ambient lighting coefficient.
* @param {Number} ambient The ambient lighting coefficient.
*/
setAmbient(ambient: number): boolean;

/**
* Set the ambient surface color. Not all renderers support separate
* ambient and diffuse colors. From a physical standpoint it really
* doesn't make too much sense to have both. For the rendering
* libraries that don’t support both, the diffuse color is used.
*
* @param {Number} r Defines the red component (between 0 and 1)
* @param {Number} g Defines the green component (between 0 and 1)
* @param {Number} b Defines the blue component (between 0 and 1)
*/
setAmbientColor(r: number, g: number, b: number): boolean;

/**
* Set the ambient surface color. Not all renderers support separate
* ambient and diffuse colors. From a physical standpoint it really
* doesn't make too much sense to have both. For the rendering
* libraries that don’t support both, the diffuse color is used.
* @param {RGBColor} ambientColor An Array of the RGB color.
*/
setAmbientColor(ambientColor: RGBColor): boolean;

/**
* Set the ambient surface color from an RGB array
* @param {RGBColor} ambientColor An Array of the RGB color.
*/
setAmbientColorFrom(ambientColor: RGBColor): boolean;

/**
* Turn on/off fast culling of polygons based on orientation of normal
* with respect to camera. If backface culling is on, polygons facing
* away from camera are not drawn.
* @param {Boolean} backfaceCulling
*/
setBackfaceCulling(backfaceCulling: boolean): boolean;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @param {Number} r Defines the red component (between 0 and 1)
* @param {Number} g Defines the green component (between 0 and 1)
* @param {Number} b Defines the blue component (between 0 and 1)
*/
setColor(r: number, g: number, b: number): boolean;

/**
* Set the color of the object. Has the side effect of setting the
* ambient diffuse and specular colors as well. This is basically
* a quick overall color setting method.
* @param {RGBColor} color An Array of the RGB color.
*/
setColor(color: RGBColor): boolean;

/**
* Set the diffuse lighting coefficient.
* @param {Number} diffuse The diffuse lighting coefficient.
*/
setDiffuse(diffuse: number): boolean;

/**
* Set the diffuse surface color.
* @param {Number} r Defines the red component (between 0 and 1)
* @param {Number} g Defines the green component (between 0 and 1)
* @param {Number} b Defines the blue component (between 0 and 1)
*/
setDiffuseColor(r: number, g: number, b: number): boolean;

/**
* Set the diffuse surface color.
* @param {RGBColor} diffuseColor An Array of the RGB color.
*/
setDiffuseColor(diffuseColor: RGBColor): boolean;

/**
* Set the diffuse surface color from an RGB array
* @param {RGBColor} diffuseColor An Array of the RGB color.
*/
setDiffuseColorFrom(diffuseColor: RGBColor): boolean;

/**
* Set the color of primitive edges (if edge visibility is enabled).
* @param {Number} r Defines the red component (between 0 and 1)
* @param {Number} g Defines the green component (between 0 and 1)
* @param {Number} b Defines the blue component (between 0 and 1)
*/
setEdgeColor(r: number, g: number, b: number): boolean;

/**
* Set the color of primitive edges (if edge visibility is enabled).
* @param {RGBColor} edgeColor An Array of the RGB color.
*/
setEdgeColor(edgeColor: RGBColor): boolean;

/**
* Set the color of primitive edges from an RGB array.
* @param {RGBColor} edgeColor An Array of the RGB color.
*/
setEdgeColorFrom(edgeColor: RGBColor): boolean;

/**
* Turn on/off the visibility of edges. On some renderers it is
* possible to render the edges of geometric primitives separately
* from the interior.
* @param {Boolean} edgeVisibility
*/
setEdgeVisibility(edgeVisibility: boolean): boolean;

/**
* Turn on/off fast culling of polygons based on orientation of normal
* with respect to camera. If frontface culling is on, polygons facing
* towards camera are not drawn.
* @param {Boolean} frontfaceCulling
*/
setFrontfaceCulling(frontfaceCulling: boolean): boolean;

/**
* Set the shading interpolation method for an object.
* @param {Interpolation} interpolation
*/
setInterpolation(interpolation: Interpolation): boolean;

/**
* Set interpolation to 0 means `FLAT`.
*/
setInterpolationToFlat(): boolean;

/**
* Set interpolation to 1 means `GOURAUD`.
*/
setInterpolationToGouraud(): boolean;

/**
* Set interpolation to 2 means `PHONG`.
*/
setInterpolationToPhong(): boolean;

/**
* Set lighting flag for an object.
* @param {Boolean} lighting
* @default true
*/
setLighting(lighting: boolean): boolean;

/**
* Set the width of a Line. The width is expressed in screen units.
* !!! note
* This is only implemented for OpenGL.
* @param {Number} lineWidth
* @default 1.0
*/
setLineWidth(lineWidth: number): boolean;

/**
* Set the object's opacity. 1.0 is totally opaque and 0.0 is
* completely transparent.
* @param {Number} opacity The opacity of the object.
*/
setOpacity(opacity: number): boolean;

/**
* Set the diameter of a point. The size is expressed in screen units.
* !!! note
* This is only implemented for OpenGL.
* @param {Number} pointSize
* @default 1.0
*/
setPointSize(pointSize: number): boolean;

/**
* Control the surface geometry representation for the object.
* @param {Representation} representation
*/
setRepresentation(representation: Representation): boolean;

/**
* Set representation to 0 means `POINT`'
*/
setRepresentationToPoints(): boolean;

/**
* Set representation to 2 means `SURFAC`'
*/
setRepresentationToSurface(): boolean;

/**
* Set representation to 1 means `WIREFRAM`'
*/
setRepresentationToWireframe(): boolean;

/**
* Set the specular lighting coefficient.
* @param {Boolean} specular
*/
setSpecular(specular: number): boolean;

/**
* Set the normal map strength.
* @param {Boolean} normal
*/
setNormalStrength(normalStrength: number): boolean;

/**
* Set the ambient occlusion map strength.
* @param {Boolean} emission
*/
setEmission(emission: number): boolean;

/**
* Set the specular surface color.
* @param {Number} r Defines the red component (between 0 and 1)
* @param {Number} g Defines the green component (between 0 and 1)
* @param {Number} b Defines the blue component (between 0 and 1)
*/
setSpecularColor(r: number, g: number, b: number): boolean;

/**
* Set the specular surface color from an RGB array
* @param {RGBColor} specularColor An Array of the RGB color.
*/
setSpecularColor(specularColor: RGBColor): boolean;

/**
* Set the specular surface color from an RGB array
* @param {RGBColor} specularColor An Array of the RGB color.
*/
setSpecularColorFrom(specularColor: RGBColor): boolean;

/**
* Set the specular power.
* @param {Number} specularPower
*/
setSpecularPower(specularPower: number): boolean;

/**
* Set the diffuse texture.
* @param {vtkTexture} diffuseTexture
*/
setDiffuseTexture(diffuseTexture: vtkTexture): boolean;

/**
* Set the metallic texture.
* @param {vtkTexture} metallicTexture
*/
setMetallicTexture(metallicTexture: vtkTexture): boolean;

/**
* Set the roughness texture.
* @param {vtkTexture} roughnessTexture
*/
setRoughnessTexture(roughnessTexture: vtkTexture): boolean;

/**
* Set the normal texture.
* @param {vtkTexture} normalTexture
*/
setNormalTexture(normalTexture: vtkTexture): boolean;

/**
* Set the ambient occlusion texture.
* @param {vtkTexture} ambientOcclusionTexture
*/
setAmbientOcclusionTexture(ambientOcclusionTexture: vtkTexture): boolean;

/**
* Set the emission texture.
* @param {vtkTexture} emissionTexture
*/
setEmissionTexture(emissionTexture: vtkTexture): boolean;
}

/**
* Method use to decorate a given object (publicAPI+model) with vtkProperty characteristics.
*
* @param publicAPI object on which methods will be bounds (public)
* @param model object on which data structure will be bounds (protected)
* @param {IPropertyInitialValues} [initialValues] (default: {})
*/
export function extend(
publicAPI: object,
model: object,
initialValues?: IPropertyInitialValues
): void;

/**
* Method use to create a new instance of vtkProperty with object color, ambient color, diffuse color,
* specular color, and edge color white; ambient coefficient=0; diffuse
* coefficient=0; specular coefficient=0; specular power=1; Gouraud shading;
* and surface representation. Backface and frontface culling are off.
* @param {IPropertyInitialValues} [initialValues] for pre-setting some of its content
*/
export function newInstance(
initialValues?: IPropertyInitialValues
): vtkProperty;

/**
* vtkProperty is an object that represents lighting and other surface
* properties of a geometric object. The primary properties that can be set are
* colors (overall, ambient, diffuse, specular, and edge color); specular power;
* opacity of the object; the representation of the object (points, wireframe,
* or surface); and the shading method to be used (flat, Gouraud, and Phong).
* Also, some special graphics features like backface properties can be set and
* manipulated with this object.
*/
export declare const vtkProperty: {
newInstance: typeof newInstance;
extend: typeof extend;
Shading: typeof Shading;
Representation: typeof Representation;
Interpolation: typeof Interpolation;
};
export default vtkProperty;
index.js
import macro from 'vtk.js/Sources/macros';
import Constants from 'vtk.js/Sources/Rendering/Core/Property/Constants';

const { Representation, Interpolation } = Constants;

function notImplemented(method) {
return () => macro.vtkErrorMacro(`vtkProperty::${method} - NOT IMPLEMENTED`);
}

// ----------------------------------------------------------------------------
// vtkProperty methods
// ----------------------------------------------------------------------------

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

publicAPI.setColor = (r, g, b) => {
if (Array.isArray(r)) {
if (
model.color[0] !== r[0] ||
model.color[1] !== r[1] ||
model.color[2] !== r[2]
) {
model.color[0] = r[0];
model.color[1] = r[1];
model.color[2] = r[2];
publicAPI.modified();
}
} else if (
model.color[0] !== r ||
model.color[1] !== g ||
model.color[2] !== b
) {
model.color[0] = r;
model.color[1] = g;
model.color[2] = b;
publicAPI.modified();
}

publicAPI.setDiffuseColor(model.color);
publicAPI.setAmbientColor(model.color);
publicAPI.setSpecularColor(model.color);
};

publicAPI.computeCompositeColor = notImplemented('ComputeCompositeColor');
publicAPI.getColor = () => {
// Inline computeCompositeColor
let norm = 0.0;
if (model.ambient + model.diffuse + model.specular > 0) {
norm = 1.0 / (model.ambient + model.diffuse + model.specular);
}

for (let i = 0; i < 3; i++) {
model.color[i] =
norm *
(model.ambient * model.ambientColor[i] +
model.diffuse * model.diffuseColor[i] +
model.specular * model.specularColor[i]);
}

return [].concat(model.color);
};

publicAPI.setSpecularPower = (specularPower) => {
const roughness = 1 / Math.max(1.0, specularPower);
if (
model.roughness !== roughness ||
model.specularPower !== specularPower
) {
model.specularPower = specularPower; // Specular power still needs to be set as long as webgl is using it (otherwise testShaderReplacementsClear fails)
model.roughness = roughness;
publicAPI.modified();
}
};

publicAPI.addShaderVariable = notImplemented('AddShaderVariable');

publicAPI.setInterpolationToFlat = () =>
publicAPI.setInterpolation(Interpolation.FLAT);
publicAPI.setInterpolationToGouraud = () =>
publicAPI.setInterpolation(Interpolation.GOURAUD);
publicAPI.setInterpolationToPhong = () =>
publicAPI.setInterpolation(Interpolation.PHONG);
publicAPI.getInterpolationAsString = () =>
macro.enumToString(Interpolation, model.interpolation);

publicAPI.setRepresentationToWireframe = () =>
publicAPI.setRepresentation(Representation.WIREFRAME);
publicAPI.setRepresentationToSurface = () =>
publicAPI.setRepresentation(Representation.SURFACE);
publicAPI.setRepresentationToPoints = () =>
publicAPI.setRepresentation(Representation.POINTS);
publicAPI.getRepresentationAsString = () =>
macro.enumToString(Representation, model.representation);
}

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

const DEFAULT_VALUES = {
color: [1, 1, 1],
ambientColor: [1, 1, 1],
diffuseColor: [1, 1, 1],
specularColor: [1, 1, 1],
edgeColor: [0, 0, 0],

ambient: 0,
diffuse: 1,
metallic: 0,
roughness: 0.6,
normalStrength: 1,
emission: 1,
baseIOR: 1.45,
specular: 0,
specularPower: 1,
opacity: 1,
interpolation: Interpolation.GOURAUD,
representation: Representation.SURFACE,
edgeVisibility: false,
backfaceCulling: false,
frontfaceCulling: false,
pointSize: 1,
lineWidth: 1,
lighting: true,

shading: false,
materialName: null,
};

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

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

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

macro.setGet(publicAPI, model, [
'lighting',
'interpolation',
'ambient',
'diffuse',
'metallic',
'roughness',
'normalStrength',
'emission',
'baseIOR',
'specular',
'specularPower',
'opacity',
'edgeVisibility',
'lineWidth',
'pointSize',
'backfaceCulling',
'frontfaceCulling',
'representation',
'diffuseTexture',
'metallicTexture',
'roughnessTexture',
'normalTexture',
'ambientOcclusionTexture',
'emissionTexture',
]);
macro.setGetArray(
publicAPI,
model,
['ambientColor', 'specularColor', 'diffuseColor', 'edgeColor'],
3
);

// Object methods
vtkProperty(publicAPI, model);
}

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

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

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

export default { newInstance, extend, ...Constants };