/** * This component makes the parentEntity (ex. car) follow the path provided by the spline * @param id String * @param name String * @param spline R3.D3.API.Spline * @param mesh R3.D3.API.Mesh * @param raytraceMesh R3.D3.API.Mesh * @param accelleration Number * @param maxSpeed Number * @param baseOffset R3.API.Vector * @param maxOffset R3.API.Vector * @param steeringSpeed Number * @param targetOffset R3.API.Vector3 * @param currentOffset R3.API.Vector3 * @param currentPathValue Number * @param currentSpeed Number * @param direction Number * @param raycaster R3.D3.Raycaster * @param currentPosition R3.API.Vector3 * @param futurePosition R3.API.Vector3 * @param up R3.API.Vector3 * @param rotationMatrix R3.API.Matrix4 * @param rotationVector R3.API.Quaternion * @param parentEntity * @constructor */ R3.D3.API.PathFollowing = function ( id, name, spline, mesh, raytraceMesh, accelleration, maxSpeed, baseOffset, maxOffset, steeringSpeed, targetOffset, currentOffset, currentPathValue, currentSpeed, direction, raycaster, currentPosition, futurePosition, up, rotationMatrix, rotationVector, parentEntity ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); } this.id = id; if (R3.Utils.UndefinedOrNull(name)) { name = this.constructor.name; } this.name = name; if (R3.Utils.UndefinedOrNull(spline)) { spline = null; } this.spline = spline; if (R3.Utils.UndefinedOrNull(mesh)) { mesh = null; } this.mesh = mesh; if (R3.Utils.UndefinedOrNull(raytraceMesh)) { raytraceMesh = null; } this.raytraceMesh = raytraceMesh; if (R3.Utils.UndefinedOrNull(maxSpeed)) { maxSpeed = 0.03; } this.maxSpeed = maxSpeed; if (R3.Utils.UndefinedOrNull(accelleration)) { accelleration = 0.1; } this.accelleration = accelleration; if (R3.Utils.UndefinedOrNull(baseOffset)) { baseOffset = new R3.API.Vector3(); } this.baseOffset = baseOffset; if (R3.Utils.UndefinedOrNull(maxOffset)) { maxOffset = new R3.API.Vector3(); } this.maxOffset = maxOffset; if (R3.Utils.UndefinedOrNull(steeringSpeed)) { steeringSpeed = 1.0; } this.steeringSpeed = steeringSpeed; if (R3.Utils.UndefinedOrNull(targetOffset)) { targetOffset = new R3.API.Vector3(); } this.targetOffset = targetOffset; if (R3.Utils.UndefinedOrNull(currentOffset)) { currentOffset = new R3.API.Vector3(); } this.currentOffset = currentOffset; if (R3.Utils.UndefinedOrNull(currentPathValue)) { currentPathValue = 0; } this.currentPathValue = currentPathValue; if (R3.Utils.UndefinedOrNull(currentSpeed)) { currentSpeed = 0; } this.currentSpeed = currentSpeed; if (R3.Utils.UndefinedOrNull(direction)) { direction = 1; } this.direction = direction; if (R3.Utils.UndefinedOrNull(raycaster)) { raycaster = new R3.D3.API.Raycaster(); } this.raycaster = raycaster; if (R3.Utils.UndefinedOrNull(currentPosition)) { currentPosition = new R3.API.Vector3(); } this.currentPosition = currentPosition; if (R3.Utils.UndefinedOrNull(futurePosition)) { futurePosition = new R3.API.Vector3(); } this.futurePosition = futurePosition; if(R3.Utils.UndefinedOrNull(up)) { up = new R3.API.Vector3(0, 1, 0); } this.up = up; if (R3.Utils.UndefinedOrNull(rotationMatrix)) { rotationMatrix = new R3.API.Matrix4(); } this.rotationMatrix = rotationMatrix; if (R3.Utils.UndefinedOrNull(rotationVector)) { rotationVector = new R3.API.Quaternion(); } this.rotationVector = rotationVector; if (R3.Utils.UndefinedOrNull(parentEntity)) { parentEntity = null; } this.parentEntity = parentEntity; }; R3.D3.API.PathFollowing.prototype = Object.create(R3.Component.prototype); R3.D3.API.PathFollowing.prototype.constructor = R3.D3.API.PathFollowing; /** * Returns an API path following component from an Object path following component * @param objectComponent * @constructor */ R3.D3.API.PathFollowing.FromObject = function(objectComponent) { var apiRaycaster = null; if (objectComponent.raycaster) { apiRaycaster = R3.D3.API.Raycaster.FromObject(objectComponent.raycaster); } return new R3.D3.API.PathFollowing( objectComponent.id, objectComponent.name, objectComponent.spline, objectComponent.mesh, objectComponent.raytraceMesh, objectComponent.accelleration, objectComponent.maxSpeed, R3.API.Vector3.FromObject(objectComponent.baseOffset), R3.API.Vector3.FromObject(objectComponent.maxOffset), objectComponent.steeringSpeed, R3.API.Vector3.FromObject(objectComponent.targetOffset), R3.API.Vector3.FromObject(objectComponent.currentOffset), objectComponent.currentPathValue, objectComponent.currentSpeed, objectComponent.direction, apiRaycaster, R3.API.Vector3.FromObject(objectComponent.currentPosition), R3.API.Vector3.FromObject(objectComponent.futurePosition), R3.API.Vector3.FromObject(objectComponent.up), R3.API.Matrix4.FromObject(objectComponent.rotationMatrix), R3.API.Quaternion.FromObject(objectComponent.rotationVector), objectComponent.parentEntity ); };