Methods¶
The 270 Customiser plugin adds the following methods to the Viewer.
Use the el.getObjectNames()
method to see the available objects to pass in these methods
getColor¶
Get current color of object as a hexstring, or css rgb value and returns it as a string.
el.getColor({name: 'Base', rgb: true});
Parameters:
- name: Type:
string
The name of the Object - rgb:
- Type:
Boolean
- Default:
false
When true, returns the color as ancss rgb
value instead of ahexidecimal
value.
- Type:
hideObject¶
Hides or shows the passed object.
Identical to showObject({ name: 'Base', visible: false, render: true })
.
Automatically calls ME.setShadow()
to update the shadow.
el.hideObject({name: 'Base', visible: true, render: true });
Parameters:
- name: Type:
string
The name of the Object - visible:
- Type:
Boolean
- Default:
true
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider setting this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
scaleTexture¶
Scale the passed Object3Ds texture to the passed factor.
A scaled texture will force the
offset
totrue
.
el.scaleTexture({name: 'Base', scale: 0.5, render: true});
Parameters:
- name: Type:
string
The name of the Object - scale: Type:
Float
Factor to scale the texture to. - render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
setColor¶
Set color of passed Object's material and automatically render a new frame (optional).
el.setColor({name: 'Base', color: '#ff0000', render: true});
Parameters:
- name: Type:
string
The name of the Object - color:
- Type:
hexidecimal string
|css value
The color to set. Both hexidecimals (#ffffff
) or valid css values (white
,rgb(255,255,255)
) are allowed.
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider setting this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
setText¶
Write text on the passed Object.
Can be used as a promise.
el.setText({name: 'Base', text: 'Hello world', color: '#ff0000', size: 128, render: true}).then(() => { /* callback */ });
Parameters:
- name: Type:
string
The name of the Object - text: Type:
string
The text to add - color:
- Type:
hexidecimal string
|css value
- Default:
#000000
The color of the text. Both hexidecimals (#ffffff
) or valid css values (white
,rgb(255,255,255)
) are allowed.
- Type:
- background:
- Type:
hexidecimal string
|css value
- Default:
current material color
The color of the background. Both hexidecimals (#ffffff
) or valid css values (white
,rgb(255,255,255)
) are allowed.
Ignored whentransparent
is set totrue
.
- Type:
- transparent:
- Type:
Boolean
- Default:
current material's transparency
Adds transparency as the background.
- Type:
- font:
- Type:
string
- Default:
sans-serif
The font used to write the text with.When using a custom font, make sure that the font file is loaded and used.
- Type:
- size:
- Type:
integer
- Default:
128
The size of the text, in pixels.While fontsize is an absolute value, it will have different results depending on the Objects texture size. So a size of 128 might look smaller or bigger going from one Object to another.
- Type:
- fontStyle:
- Type:
string
- Default:
normal
Apply a css font style to the text. Options arenormal
,italic
,oblique
.
- Type:
- fontWeight:
- Type:
string
- Default:
normal
Apply a css font weight to the text. Options arelighter
,light
,normal
,bold
,bolder
.
- Type:
- retina:
- Type:
Boolean
- Default:
true
Upscales the font for sharper rendering. Recommended in most cases.
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
setTexture¶
Map the passed image on the Object. Image source can be a HTMLImage, HTMLCanvas, Base64 or uri string.
Can be used as a promise.
el.setTexture({name: 'Base', source: document.querySelector('#image'), background: '#ff0000', scale: 'contain'}).then(() => { /* callback */ });
Parameters:
- name: Type:
string
The name of the Object - source: Type:
HTMLNode
|string
The image source to add. Image source can be a HTMLImage, HTMLCanvas, Base64 or uri string. - background:
- Type:
string
- Default:
current material color
The color of the background when thesource
contains transparency. Both hexidecimals (#ffffff
) or valid css values (white
,rgb(255,255,255)
) are allowed.
Ignored whentransparent
is set totrue
.
- Type:
- transparent:
- Type:
Boolean
- Default:
current material's transparency
Render transparent pixels from thesource
as transparent.
- Type:
- scale:
- Type:
string
|Float
- Default:
fit
The scaling method used on the image, or the scale factor:fit
scales the image dimensions to the texture dimensions.contain
scales the image as large as possible within its container without cropping or stretching the image.cover
scales the image (while preserving its ratio) to the smallest possible size to fill the container (that is: both its height and width completely cover the container), leaving no empty space.none
keeps the intrinsic image dimensions.Float
scales the texture to the passed factor.Passing a Float forces the scaling method to
contain
, andoffset
totrue
.
- Type:
- offset:
- Type:
Boolean
- Default:
false
Adds a safe border around the image to prevent anti-alias smearing. This is typically needed if the Object UV size does not match passed image.
- Type:
- retina:
- Type:
Boolean
- Default:
false
Upscales the image for sharper rendering, but at a performance cost. It is recommended to only use this when needed.
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
setVariant¶
Applies the passed variant to the loaded Asset or Object and optionally renders a new frame.
A variant is a preconfigured set of colors and/or materials, available in the loaded Asset.
Can be used as a promise.
el.setVariant({name: 'plane', variant: 'leather', render: true}).then(() => { /* callback */ })
Parameters:
- name: Type:
string
The name of the Object - variant: Type:
string
The name of the desired variant. UsegetVariants()
to find the available variants. - render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider setting this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
showObject¶
Shows or hides the passed Object.
Identical to hideObject({ name: 'Base', visible: false, render: true })
.
Automatically calls ME.setShadow()
to update the shadow.
el.showObject({ name: 'Base', visible: true, render: true });
Parameters:
- name: Type:
string
The name of the Object - visible:
- Type:
Boolean
- Default:
true
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
removeText¶
Removes any text set on passed Object.
el.removeText({name: 'Base', render: true});
Parameters:
- name: Type:
string
The name of the Object - render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type:
removeTexture¶
Removes any image set on passed Object. The Object's base color will remain as is.
el.removeTexture({name: 'Base', render: true});
Parameters:
- name: Type:
string
The name of the Object - transparent:
- Type:
Boolean
- Default:
current material's transparency
Forces transparency on the material after texture has been removed.false
will render the material as white opaque.
- Type:
- render:
- Type:
Boolean
- Default:
true
Immediately renders a new frame whentrue
. If you are changing multiple items in the Viewer, consider settings this tofalse
and callrequestRender()
manually to prevent unneeded frames.
- Type: