import {EmphasisMaterial} from '@xeokit/xeokit-sdk/src/viewer/scene/materials/EmphasisMaterial.js'
EmphasisMaterial
Configures the appearance of Entitys when they are xrayed, highlighted or selected.
- XRay an Entity by setting Entity#xrayed
true
. - Highlight an Entity by setting Entity#highlighted
true
. - Select an Entity by setting Entity#selected
true
. - When Entitys are within the subtree of a root Entity, then setting Entity#xrayed, Entity#highlighted or Entity#selected on the root will collectively set those properties on all sub-Entitys.
- EmphasisMaterial provides several presets. Select a preset by setting EmphasisMaterial#preset to the ID of a preset in EmphasisMaterial#presets.
- By default, a Mesh uses the default EmphasisMaterials in Scene#xrayMaterial, Scene#highlightMaterial and Scene#selectedMaterial but you can assign each Mesh#xrayMaterial, Mesh#highlightMaterial or Mesh#selectedMaterial to a custom EmphasisMaterial, if required.
Usage
In the example below, we'll create a Mesh with its own XRayMaterial and set Mesh#xrayed true
to xray it.
Recall that Mesh is a concrete subtype of the abstract Entity base class.
new Mesh(viewer.scene, {
geometry: new BoxGeometry(viewer.scene, {
edgeThreshold: 1
}),
material: new PhongMaterial(viewer.scene, {
diffuse: [0.2, 0.2, 1.0]
}),
xrayMaterial: new EmphasisMaterial(viewer.scene, {
fill: true,
fillColor: [0, 0, 0],
fillAlpha: 0.7,
edges: true,
edgeColor: [0.2, 1.0, 0.2],
edgeAlpha: 1.0,
edgeWidth: 2
}),
xrayed: true
});
Note the edgeThreshold
configuration for the ReadableGeometry on our Mesh. EmphasisMaterial configures
a wireframe representation of the ReadableGeometry for the selected emphasis mode, which will have inner edges (those edges between
adjacent co-planar triangles) removed for visual clarity. The edgeThreshold
indicates that, for
this particular ReadableGeometry, an inner edge is one where the angle between the surface normals of adjacent triangles
is not greater than 5
degrees. That's set to 2
by default, but we can override it to tweak the effect
as needed for particular Geometries.
Here's the example again, this time implicitly defaulting to the Scene#edgeMaterial. We'll also modify that EdgeMaterial to customize the effect.
new Mesh({
geometry: new TeapotGeometry(viewer.scene, {
edgeThreshold: 5
}),
material: new PhongMaterial(viewer.scene, {
diffuse: [0.2, 0.2, 1.0]
}),
xrayed: true
});
var xrayMaterial = viewer.scene.xrayMaterial;
xrayMaterial.fillColor = [0.2, 1.0, 0.2];
xrayMaterial.fillAlpha = 1.0;
Presets
Let's switch the Scene#xrayMaterial to one of the presets in EmphasisMaterial#presets:
viewer.xrayMaterial.preset = EmphasisMaterial.presets["sepia"];
We can also create an EmphasisMaterial from a preset, while overriding properties of the preset as required:
var myEmphasisMaterial = new EMphasisMaterial(viewer.scene, {
preset: "sepia",
fillColor = [1.0, 0.5, 0.5]
});
Constructor Summary
Public Constructor | ||
public |
constructor(owner: Component, cfg: *) |
Member Summary
Public Members | ||
public set |
Sets whether to render backfaces when EmphasisMaterial#fill is |
|
public get |
Gets whether to render backfaces when EmphasisMaterial#fill is |
|
public set |
Sets the transparency of edges. |
|
public get |
Gets the transparency of edges. |
|
public set |
Sets the RGB color of edges. |
|
public get |
Gets the RGB color of edges. |
|
public set |
Sets edge width. |
|
public get |
Gets edge width. |
|
public set |
Sets if edges are visible. |
|
public get |
Gets if edges are visible. |
|
public set |
Sets if surfaces are filled with color. |
|
public get |
Gets if surfaces are filled with color. |
|
public set |
Sets the transparency of filled faces. |
|
public get |
Gets the transparency of filled faces. |
|
public set |
Sets the RGB color of filled faces. |
|
public get |
Gets the RGB color of filled faces. |
|
public set |
Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through". |
|
public get |
Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through". |
|
public set |
Selects a preset EmphasisMaterial configuration. |
|
public get |
Gets the current preset EmphasisMaterial configuration. |
|
public get |
Gets available EmphasisMaterial presets. |
Method Summary
Public Methods | ||
public |
destroy() Destroys this EmphasisMaterial. |
Inherited Summary
From class Component | ||
public get |
The Component that owns the lifecycle of this Component, if any. |
|
public |
True as soon as this Component has been destroyed |
|
public |
ID of this Component, unique within the Scene. |
|
public |
meta: * Arbitrary, user-defined metadata on this component. |
|
public |
The parent Scene that contains this Component. |
|
public |
The viewer that contains this Scene. |
|
public |
clear() Destroys all Components that are owned by this. |
|
public |
destroy() Destroys this component. |
|
public |
Logs an error for this component to the JavaScript console. |
|
public |
Fires an event on this component. |
|
public |
Returns true if there are any subscribers to the given event on this component. |
|
public |
Tests if this component is of the given type, or is a subclass of the given type. |
|
public |
Logs a console debugging message for this component. |
|
public |
Cancels an event subscription that was previously made with Component#on or Component#once. |
|
public |
Subscribes to an event on this component. |
|
public |
Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd. |
|
public |
scheduleTask(task: *) Schedule a task to perform on the next browser interval |
|
public |
Logs a warning for this component to the JavaScript console. |
From class Material | ||
public |
destroy() |
Public Constructors
public constructor(owner: Component, cfg: *) source
Override:
Material#constructorParams:
Name | Type | Attribute | Description |
owner | Component | Owner component. When destroyed, the owner will destroy this component as well. |
|
cfg | * |
|
The EmphasisMaterial configuration |
cfg.id | String |
|
Optional ID, unique among all components in the parent Scene, generated automatically when omitted. |
cfg.fill | Boolean |
|
Indicates if xray surfaces are filled with color. |
cfg.fillColor | Number[] |
|
EmphasisMaterial fill color. |
cfg.fillAlpha | Number |
|
Transparency of filled xray faces. A value of |
cfg.edges | Boolean |
|
Indicates if xray edges are visible. |
cfg.edgeColor | Number[] |
|
RGB color of xray edges. |
cfg.edgeAlpha | Number |
|
Transparency of xray edges. A value of |
cfg.edgeWidth | Number |
|
Width of xray edges, in pixels. |
cfg.preset | String |
|
Selects a preset EmphasisMaterial configuration - see EmphasisMaterial#presets. |
cfg.backfaces | Boolean |
|
Whether to render geometry backfaces when emphasising. |
cfg.glowThrough | Boolean |
|
Whether to make the emphasized object appear to float on top of other objects, as if it were "glowing through" them. |
Public Members
public set backfaces: Boolean source
Sets whether to render backfaces when EmphasisMaterial#fill is true
.
Default is false
.
public get backfaces: Boolean source
Gets whether to render backfaces when EmphasisMaterial#fill is true
.
Default is true
.
public set edgeAlpha: Number source
Sets the transparency of edges.
A value of 0.0
indicates fully transparent, 1.0
is fully opaque.
Default is 0.2
.
public get edgeAlpha: Number source
Gets the transparency of edges.
A value of 0.0
indicates fully transparent, 1.0
is fully opaque.
Default is 0.2
.
public set edgeWidth: Number source
Sets edge width.
This is not supported by WebGL implementations based on DirectX [2019].
Default value is 1.0
pixels.
public get edgeWidth: Number source
Gets edge width.
This is not supported by WebGL implementations based on DirectX [2019].
Default value is 1.0
pixels.
public set fillAlpha: Number source
Sets the transparency of filled faces.
A value of 0.0
indicates fully transparent, 1.0
is fully opaque.
Default is 0.2
.
public get fillAlpha: Number source
Gets the transparency of filled faces.
A value of 0.0
indicates fully transparent, 1.0
is fully opaque.
Default is 0.2
.
public set fillColor: Number[] source
Sets the RGB color of filled faces.
Default is [0.4, 0.4, 0.4]
.
public get fillColor: Number[] source
Gets the RGB color of filled faces.
Default is [0.4, 0.4, 0.4]
.
public set glowThrough: Boolean source
Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through".
Default is true
.
Note: updating this property will not affect the appearance of objects that are already emphasized.
public get glowThrough: Boolean source
Sets whether to render emphasized objects over the top of other objects, as if they were "glowing through".
Default is true
.
public set preset: String source
Selects a preset EmphasisMaterial configuration.
Default value is "default".