|
@@ -0,0 +1,128 @@
|
|
|
+import * as THREE from "three";
|
|
|
+
|
|
|
+
|
|
|
+export const radarEffectClass = {
|
|
|
+ constructor(options) {
|
|
|
+ this.webgl = options.webgl;
|
|
|
+ this.view = options.view;
|
|
|
+ this.points = options.points;
|
|
|
+ this._camera = null;
|
|
|
+
|
|
|
+ },
|
|
|
+ initialize() {
|
|
|
+ this.clock = new THREE.Clock();
|
|
|
+
|
|
|
+ this.renderer = new THREE.WebGLRenderer({
|
|
|
+ context: this.gl,
|
|
|
+ premultipliedAlpha: false,
|
|
|
+ });
|
|
|
+ this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
|
+ this.renderer.setViewport(0, 0, this.view.width, this.view.height);
|
|
|
+
|
|
|
+ this.renderer.autoClear = false;
|
|
|
+ this.renderer.autoClearDepth = false;
|
|
|
+ this.renderer.autoClearColor = false;
|
|
|
+
|
|
|
+
|
|
|
+ let originalSetRenderTarget = this.renderer.setRenderTarget.bind(this.renderer);
|
|
|
+ this.renderer.setRenderTarget = function (target) {
|
|
|
+ originalSetRenderTarget(target);
|
|
|
+ if (target == null) {
|
|
|
+ context.bindRenderTarget();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ this.scene = new THREE.Scene();
|
|
|
+
|
|
|
+ let cam = this.camera;
|
|
|
+ this._camera = new THREE.PerspectiveCamera(cam.fovY, cam.aspect, cam.near, cam.far);
|
|
|
+
|
|
|
+
|
|
|
+ const axesHelper = new THREE.AxesHelper(1);
|
|
|
+ axesHelper.position.copy(1000000, 100000, 100000);
|
|
|
+ this.scene.add(axesHelper);
|
|
|
+
|
|
|
+ let grid = new THREE.GridHelper(30, 10, 0xf0f0f0, 0xffffff);
|
|
|
+ this.scene.add(grid);
|
|
|
+
|
|
|
+
|
|
|
+ this.ambient = new THREE.AmbientLight(0xffffff, 0.5);
|
|
|
+ this.scene.add(this.ambient);
|
|
|
+
|
|
|
+ this.sun = new THREE.DirectionalLight(0xffffff, 0.5);
|
|
|
+ this.sun.position.set(-600, 300, 60000);
|
|
|
+ this.scene.add(this.sun);
|
|
|
+ this.getGeometry();
|
|
|
+
|
|
|
+
|
|
|
+ this.resetWebGLState();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getGeometry() {
|
|
|
+ this.points.forEach(point => {
|
|
|
+ let pointGround = {
|
|
|
+ type: "point",
|
|
|
+ x: point[0],
|
|
|
+ y: point[1],
|
|
|
+ z: 1,
|
|
|
+ viewH: 3000,
|
|
|
+ };
|
|
|
+ let pointSky = {
|
|
|
+ type: "point",
|
|
|
+ x: point[0],
|
|
|
+ y: point[1],
|
|
|
+ z: 10,
|
|
|
+ }
|
|
|
+ const mixedPoints = [
|
|
|
+ pointGround.x, pointGround.y, pointGround.z,
|
|
|
+ pointSky.x, pointSky.y, pointSky.z,
|
|
|
+ ]
|
|
|
+ let cenP = [];
|
|
|
+ this.webgl.toRenderCoordinates(
|
|
|
+ this.view,
|
|
|
+ mixedPoints,
|
|
|
+ 0,
|
|
|
+ this.view.spatialReference,
|
|
|
+ cenP,
|
|
|
+ 0,
|
|
|
+ 1
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * 渲染器更新渲染
|
|
|
+ * @memberof BuildingEffect
|
|
|
+ * @method render
|
|
|
+ * @param {Object} context 已有渲染器信息,无需传值
|
|
|
+ */
|
|
|
+ render(context) {
|
|
|
+ let cam = this.camera;
|
|
|
+
|
|
|
+ this._camera.position.set(cam.eye[0], cam.eye[1], cam.eye[2]);
|
|
|
+ this._camera.up.set(cam.up[0], cam.up[1], cam.up[2]);
|
|
|
+ this._camera.lookAt(new THREE.Vector3(cam.center[0], cam.center[1], cam.center[2]));
|
|
|
+
|
|
|
+ this._camera.projectionMatrix.fromArray(cam.projectionMatrix);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.renderer.state.reset();
|
|
|
+
|
|
|
+ this.bindRenderTarget();
|
|
|
+
|
|
|
+ this.renderer.render(this.scene, this._camera);
|
|
|
+
|
|
|
+ this.requestRender();
|
|
|
+
|
|
|
+
|
|
|
+ this.resetWebGLState();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|