After a little work around it worked out. Thank you.
For those who need it, this is the script
var MouseInput = pc.createScript('mouseInput');
MouseInput.attributes.add('orbitSensitivity', {
type: 'number',
default: 0.3,
title: 'Orbit Sensitivity',
description: 'How fast the camera moves around the orbit. Higher is faster'
});
MouseInput.attributes.add('distanceSensitivity', {
type: 'number',
default: 0.15,
title: 'Distance Sensitivity',
description: 'How fast the camera moves in and out. Higher is faster'
});
// initialize code called once per entity
MouseInput.prototype.initialize = function() {
this.cameraController = this.entity.script.cameraController;
this.addEvents();
this.on('destroy', function() {
this.removeEvents();
}, this);
this.on('enable', function() {
this.addEvents();
}, this);
this.on('disable', function() {
this.removeEvents();
}, this);
if (this.cameraController) {
var self = this;
var onMouseOut = function (e) {
self.onMouseOut(e);
};
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.on(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);
// Listen to when the mouse travels out of the window
window.addEventListener('mouseout', onMouseOut, false);
}
// Disabling the context menu stops the browser displaying a menu when
// you right-click the page
this.app.mouse.disableContextMenu();
this.lookButtonDown = false;
this.lastPoint = new pc.Vec2();
};
MouseInput.fromWorldPoint = new pc.Vec3();
MouseInput.toWorldPoint = new pc.Vec3();
MouseInput.worldDiff = new pc.Vec3();
MouseInput.prototype.onMouseDown = function (event) {
switch (event.button) {
case pc.MOUSEBUTTON_LEFT: {
this.lookButtonDown = true;
} break;
case pc.MOUSEBUTTON_MIDDLE:
case pc.MOUSEBUTTON_RIGHT: {
this.panButtonDown = true;
} break;
}
};
MouseInput.prototype.onMouseUp = function (event) {
switch (event.button) {
case pc.MOUSEBUTTON_LEFT: {
this.lookButtonDown = false;
} break;
}
};
MouseInput.prototype.onMouseMove = function (event) {
var mouse = pc.app.mouse;
if (this.lookButtonDown) {
this.cameraController.pitch -= event.dy * this.orbitSensitivity;
this.cameraController.yaw -= event.dx * this.orbitSensitivity;
}
this.lastPoint.set(event.x, event.y);
};
MouseInput.prototype.onMouseWheel = function (event) {
this.cameraController.distance -= event.wheel * this.distanceSensitivity * (this.cameraController.distance * 0.1);
event.event.preventDefault();
};
MouseInput.prototype.onMouseOut = function (event) {
this.lookButtonDown = false;
};
MouseInput.prototype.addEvents = function() {
this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.on(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);
};
MouseInput.prototype.removeEvents = function() {
this.app.mouse.off(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
this.app.mouse.off(pc.EVENT_MOUSEUP, this.onMouseUp, this);
this.app.mouse.off(pc.EVENT_MOUSEMOVE, this.onMouseMove, this);
this.app.mouse.off(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this);
};