rotateToRef function non existent

I was trying to use this function for a Vector2D object but I am getting ‘undefined’ error. It appears this function is described in the official Babylon documentation but is not included in the final package. Am I missing something?

Hello and welcome!
can you share some code so we can have a look?

I am trying to convert an involute gear script written for JSModeler I created years ago. I am not much of a programer but I experiment with 3d design and coding. Here is the snippet I’m working on:

		// build a single 2d tooth in the 'points' array
		var resolution = 10;
		var points = [new BABYLON.Vector2(0,0)];

		for(var i = 0; i <= resolution; i++)
		{
			// first side of the tooth
			var angle = maxangle * i / resolution;
			var tanlength = angle * baseRadius;
			var radvector = BABYLON.Vector2.rotateToRef(angle, radvector);
			var tanvector = radvector.normalize();
			var p = radvector.times(baseRadius).plus(tanvector.times(tanlength));
			points[i+1] = p;
			// opposite side of the tooth
			radvector = BABYLON.Vector2.fromAngle(angularToothWidthAtBase - angle, radvector);
			tanvector = radvector.normalize().negate();
			p = radvector.times(baseRadius).plus(tanvector.times(tanlength));
			points[2 * resolution + 2 - i] = p;
		}

Web inspector returns an error code that rotateToRef is not a function.

I think you need to use .rotateToRef() as a method of an existing Vector2 instance.

from = new BABYLON.Vector2()
result = new BABYLON.Vector2()
from.rotateToRef(1.57, result)

Static methods, in contrast, are capitalized in BJS.

2 Likes

Tested the code. I am still getting an error code.

TypeError: from.rotateToRef is not a function. (In 'from.rotateToRef(2, result)', 'from.rotateToRef' is undefined)

Logging the object in web inspector reveals that the method does not exist.

Vector2 | Babylon.js Documentation will be helpful:

.times() is .scale()
.plus() is .add()
.fromAngle() : not sure but perhaps rotate a (1,0) vector by angle, or just .Vector2(cos(a),sin(a))
.normalize() is .normalize()
.negate() is .negate()

1 Like

In your case you may want something like:

var radvector = new BABYLON.Vector2();
var fromVector = new BABYLON.Vector2(1, 0);
fromVector.rotateToRef(angle, radvector);

I am still getting undefined error. It seems like the method should appear in the object inspector console under ‘normalize()’, but I can’t find it. I will try something else. Thanks for your help.

Ah, I noticed BJS 4.2.0 does not have it. It seems the method was introduced by v 5.0 .

Here is a basic PG:
https://playground.babylonjs.com/#9TBCWB#1

1 Like

Thank you! Do you have a link to the latest alpha release so I can plug it into my project?

https://preview.babylonjs.com/babylon.js