How to use the Matrix4 function from three

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

114
115
116
117
118
119
120
121
122
123
_clipBox = new THREE.Box3( new THREE.Vector3( - 1, - 1, - 1 ), new THREE.Vector3( 1, 1, 1 ) ),
_boundingBox = new THREE.Box3(),
_points3 = new Array( 3 ),
_points4 = new Array( 4 ),

_viewMatrix = new THREE.Matrix4(),
_viewProjectionMatrix = new THREE.Matrix4(),

_modelMatrix,
_modelViewProjectionMatrix = new THREE.Matrix4(),
fork icon185
star icon867
watch icon40

+ 32 other calls in file

23
24
25
26
27
28
29
30
31
32
config.head_color = typeof (config.head_color) !== 'undefined' ? config.head_color : 255;
config.use_head = typeof (config.use_head) !== 'undefined' ? config.use_head : true;
config.head_size = config.head_size || 1.0;
config.line_width = config.line_width || 0.01;

const modelMatrix = new THREE.Matrix4();
const originColor = new THREE.Color(config.origin_color);
const headColor = new THREE.Color(config.head_color);
const vectors = config.vectors.data;
const origins = config.origins.data;
fork icon119
star icon813
watch icon25

+ 3 other calls in file

52
53
54
55
56
57
58
59
60
61
if (object.geometry.attributes.sizes) {
    threshold = object.geometry.attributes.sizes.array[triangleIndex] / 2.0;
}

if (object.isInstancedMesh) {
    let matrix = new THREE.Matrix4().fromArray(object.instanceMatrix.array, triangleIndex * 16);
    threshold = matrix.getMaxScaleOnAxis() / 2.0;
}

localThreshold = threshold / ((object.scale.x + object.scale.y + object.scale.z) / 3);
fork icon119
star icon813
watch icon25

+ 3 other calls in file

181
182
183
184
185
186
187
188
189
190
} else {
    axis.set(direction.z, 0, -direction.x).normalize();
    quaternion = new THREE.Quaternion().setFromAxisAngle(axis, Math.acos(direction.y));
}

coneGeometry.applyMatrix4(new THREE.Matrix4().makeRotationFromQuaternion(quaternion));
coneGeometry.translate(destination.x, destination.y, destination.z);

if (!heads) {
    heads = [coneGeometry];
fork icon117
star icon808
watch icon24

+ 4 other calls in file

121
122
123
124
125
126
127
128
129
130
for (i = 0; i < positions.length / 3; i++) {
    const s = (sizes && sizes[i]) || 1.0;

    object.setMatrixAt(
        i,
        (new THREE.Matrix4())
            .identity()
            .setPosition(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2])
            .scale(new THREE.Vector3(s, s, s)),
    );
fork icon115
star icon803
watch icon0

+ 5 other calls in file

1
2
3
4
5
6
7
8
9
10
11
12
const { Pathfinding } = require('../');
const test = require('tape');


const EPS = 1e-5;
const ZONE = 'level';
const ROTATE = new THREE.Matrix4()
  .makeRotationAxis(new THREE.Vector3(1, 0, 0), Math.PI / 2);


test('initialize', (t) => {
  t.ok(Pathfinding, 'module loads');
fork icon109
star icon888
watch icon0

+ 3 other calls in file

698
699
700
701
702
703
704
705
706
707
}
applyScaleNode() {
    this.geometry.computeBoundingBox();
    const box = this.geometry.boundingBox.clone();
    const center = box.getCenter(new three.Vector3());
    const matrix = new three.Matrix4();
    matrix.compose(new three.Vector3(-center.x, -center.y, -center.z), new three.Quaternion(), new three.Vector3(UnitsUtils.EARTH_RADIUS, UnitsUtils.EARTH_RADIUS, UnitsUtils.EARTH_RADIUS));
    this.geometry.applyMatrix4(matrix);
    this.position.copy(center);
    this.updateMatrix();
fork icon75
star icon468
watch icon0

+ 3 other calls in file

58
59
60
61
62
63
64
65
66
    this.mesh.rotation.y = Math.PI;

    this.scene.add(this.mesh);

    geometry = new THREE.BoxGeometry(0.75, 0.75, 1);
    geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,-0.5));

    this.point = new THREE.Mesh(geometry);
}
fork icon40
star icon163
watch icon13

692
693
694
695
696
697
698
699
700
701
this.fromCamera.updateMatrix(); // make sure camera's local matrix is updated
this.fromCamera.updateMatrixWorld(); // make sure camera's world matrix is updated
this.fromCamera.matrixWorldInverse.getInverse( this.fromCamera.matrixWorld );

var frustum = new THREE.Frustum();
frustum.setFromMatrix( new THREE.Matrix4().multiplyMatrices(this.fromCamera.projectionMatrix, 
															this.fromCamera.matrixWorldInverse ) );

