mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
Added AxisEntity
This commit is contained in:
parent
4ce0b5bf92
commit
cddd7ce582
@ -71,7 +71,8 @@
|
|||||||
Object3d,
|
Object3d,
|
||||||
EmptyTerrain,
|
EmptyTerrain,
|
||||||
Mat4,
|
Mat4,
|
||||||
Vec3
|
Vec3,
|
||||||
|
AxisEntity
|
||||||
} from "../../lib/@openglobus/og.esm.js";
|
} from "../../lib/@openglobus/og.esm.js";
|
||||||
|
|
||||||
|
|
||||||
@ -92,89 +93,98 @@
|
|||||||
|
|
||||||
function setPitch(a) {
|
function setPitch(a) {
|
||||||
axesLayer.each((e) => {
|
axesLayer.each((e) => {
|
||||||
let line = e.childrenNodes[0];
|
|
||||||
let tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setPitch(a);
|
|
||||||
tip.geoObject.setPitch(a);
|
|
||||||
|
|
||||||
line = e.childrenNodes[1];
|
e.setPitch(a);
|
||||||
tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setPitch(a);
|
|
||||||
tip.geoObject.setPitch(a);
|
|
||||||
|
|
||||||
line = e.childrenNodes[2];
|
// let line = e.childrenNodes[0];
|
||||||
tip = line.childrenNodes[0];
|
// let tip = line.childrenNodes[0];
|
||||||
line.geoObject.setPitch(a + 90);
|
// line.geoObject.setPitch(a);
|
||||||
tip.geoObject.setPitch(a + 90);
|
// tip.geoObject.setPitch(a);
|
||||||
|
//
|
||||||
|
// line = e.childrenNodes[1];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setPitch(a);
|
||||||
|
// tip.geoObject.setPitch(a);
|
||||||
|
//
|
||||||
|
// line = e.childrenNodes[2];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setPitch(a + 90);
|
||||||
|
// tip.geoObject.setPitch(a + 90);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setYaw(a) {
|
function setYaw(a) {
|
||||||
axesLayer.each((e) => {
|
axesLayer.each((e) => {
|
||||||
let line = e.childrenNodes[0];
|
|
||||||
let tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setYaw(a);
|
|
||||||
tip.geoObject.setYaw(a);
|
|
||||||
|
|
||||||
line = e.childrenNodes[1];
|
e.setYaw(a);
|
||||||
tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setYaw(a);
|
|
||||||
tip.geoObject.setYaw(a);
|
|
||||||
|
|
||||||
line = e.childrenNodes[2];
|
// let line = e.childrenNodes[0];
|
||||||
tip = line.childrenNodes[0];
|
// let tip = line.childrenNodes[0];
|
||||||
line.geoObject.setYaw(a);
|
// line.geoObject.setYaw(a);
|
||||||
tip.geoObject.setYaw(a);
|
// tip.geoObject.setYaw(a);
|
||||||
|
//
|
||||||
|
// line = e.childrenNodes[1];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setYaw(a);
|
||||||
|
// tip.geoObject.setYaw(a);
|
||||||
|
//
|
||||||
|
// line = e.childrenNodes[2];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setYaw(a);
|
||||||
|
// tip.geoObject.setYaw(a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRoll(a) {
|
function setRoll(a) {
|
||||||
axesLayer.each((e) => {
|
axesLayer.each((e) => {
|
||||||
let line = e.childrenNodes[0];
|
|
||||||
let tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setRoll(a + 90);
|
|
||||||
tip.geoObject.setRoll(a + 90);
|
|
||||||
|
|
||||||
line = e.childrenNodes[1];
|
e.setRoll(a);
|
||||||
tip = line.childrenNodes[0];
|
|
||||||
line.geoObject.setRoll(a);
|
// let line = e.childrenNodes[0];
|
||||||
tip.geoObject.setRoll(a);
|
// let tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setRoll(a + 90);
|
||||||
|
// tip.geoObject.setRoll(a + 90);
|
||||||
|
//
|
||||||
|
// line = e.childrenNodes[1];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
|
// line.geoObject.setRoll(a);
|
||||||
|
// tip.geoObject.setRoll(a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
|
||||||
const SCALE = 0.1;
|
// const SCALE = 0.1;
|
||||||
const SCALE_VEC = new Vec3(SCALE, SCALE, SCALE);
|
// const SCALE_VEC = new Vec3(SCALE, SCALE, SCALE);
|
||||||
const TIP_LENGTH = 0.17;
|
// const TIP_LENGTH = 0.17;
|
||||||
const TIP_RADIUS = 0.04;
|
// const TIP_RADIUS = 0.04;
|
||||||
const SPIN_RADIUS = 0.0055;
|
// const SPIN_RADIUS = 0.0055;
|
||||||
|
//
|
||||||
|
// const lineObj = Object3d.createCylinder(SPIN_RADIUS, SPIN_RADIUS, 1.0 - TIP_LENGTH).scale(SCALE_VEC);
|
||||||
|
// const tipObj = Object3d.createCylinder(0, TIP_RADIUS, TIP_LENGTH, 16, 16, false, true, 0, -TIP_LENGTH).scale(SCALE_VEC);
|
||||||
|
|
||||||
const lineObj = Object3d.createCylinder(SPIN_RADIUS, SPIN_RADIUS, 1.0 - TIP_LENGTH).scale(SCALE_VEC);
|
// function setArrowLength(axis, length) {
|
||||||
const tipObj = Object3d.createCylinder(0, TIP_RADIUS, TIP_LENGTH, 16, 16, false, true, 0, -TIP_LENGTH).scale(SCALE_VEC);
|
// const scale = new Vec3(1, (length - TIP_LENGTH) / (1.0 - TIP_LENGTH), 1);
|
||||||
|
// const trans = new Vec3(0, length * SCALE, 0);
|
||||||
function setArrowLength(axis, length) {
|
//
|
||||||
const scale = new Vec3(1, (length - TIP_LENGTH) / (1.0 - TIP_LENGTH), 1);
|
// // X
|
||||||
const trans = new Vec3(0, length * SCALE, 0);
|
// let line = axis.childrenNodes[0];
|
||||||
|
// let tip = line.childrenNodes[0];
|
||||||
// X
|
// line.geoObject.setScale3v(scale);
|
||||||
let line = axis.childrenNodes[0];
|
// tip.geoObject.setTranslate3v(trans);
|
||||||
let tip = line.childrenNodes[0];
|
//
|
||||||
line.geoObject.setScale3v(scale);
|
// // Y
|
||||||
tip.geoObject.setTranslate3v(trans);
|
// line = axis.childrenNodes[1];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
// Y
|
// line.geoObject.setScale3v(scale);
|
||||||
line = axis.childrenNodes[1];
|
// tip.geoObject.setTranslate3v(trans);
|
||||||
tip = line.childrenNodes[0];
|
//
|
||||||
line.geoObject.setScale3v(scale);
|
// // Z
|
||||||
tip.geoObject.setTranslate3v(trans);
|
// line = axis.childrenNodes[2];
|
||||||
|
// tip = line.childrenNodes[0];
|
||||||
// Z
|
// line.geoObject.setScale3v(scale);
|
||||||
line = axis.childrenNodes[2];
|
// tip.geoObject.setTranslate3v(trans);
|
||||||
tip = line.childrenNodes[0];
|
// }
|
||||||
line.geoObject.setScale3v(scale);
|
|
||||||
tip.geoObject.setTranslate3v(trans);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelector(".gpitch").addEventListener("input", (e) => {
|
document.querySelector(".gpitch").addEventListener("input", (e) => {
|
||||||
setPitch(Number(e.target.value));
|
setPitch(Number(e.target.value));
|
||||||
@ -189,98 +199,99 @@
|
|||||||
document.querySelector(".glength").addEventListener("input", (e) => {
|
document.querySelector(".glength").addEventListener("input", (e) => {
|
||||||
let spinEntities = axesLayer.getEntities();
|
let spinEntities = axesLayer.getEntities();
|
||||||
for (let i = 0; i < spinEntities.length; i++) {
|
for (let i = 0; i < spinEntities.length; i++) {
|
||||||
setArrowLength(spinEntities[i], Number(e.target.value));
|
spinEntities[i].setSize(Number(e.target.value));
|
||||||
|
//setArrowLength(spinEntities[i], Number(e.target.value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let i = -90; i <= 90; i += 5) {
|
for (let i = -90; i <= 90; i += 5) {
|
||||||
for (let j = -180; j < 180; j += 10) {
|
for (let j = -180; j < 180; j += 10) {
|
||||||
|
|
||||||
let axisEntity = new Entity();
|
let axisEntity = new AxisEntity();
|
||||||
|
|
||||||
let arrowX = new Entity({
|
// let arrowX = new Entity({
|
||||||
independentPicking: true,
|
// independentPicking: true,
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "green",
|
// color: "green",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "line",
|
// tag: "line",
|
||||||
object3d: lineObj,
|
// object3d: lineObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 0,
|
// pitch: 0,
|
||||||
roll: 90
|
// roll: 90
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
arrowX.appendChild(new Entity({
|
// arrowX.appendChild(new Entity({
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "green",
|
// color: "green",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "tip",
|
// tag: "tip",
|
||||||
object3d: tipObj,
|
// object3d: tipObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 0,
|
// pitch: 0,
|
||||||
roll: 90
|
// roll: 90
|
||||||
}
|
// }
|
||||||
}));
|
// }));
|
||||||
|
//
|
||||||
|
//
|
||||||
let arrowY = new Entity({
|
// let arrowY = new Entity({
|
||||||
independentPicking: true,
|
// independentPicking: true,
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "blue",
|
// color: "blue",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "line",
|
// tag: "line",
|
||||||
object3d: lineObj,
|
// object3d: lineObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 0
|
// pitch: 0
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
arrowY.appendChild(new Entity({
|
// arrowY.appendChild(new Entity({
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "blue",
|
// color: "blue",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "tip",
|
// tag: "tip",
|
||||||
object3d: tipObj,
|
// object3d: tipObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 0
|
// pitch: 0
|
||||||
}
|
// }
|
||||||
}));
|
// }));
|
||||||
|
//
|
||||||
let arrowZ = new Entity({
|
// let arrowZ = new Entity({
|
||||||
independentPicking: true,
|
// independentPicking: true,
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "red",
|
// color: "red",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "line",
|
// tag: "line",
|
||||||
object3d: lineObj,
|
// object3d: lineObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 90
|
// pitch: 90
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
arrowZ.appendChild(new Entity({
|
// arrowZ.appendChild(new Entity({
|
||||||
geoObject: {
|
// geoObject: {
|
||||||
color: "red",
|
// color: "red",
|
||||||
scale: 1.0,
|
// scale: 1.0,
|
||||||
instanced: true,
|
// instanced: true,
|
||||||
tag: "tip",
|
// tag: "tip",
|
||||||
object3d: tipObj,
|
// object3d: tipObj,
|
||||||
yaw: 0,
|
// yaw: 0,
|
||||||
pitch: 90
|
// pitch: 90
|
||||||
}
|
// }
|
||||||
}));
|
// }));
|
||||||
|
//
|
||||||
axisEntity.appendChild(arrowX);
|
// axisEntity.appendChild(arrowX);
|
||||||
axisEntity.appendChild(arrowY);
|
// axisEntity.appendChild(arrowY);
|
||||||
axisEntity.appendChild(arrowZ);
|
// axisEntity.appendChild(arrowZ);
|
||||||
|
//
|
||||||
setArrowLength(axisEntity, 1);
|
// setArrowLength(axisEntity, 1);
|
||||||
|
|
||||||
axesLayer.add(axisEntity);
|
axesLayer.add(axisEntity);
|
||||||
}
|
}
|
||||||
|
|||||||
185
src/control/editor/AxisEntity.ts
Normal file
185
src/control/editor/AxisEntity.ts
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
import {Entity, IEntityParams} from "../../entity/Entity";
|
||||||
|
import {EntityCollection} from "../../entity/EntityCollection";
|
||||||
|
import {Vector} from "../../layer/Vector";
|
||||||
|
import {Vec3} from "../../math/Vec3";
|
||||||
|
import {Object3d} from "../../Object3d";
|
||||||
|
|
||||||
|
const SCALE = 0.1;
|
||||||
|
const SCALE_VEC = new Vec3(SCALE, SCALE, SCALE);
|
||||||
|
const TIP_LENGTH = 0.17;
|
||||||
|
const TIP_RADIUS = 0.04;
|
||||||
|
const SPIN_RADIUS = 0.0055;
|
||||||
|
|
||||||
|
const lineObj = Object3d.createCylinder(SPIN_RADIUS, SPIN_RADIUS, 1.0 - TIP_LENGTH).scale(SCALE_VEC);
|
||||||
|
const tipObj = Object3d.createCylinder(0, TIP_RADIUS, TIP_LENGTH, 16, 16, false, true, 0, -TIP_LENGTH).scale(SCALE_VEC);
|
||||||
|
|
||||||
|
export interface IAxisEntityParams extends IEntityParams {
|
||||||
|
size?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AxisEntity extends Entity {
|
||||||
|
protected _size: number;
|
||||||
|
|
||||||
|
constructor(params: IAxisEntityParams = {}) {
|
||||||
|
super(params);
|
||||||
|
this._size = params.size != undefined ? params.size : 1.0;
|
||||||
|
this._initArrows();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _initArrows() {
|
||||||
|
let arrowX = new Entity({
|
||||||
|
independentPicking: true,
|
||||||
|
geoObject: {
|
||||||
|
color: "green",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "line",
|
||||||
|
object3d: lineObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 0,
|
||||||
|
roll: 90
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
arrowX.appendChild(new Entity({
|
||||||
|
geoObject: {
|
||||||
|
color: "green",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "tip",
|
||||||
|
object3d: tipObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 0,
|
||||||
|
roll: 90
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
let arrowY = new Entity({
|
||||||
|
independentPicking: true,
|
||||||
|
geoObject: {
|
||||||
|
color: "blue",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "line",
|
||||||
|
object3d: lineObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
arrowY.appendChild(new Entity({
|
||||||
|
geoObject: {
|
||||||
|
color: "blue",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "tip",
|
||||||
|
object3d: tipObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 0
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
let arrowZ = new Entity({
|
||||||
|
independentPicking: true,
|
||||||
|
geoObject: {
|
||||||
|
color: "red",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "line",
|
||||||
|
object3d: lineObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 90
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
arrowZ.appendChild(new Entity({
|
||||||
|
geoObject: {
|
||||||
|
color: "red",
|
||||||
|
scale: 1.0,
|
||||||
|
instanced: true,
|
||||||
|
tag: "tip",
|
||||||
|
object3d: tipObj,
|
||||||
|
yaw: 0,
|
||||||
|
pitch: 90
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.appendChild(arrowX);
|
||||||
|
this.appendChild(arrowY);
|
||||||
|
this.appendChild(arrowZ);
|
||||||
|
|
||||||
|
this.setSize(this._size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setSize(size: number) {
|
||||||
|
this._size = size;
|
||||||
|
|
||||||
|
const scale = new Vec3(1, (this._size - TIP_LENGTH) / (1.0 - TIP_LENGTH), 1);
|
||||||
|
const trans = new Vec3(0, this._size * SCALE, 0);
|
||||||
|
|
||||||
|
// X
|
||||||
|
let line = this.childrenNodes[0];
|
||||||
|
let tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setScale3v(scale);
|
||||||
|
tip.geoObject!.setTranslate3v(trans);
|
||||||
|
|
||||||
|
// Y
|
||||||
|
line = this.childrenNodes[1];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setScale3v(scale);
|
||||||
|
tip.geoObject!.setTranslate3v(trans);
|
||||||
|
|
||||||
|
// Z
|
||||||
|
line = this.childrenNodes[2];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setScale3v(scale);
|
||||||
|
tip.geoObject!.setTranslate3v(trans);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setPitch(a: number) {
|
||||||
|
let line = this.childrenNodes[0];
|
||||||
|
let tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setPitch(a);
|
||||||
|
tip.geoObject!.setPitch(a);
|
||||||
|
|
||||||
|
line = this.childrenNodes[1];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setPitch(a);
|
||||||
|
tip.geoObject!.setPitch(a);
|
||||||
|
|
||||||
|
line = this.childrenNodes[2];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setPitch(a + 90);
|
||||||
|
tip.geoObject!.setPitch(a + 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setYaw(a: number) {
|
||||||
|
let line = this.childrenNodes[0];
|
||||||
|
let tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setYaw(a);
|
||||||
|
tip.geoObject!.setYaw(a);
|
||||||
|
|
||||||
|
line = this.childrenNodes[1];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setYaw(a);
|
||||||
|
tip.geoObject!.setYaw(a);
|
||||||
|
|
||||||
|
line = this.childrenNodes[2];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setYaw(a);
|
||||||
|
tip.geoObject!.setYaw(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public setRoll(a: number) {
|
||||||
|
let line = this.childrenNodes[0];
|
||||||
|
let tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setRoll(a + 90);
|
||||||
|
tip.geoObject!.setRoll(a + 90);
|
||||||
|
|
||||||
|
line = this.childrenNodes[1];
|
||||||
|
tip = line.childrenNodes[0];
|
||||||
|
line.geoObject!.setRoll(a);
|
||||||
|
tip.geoObject!.setRoll(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -83,6 +83,8 @@ import {
|
|||||||
GlobusRgbTerrain
|
GlobusRgbTerrain
|
||||||
} from './terrain/index';
|
} from './terrain/index';
|
||||||
|
|
||||||
|
import {AxisEntity} from "./control/editor/AxisEntity";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
bv,
|
bv,
|
||||||
jd,
|
jd,
|
||||||
@ -137,5 +139,7 @@ export {
|
|||||||
EquiQuadTreeStrategy,
|
EquiQuadTreeStrategy,
|
||||||
EarthQuadTreeStrategy,
|
EarthQuadTreeStrategy,
|
||||||
Wgs84QuadTreeStrategy,
|
Wgs84QuadTreeStrategy,
|
||||||
Object3d
|
Object3d,
|
||||||
|
|
||||||
|
AxisEntity,
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user