three#CanvasTexture JavaScript Examples
The following examples show how to use
three#CanvasTexture.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Defaults.js From three-mesh-ui with MIT License | 6 votes |
function makeBackgroundTexture() {
if ( !defaultBgTexture ) {
const ctx = document.createElement( 'canvas' ).getContext( '2d' );
ctx.canvas.width = 1;
ctx.canvas.height = 1;
ctx.fillStyle = '#ffffff';
ctx.fillRect( 0, 0, 1, 1 );
defaultBgTexture = new CanvasTexture( ctx.canvas );
defaultBgTexture.isDefault = true;
}
return defaultBgTexture;
}
Example #2
Source File: AnimatedTextureAtlas.js From webmc with MIT License | 6 votes |
constructor (game) {
this.game = game
this.atlasCreator = new TextureAtlasCreator({
textureX: this.game.al.get('blocksAtlasFull'),
textureMapping: this.game.al.get('blocksMappingFull')
})
const canvas = this.atlasCreator.gen(0)
const texture = new CanvasTexture(canvas)
texture.magFilter = NearestFilter
texture.minFilter = NearestMipmapLinearFilter
this.material = new MeshStandardMaterial({
side: 0,
map: texture,
vertexColors: true,
transparent: true,
alphaTest: 0.1
})
}
Example #3
Source File: item.js From architect3d with MIT License | 4 votes |
/**
* Constructs an item.
*
* @param model
* TODO
* @param metadata
* TODO
* @param geometry
* TODO
* @param material
* TODO
* @param position
* TODO
* @param rotation
* TODO
* @param scale
* TODO
*/
constructor(model, metadata, geometry, material, position, rotation, scale, isgltf=false)
{
super();
this.model = model;
this.metadata = metadata;
/** */
this.errorGlow = new Mesh();
/** */
this.hover = false;
/** */
this.selected = false;
/** */
this.highlighted = false;
/** */
this.error = false;
/** */
this.emissiveColor = 0x444444;
/** Does this object affect other floor items */
this.obstructFloorMoves = true;
/** */
this.position_set = false;
/** Show rotate option in context menu */
this.allowRotate = true;
/** */
this.fixed = false;
/** dragging */
this.dragOffset = new Vector3();
/** */
this.halfSize = new Vector3(0,0,0);
this.bhelper = null;
this.scene = this.model.scene;
this._freePosition = true;
if(!isgltf)
{
this.geometry = geometry;
this.material = material;
// center in its boundingbox
this.geometry.computeBoundingBox();
this.geometry.applyMatrix(new Matrix4().makeTranslation(- 0.5 * (this.geometry.boundingBox.max.x + this.geometry.boundingBox.min.x),- 0.5 * (this.geometry.boundingBox.max.y + this.geometry.boundingBox.min.y),- 0.5 * (this.geometry.boundingBox.max.z + this.geometry.boundingBox.min.z)));
this.geometry.computeBoundingBox();
}
else
{
var objectBox = new Box3();
objectBox.setFromObject(geometry);
var hsize = objectBox.max.clone().sub(objectBox.min).multiplyScalar(0.5);
this.geometry = new BoxGeometry(hsize.x*0.5, hsize.y*0.5, hsize.z*0.5);
this.material = new MeshStandardMaterial({color: 0x000000, wireframe: true, visible:false});
this.geometry.computeBoundingBox();
this.add(geometry);
}
if(!this.material.color)
{
this.material.color = new Color('#FFFFFF');
}
this.wirematerial = new MeshBasicMaterial({color: 0x000000, wireframe: true});
this.errorColor = 0xff0000;
this.resizable = metadata.resizable;
this.castShadow = true;
this.receiveShadow = false;
this.originalmaterial = material;
this.texture = this.material.texture;
this.position_set = false;
if (position)
{
this.position.copy(position);
this.position_set = true;
}
this.halfSize = this.objectHalfSize();
this.canvasWH = document.createElement('canvas');
this.canvasWH.width = this.getWidth()+1.0;
this.canvasWH.height = this.getHeight()+1.0;
this.canvascontextWH = this.canvasWH.getContext('2d');
this.canvasTextureWH = new CanvasTexture(this.canvasWH);
this.canvasMaterialWH = new MeshBasicMaterial({map:this.canvasTextureWH, side: DoubleSide, transparent:true});
this.canvasPlaneWH = new Mesh(new PlaneGeometry(this.getWidth(), this.getHeight(), 1, 1), this.canvasMaterialWH);
this.canvasPlaneWH.scale.set(1, 1, 1);
this.canvasPlaneWH.position.set(0, 0, this.getDepth()*0.5 + 0.3);
this.canvasWD = document.createElement('canvas');
this.canvasWD.width = this.getWidth()+1.0;
this.canvasWD.height = this.getDepth()+1.0;
this.canvascontextWD = this.canvasWD.getContext('2d');
this.canvasTextureWD = new CanvasTexture(this.canvasWD);
this.canvasMaterialWD = new MeshBasicMaterial({map:this.canvasTextureWD, side: DoubleSide, transparent:true});
this.canvasPlaneWD = new Mesh(new PlaneGeometry(this.getWidth(), this.getDepth(), 1, 1), this.canvasMaterialWD);
this.canvasPlaneWD.rotateX(-Math.PI * 0.5);
this.canvasPlaneWD.scale.set(1, 1, 1);
this.canvasPlaneWD.position.set(0, this.getHeight()*0.5 + 0.3, 0);
this.canvasPlaneWH.visible = this.canvasPlaneWD.visible = false;
this.add(this.canvasPlaneWH);
this.add(this.canvasPlaneWD);
this.resizeProportionally = true;
if (rotation)
{
this.rotation.y = rotation;
}
if (scale != null)
{
this.setScale(scale.x, scale.y, scale.z);
}
if(this.metadata.materialColors)
{
if(this.metadata.materialColors.length)
{
if(this.material.length)
{
for (var i=0;i<this.metadata.materialColors.length;i++)
{
this.material[i].color = new Color(this.metadata.materialColors[i]);
}
}
else
{
this.material.color = new Color(this.metadata.materialColors[0]);
}
}
}
}