更新编译输出为es5支持老旧的浏览器

This commit is contained in:
ChenX
2018-06-06 17:23:22 +08:00
parent 256a7ea8a6
commit 29a6dd0fff
38 changed files with 616 additions and 533 deletions

120
dist/Viewer.js vendored
View File

@@ -1,33 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const _1 = require(".");
const CameraUpdate_1 = require("./CameraUpdate");
const ColorPalette_1 = require("./ColorPalette");
const GeUtils_1 = require("./GeUtils");
const PlaneExt_1 = require("./PlaneExt");
class Viewer {
var THREE = require("three");
var _1 = require(".");
var CameraUpdate_1 = require("./CameraUpdate");
var ColorPalette_1 = require("./ColorPalette");
var GeUtils_1 = require("./GeUtils");
var PlaneExt_1 = require("./PlaneExt");
var Viewer = /** @class */ (function () {
//构造
constructor(canvasContainer) {
function Viewer(canvasContainer) {
var _this = this;
this.m_Camera = new CameraUpdate_1.CameraUpdate();
this.m_bNeedUpdate = true;
this.m_Scene = new THREE.Scene();
this.OnSize = (width, height) => {
this._Width = width ? width : this.m_DomEl.clientWidth;
this._Height = height ? height : this.m_DomEl.clientHeight;
this.OnSize = function (width, height) {
_this._Width = width ? width : _this.m_DomEl.clientWidth;
_this._Height = height ? height : _this.m_DomEl.clientHeight;
//校验.成为2的倍数 避免外轮廓错误.
if (this._Width % 2 == 1)
this._Width -= 1;
if (this._Height % 2 == 1)
this._Height -= 1;
this.m_Render.setSize(this._Width, this._Height);
this.m_Camera.SetSize(this._Width, this._Height);
if (_this._Width % 2 == 1)
_this._Width -= 1;
if (_this._Height % 2 == 1)
_this._Height -= 1;
_this.m_Render.setSize(_this._Width, _this._Height);
_this.m_Camera.SetSize(_this._Width, _this._Height);
};
this.StartRender = () => {
requestAnimationFrame(this.StartRender);
if (this.m_Scene != null && this.m_bNeedUpdate) {
this.Render();
this.m_bNeedUpdate = false;
this.StartRender = function () {
requestAnimationFrame(_this.StartRender);
if (_this.m_Scene != null && _this.m_bNeedUpdate) {
_this.Render();
_this.m_bNeedUpdate = false;
}
};
this.m_DomEl = canvasContainer;
@@ -35,23 +36,23 @@ class Viewer {
this.OnSize();
this.StartRender();
new _1.CameraControls(this);
window.addEventListener("resize", () => {
this.OnSize();
window.addEventListener("resize", function () {
_this.OnSize();
});
let oldMesh;
this.m_Render.domElement.addEventListener("mousemove", (e) => {
let mesh = _1.PointPick(this, e.offsetX, e.offsetY);
var oldMesh;
this.m_Render.domElement.addEventListener("mousemove", function (e) {
var mesh = _1.PointPick(_this, e.offsetX, e.offsetY);
if (oldMesh)
oldMesh.material = _1.boardMaterial;
if (mesh && mesh.material !== ColorPalette_1.ColorMaterial.GetLineMaterial(1)) {
oldMesh = mesh;
mesh.material = _1.selectMaterial;
}
this.m_bNeedUpdate = true;
_this.m_bNeedUpdate = true;
});
}
//初始化render
initRender(canvasContainer) {
Viewer.prototype.initRender = function (canvasContainer) {
this.m_Render = new THREE.WebGLRenderer({
antialias: true,
precision: "highp",
@@ -72,69 +73,70 @@ class Viewer {
//设置它的背景色为黑色
this.m_Render.setClearColor(0xffffff, 1);
this.OnSize();
}
Render() {
};
Viewer.prototype.Render = function () {
this.m_Render.render(this.m_Scene, this.m_Camera.Camera);
}
ScreenToWorld(pt, planVec) {
};
Viewer.prototype.ScreenToWorld = function (pt, planVec) {
//变换和求交点
let plan = new PlaneExt_1.PlaneExt(planVec || new THREE.Vector3(0, 0, 1));
let raycaster = new THREE.Raycaster();
var plan = new PlaneExt_1.PlaneExt(planVec || new THREE.Vector3(0, 0, 1));
var raycaster = new THREE.Raycaster();
// 射线从相机射线向屏幕点位置
raycaster.setFromCamera({
x: (pt.x / this._Width) * 2 - 1,
y: -(pt.y / this._Height) * 2 + 1
}, this.m_Camera.Camera);
plan.intersectRay(raycaster.ray, pt, true);
}
WorldToScreen(pt) {
let widthHalf = this._Width * 0.5;
let heightHalf = this._Height * 0.5;
};
Viewer.prototype.WorldToScreen = function (pt) {
var widthHalf = this._Width * 0.5;
var heightHalf = this._Height * 0.5;
pt.project(this.m_Camera.Camera);
pt.x = (pt.x * widthHalf) + widthHalf;
pt.y = -(pt.y * heightHalf) + heightHalf;
}
};
/**
* 更新视角观测目标(物体中心)
*
* @memberof Viewer
*/
UpdateLockTarget() {
let renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_Camera.Camera);
let box = GeUtils_1.GetBoxArr(renderList.opaque.map(o => o.object));
Viewer.prototype.UpdateLockTarget = function () {
var renderList = this.m_Render.renderLists.get(this.m_Scene, this.m_Camera.Camera);
var box = GeUtils_1.GetBoxArr(renderList.opaque.map(function (o) { return o.object; }));
if (box)
this.m_LookTarget = box.getCenter(new THREE.Vector3());
else
this.m_LookTarget = GeUtils_1.cZeroVec;
}
Rotate(mouseMove) {
};
Viewer.prototype.Rotate = function (mouseMove) {
this.m_Camera.Rotate(mouseMove, this.m_LookTarget);
this.m_bNeedUpdate = true;
}
Pan(mouseMove) {
};
Viewer.prototype.Pan = function (mouseMove) {
this.m_Camera.Pan(mouseMove);
this.m_bNeedUpdate = true;
}
Zoom(scale, center) {
};
Viewer.prototype.Zoom = function (scale, center) {
this.m_Camera.Zoom(scale, center);
this.m_bNeedUpdate = true;
}
ZoomAll() {
};
Viewer.prototype.ZoomAll = function () {
this.m_Camera.ZoomExtensBox3(GeUtils_1.GetBox(this.m_Scene, true));
this.m_bNeedUpdate = true;
}
ViewToTop() {
};
Viewer.prototype.ViewToTop = function () {
this.m_Camera.LookAt(new THREE.Vector3(0, 0, -1));
this.m_bNeedUpdate = true;
}
ViewToFront() {
};
Viewer.prototype.ViewToFront = function () {
this.m_Camera.LookAt(new THREE.Vector3(0, 1, 0));
this.m_bNeedUpdate = true;
}
ViewToSwiso() {
};
Viewer.prototype.ViewToSwiso = function () {
this.m_Camera.LookAt(new THREE.Vector3(1, 1, -1));
this.m_bNeedUpdate = true;
}
}
};
return Viewer;
}());
exports.Viewer = Viewer;
//# sourceMappingURL=Viewer.js.map