for (var i = 0, il = this.points.length ; i < il ; i ++) {
	var p = this.points[i];
fork icon13
star icon110
watch icon0

75
76
77
78
79
80
81
82
83
84
	this.dimension.width,
	this.dimension.height,
	this.dimension.depth
);
geometry.applyMatrix(
	new THREE.Matrix4().makeTranslation(
		this.dimension.width / 2,
		this.dimension.height / 2,
		this.dimension.depth / 2
	)
fork icon147
star icon53
watch icon0

77
78
79
80
81
82
83
84
85
86
  thickness = thickness || 0;
  const edgeLength = thickness + 1.0;
  const xAxis = this.vertices[1].clone().sub(this.vertices[0]);
  const yAxis = this.vertices[2].clone().sub(this.vertices[0]);
  const zAxis = this.vertices[3].clone().sub(this.vertices[0]);
  return new THREE.Matrix4()
    .makeBasis(xAxis, yAxis, zAxis)
    .scale(new THREE.Vector3(edgeLength, edgeLength, edgeLength))
    .setPosition(this.vertices[0].clone().multiplyScalar(2.0).add(xAxis).add(yAxis).add(zAxis).divideScalar(2.0));
}
fork icon12
star icon50
watch icon10

+ 31 other calls in file

88
89
90
91
92
93
94
95
96
97
                    poleDir.z,localUp.z,cross.z,cameraPosition.z,
                    0,0,0,1);

    this.camera.matrixAutoUpdate = false;

    var cameraPlace = new THREE.Matrix4();
cameraPlace.makeTranslation ( 0, curCamHeight * scope.scale * .8, curCamZoom * scope.scale * .8)

var cameraRot = new THREE.Matrix4();
cameraRot.makeRotationX(-0.32 - (playerPosition.length()/1200));
fork icon15
star icon47
watch icon10

+ 19 other calls in file

24
25
26
27
28
29
30
31
32
33
THREE.Object3D.call(this);

vrDisplay = State.get('vrDisplay');

this.gamepadVive;
this.standingMatrix = new THREE.Matrix4();
this.lastPressed = false;
this.lastButton2Pressed = false;

this.active = false;
fork icon10
star icon33
watch icon0

43
44
45
46
47
48
49
50
51
52

    this.scene.setListenerFromMatrix(this.listenerMatrix);
}

_getMatrix4({euler, location, matrix4}) {
    const _matrix4 = matrix4 || new THREE.Matrix4();

    if(euler) {
        const _euler = new THREE.Euler();
        _euler.copy(euler);
fork icon8
star icon36
watch icon0

10
11
12
13
14
15
16
17
18
19

const __tmpDir3 = new THREE.Vector3();
const __tmpQuaternion = new THREE.Vector3();
const __tmpPos3 = new THREE.Vector3();
const __tmpNormalMatrix = new THREE.Matrix3();
const __tmpRotationMatrix = new THREE.Matrix4();
const __tmpNormal = new THREE.Vector3();

const States = {
  Default: 0,
fork icon4
star icon25
watch icon2

+ 11 other calls in file

1007
1008
1009
1010
1011
1012
1013
1014
1015

var tempVector = new THREE.Vector3( 0, 0, 0 );
var tempEuler = new THREE.Euler();
var alignVector = new THREE.Vector3( 0, 1, 0 );
var zeroVector = new THREE.Vector3( 0, 0, 0 );
var lookAtMatrix = new THREE.Matrix4();
var tempQuaternion = new THREE.Quaternion();
var tempQuaternion2 = new THREE.Quaternion();
var identityQuaternion = new THREE.Quaternion();
fork icon4
star icon26
watch icon0

2788
2789
2790
2791
2792
2793
2794
2795
2796
2797

if (nodeDef.extensions)
  addUnknownExtensionsToUserData(extensions, node, nodeDef);

if (nodeDef.matrix !== undefined) {
  var matrix = new THREE.Matrix4();
  matrix.fromArray(nodeDef.matrix);
  node.applyMatrix(matrix);
} else {
  if (nodeDef.translation !== undefined) {
fork icon3
star icon7
watch icon8

+ 29 other calls in file

28
29
30
31
32
33
34
35
36
37
let repeat_mode = "NONE";
this.ready = false;
let morphColours = false;
let morphVertices = false;
this.isGlyphset = true;
let _transformMatrix = new THREE.Matrix4();
const _bot_colour = new THREE.Color();
const _top_colour = new THREE.Color();
const _boundingBox1 = new THREE.Box3();
const _boundingBox2 = new THREE.Box3();
fork icon10
star icon3
watch icon3

+ 9 other calls in file

386
387
388
389
390
391
392
393
394
395
imesh.instanceMatrix.needsUpdate = true;

this.scene.add(imesh);

let bondGeometry = new THREE.CylinderGeometry(.4, 0.4, 1.0, 6, 4, true);
bondGeometry.applyMatrix4(new THREE.Matrix4().makeRotationX(3.1415/2.0));


let bondMesh = new THREE.InstancedMesh( bondGeometry, material, 10000);
bondMesh.count = this.bonds.length;
fork icon3
star icon7
watch icon0

+ 14 other calls in file

287
288
289
290
291
292
293
294
295
// Make the geometry (of "direction" length)
//material.roughness = 0.2;
//material.metalness = 0.2;
//var geometry = new THREE.CylinderGeometry(.4, 0.4, direction.length(), 6, 4, true);
// shift it so one end rests on the origin
//geometry.applyMatrix4(new THREE.Matrix4().makeTranslation(0, direction.length() / 2, 0));
//geometry.position = new THREE.Vector3( .5*(pY[0]+ pX[0]), .5*(pY[1]+ pX[1]), .5*(pY[2]+ pX[2]));


fork icon3
star icon7
watch icon0

+ 15 other calls in file

Other functions in three

Sorted by popularity

function icon

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