How to use the Material function from three

Find comprehensive JavaScript three.Material code examples handpicked from public code repositorys.

three.Material is a class in the Three.js library that defines the appearance and behavior of an object in a 3D scene.

20
21
22
23
24
25
26
27
28

SpriteCanvasMaterial.prototype.clone = function () {

        var material = new SpriteCanvasMaterial();

        THREE.Material.prototype.clone.call( this, material );

        material.color.copy( this.color );
        material.program = this.program;
fork icon185
star icon870
watch icon40

+ 29 other calls in file

16
17
18
19
20
21
22
23
24

        this.setValues( parameters );

};

THREE.SpriteCanvasMaterial.prototype = Object.create( THREE.Material.prototype );
THREE.SpriteCanvasMaterial.prototype.constructor = THREE.SpriteCanvasMaterial;

THREE.SpriteCanvasMaterial.prototype.clone = function () {
fork icon519
star icon3
watch icon0

+ 7 other calls in file

How does three.Material work?

In Three.js, Material is a class that defines the visual appearance of an object and how it interacts with light, which includes its color, shininess, transparency, and more. It provides a set of properties and methods that define how the object should be rendered on the screen.

430
431
432
433
434
435
436
437
438
439
440
441
442
443


	return material;


};


MeshLineMaterial.prototype = Object.create( THREE.Material.prototype );
MeshLineMaterial.prototype.constructor = MeshLineMaterial;


MeshLineMaterial.prototype.copy = function ( source ) {

fork icon397
star icon9
watch icon1

+ 3 other calls in file

1885
1886
1887
1888
1889
1890
1891
1892
1893

var pointsMaterial = this.cache.get(cacheKey);

if (!pointsMaterial) {
  pointsMaterial = new THREE.PointsMaterial();
  THREE.Material.prototype.copy.call(pointsMaterial, material);
  pointsMaterial.color.copy(material.color);
  pointsMaterial.map = material.map;
  pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
fork icon3
star icon7
watch icon0

+ 29 other calls in file

Ai Example

1
2
3
4
5
import * as THREE from "three";

const material = new THREE.MeshBasicMaterial({
  color: 0xff0000,
});

In this example, we use the Material class to create a new instance of MeshBasicMaterial, which is a type of material used to render basic geometries with flat shading. We pass an object containing options for the material, including the color of the material.

2923
2924
2925
2926
2927
2928
2929
2930
2931
let pointsMaterial = this.cache.get( cacheKey );

if ( ! pointsMaterial ) {

    pointsMaterial = new THREE.PointsMaterial();
    THREE.Material.prototype.copy.call( pointsMaterial, material );
    pointsMaterial.color.copy( material.color );
    pointsMaterial.map = material.map;
    pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
fork icon2
star icon10
watch icon0

+ 3 other calls in file

1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
else if (mesh.isLine) {
    const cacheKey = 'LineBasicMaterial:' + material.uuid;
    let lineMaterial = this.cache.get(cacheKey);
    if (!lineMaterial) {
        lineMaterial = new three.LineBasicMaterial();
        three.Material.prototype.copy.call(lineMaterial, material);
        lineMaterial.color.copy(material.color);
        this.cache.add(cacheKey, lineMaterial);
    }
    material = lineMaterial;
fork icon2
star icon7
watch icon0

75
76
77
78
79
80
81
82
83
84
scene.add(this.mesh);

this.currentPosition = new THREE.Vector3(0, 0, 0);

/* Add setOpacity method for the material */
THREE.Material.prototype.setOpacity =
function setOpacity(opacity, animationTime, callback) {
  function animate(material, countdown, v) {
    material.opacity += v;
    // material.nee
fork icon2
star icon6
watch icon6

2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
var pointsMaterial = this.cache.get(cacheKey);

if (!pointsMaterial) {
  pointsMaterial = new _three.PointsMaterial();

  _three.Material.prototype.copy.call(pointsMaterial, material);

  pointsMaterial.color.copy(material.color);
  pointsMaterial.map = material.map;
  pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
fork icon0
star icon1
watch icon0

+ 3 other calls in file

336
337
338
339
340
341
342
343
344
345
346
347
348
349


	return material;


};


THREE.MeshLineMaterial.prototype = Object.create( THREE.Material.prototype );
THREE.MeshLineMaterial.prototype.constructor = THREE.MeshLineMaterial;


THREE.MeshLineMaterial.prototype.copy = function ( source ) {

fork icon0
star icon0
watch icon1

+ 179 other calls in file

435
436
437
438
439
440
441
442
443
444
445
446
447
MeshLineMaterial.prototype = Object.create( THREE.Material.prototype );
MeshLineMaterial.prototype.constructor = MeshLineMaterial;


MeshLineMaterial.prototype.copy = function ( source ) {


  THREE.Material.prototype.copy.call( this, source );


  this.lineWidth = source.lineWidth;
  this.map = source.map;
  this.useMap = source.useMap;
fork icon0
star icon0
watch icon1

+ 398 other calls in file

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)