Files
sdk4.0/src/Obj/Base/Road/index3.js
2025-07-15 10:37:23 +08:00

788 lines
33 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 道路
*/
import Base from "../index";
import PolylineImageTrailMaterialProperty from "../../Materail/PolylineImageTrailMaterialProperty";
import { init_material } from "./RoadMaterialProperty";
class Corridor extends Base {
/**
* @constructor
* @param sdk
* @param options {object} 属性
* @param options.name{string} 名称
* @param options.image{string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement} 指定 Image、URL、Canvas 或 Video 的属性
* @param options.width=10{number} 宽度
* @param options.height=0{number} 高度
* */
constructor(sdk, options = {}) {
super(sdk, options);
this.options.name = options.name || ''
this.options.image = options.image
this.options.width = options.width || 10
this.options.height = options.height || 0
init_material()
}
create(positions) {
this.computeRoad(positions)
let fromDegreesArray = []
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
}
let length = this.computeDistance2(positions)
let geometry = new Cesium.CorridorGeometry({
positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
width: this.options.width,
height: this.options.height,
cornerType: Cesium.CornerType.MITERED,
vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat
})
// console.log(Cesium.CorridorGeometry.createGeometry(geometry))
// this.entity = this.sdk.viewer.scene.primitives.add(new Cesium.Primitive({//GroundPrimitive贴地
// geometryInstances: new Cesium.GeometryInstance({
// geometry: geometry,
// attributes: {
// color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 1.0, 1.0, 0.5))
// }
// }),
// appearance: new Cesium.MaterialAppearance({
// material: Cesium.Material.fromType('Image', {
// image: this.options.image,
// repeat: new Cesium.Cartesian2(length / this.options.width * 2, 1.0)
// }),
// faceForward: true,
// renderState: {
// blending: Cesium.BlendingState.ALPHA_BLEND
// }
// })
// }));
// console.log(this.entity, Outlinegeometry)
// this.entity = this.sdk.viewer.entities.add({
// name: "Red corridor on surface with rounded corners",
// corridor: {
// positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
// width: this.options.width,
// height: 10,
// cornerType: Cesium.CornerType.MITERED,
// material: new Cesium.ImageMaterialProperty({
// image: this.options.image,
// repeat: new Cesium.Cartesian2(100, 1.0),
// color: Cesium.Color.TOMATO
// })
// }
// });
}
// 编辑框
async edit(state) { }
remove() {
this.sdk.viewer.scene.primitives.remove(this.entity)
this.entity = null
}
computeRoad(positions) {
let fromDegreesArray = []
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
}
let Outlinegeometry = new Cesium.CorridorGeometry({
positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
width: this.options.width,
cornerType: Cesium.CornerType.MITERED,
vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat
})
let geometry = Cesium.CorridorGeometry.createGeometry(Outlinegeometry)
console.log(geometry)
let t = 0
setInterval(() => {
t++
}, 100);
// let entity = this.sdk.viewer.scene.primitives.add(new Cesium.GroundPolylinePrimitive({
// geometryInstances : new Cesium.GeometryInstance({
// geometry : new Cesium.GroundPolylineGeometry({
// positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
// width: this.options.width,
// cornerType: Cesium.CornerType.MITERED,
// vertexFormat: Cesium.MaterialAppearance.MaterialSupport.ALL.vertexFormat
// })
// }),
// appearance: new Cesium.PolylineMaterialAppearance({
// aboveGroud: true,
// material: new Cesium.Material({
// fabric: {
// uniforms: {
// image: this.options.image,
// repeat: new Cesium.Cartesian2(1000, 1.0),
// color: new Cesium.Color(1.0, 0.0, 0.0, 0.1)
// },
// source: `
// uniform sampler2D image;
// uniform vec4 color;
// uniform vec2 repeat;
// czm_material czm_getMaterial(czm_materialInput materialInput){
// czm_material material=czm_getDefaultMaterial(materialInput);
// vec2 st=repeat*materialInput.st;
// float time=fract(czm_frameNumber);
// vec4 colorImage=texture2D(image,vec2(fract(st.s-time),st.t));
// material.alpha=colorImage.a;
// material.diffuse=colorImage.rgb;
// return material;
// }`,
// },
// }),
// vertexShaderSource: `#define CLIP_POLYLINE
// void clipLineSegmentToNearPlane(
// vec3 p0,
// vec3 p1,
// out vec4 positionWC,
// out bool clipped,
// out bool culledByNearPlane,
// out vec4 clippedPositionEC)
// {
// culledByNearPlane = false;
// clipped = false;
// vec3 p0ToP1 = p1 - p0;
// float magnitude = length(p0ToP1);
// vec3 direction = normalize(p0ToP1);
// float endPoint0Distance = czm_currentFrustum.x + p0.z;
// float denominator = -direction.z;
// if (endPoint0Distance > 0.0 && abs(denominator) < czm_epsilon7)
// {
// culledByNearPlane = true;
// }
// else if (endPoint0Distance > 0.0)
// {
// float t = endPoint0Distance / denominator;
// if (t < 0.0 || t > magnitude)
// {
// culledByNearPlane = true;
// }
// else
// {
// p0 = p0 + t * direction;
// p0.z = min(p0.z, -czm_currentFrustum.x);
// clipped = true;
// }
// }
// clippedPositionEC = vec4(p0, 1.0);
// positionWC = czm_eyeToWindowCoordinates(clippedPositionEC);
// }
// vec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)
// {
// #ifdef POLYLINE_DASH
// vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);
// vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);
// vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);
// vec2 lineDir;
// if (usePrevious) {
// lineDir = normalize(positionWindow.xy - previousWindow.xy);
// }
// else {
// lineDir = normalize(nextWindow.xy - positionWindow.xy);
// }
// angle = atan(lineDir.x, lineDir.y) - 1.570796327;
// angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;
// #endif
// vec4 clippedPrevWC, clippedPrevEC;
// bool prevSegmentClipped, prevSegmentCulled;
// clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, clippedPrevWC, prevSegmentClipped, prevSegmentCulled, clippedPrevEC);
// vec4 clippedNextWC, clippedNextEC;
// bool nextSegmentClipped, nextSegmentCulled;
// clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, clippedNextWC, nextSegmentClipped, nextSegmentCulled, clippedNextEC);
// bool segmentClipped, segmentCulled;
// vec4 clippedPositionWC, clippedPositionEC;
// clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, clippedPositionWC, segmentClipped, segmentCulled, clippedPositionEC);
// if (segmentCulled)
// {
// return vec4(0.0, 0.0, 0.0, 1.0);
// }
// vec2 directionToPrevWC = normalize(clippedPrevWC.xy - clippedPositionWC.xy);
// vec2 directionToNextWC = normalize(clippedNextWC.xy - clippedPositionWC.xy);
// if (prevSegmentCulled)
// {
// directionToPrevWC = -directionToNextWC;
// }
// else if (nextSegmentCulled)
// {
// directionToNextWC = -directionToPrevWC;
// }
// vec2 thisSegmentForwardWC, otherSegmentForwardWC;
// if (usePrevious)
// {
// thisSegmentForwardWC = -directionToPrevWC;
// otherSegmentForwardWC = directionToNextWC;
// }
// else
// {
// thisSegmentForwardWC = directionToNextWC;
// otherSegmentForwardWC = -directionToPrevWC;
// }
// vec2 thisSegmentLeftWC = vec2(-thisSegmentForwardWC.y, thisSegmentForwardWC.x);
// vec2 leftWC = thisSegmentLeftWC;
// float expandWidth = width * 0.5;
// if (!czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) && !czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))
// {
// vec2 otherSegmentLeftWC = vec2(-otherSegmentForwardWC.y, otherSegmentForwardWC.x);
// vec2 leftSumWC = thisSegmentLeftWC + otherSegmentLeftWC;
// float leftSumLength = length(leftSumWC);
// leftWC = leftSumLength < czm_epsilon6 ? thisSegmentLeftWC : (leftSumWC / leftSumLength);
// vec2 u = -thisSegmentForwardWC;
// vec2 v = leftWC;
// float sinAngle = abs(u.x * v.y - u.y * v.x);
// expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);
// }
// vec2 offset = leftWC * expandDirection * expandWidth * czm_pixelRatio;
// return vec4(clippedPositionWC.xy + offset, -clippedPositionWC.z, 1.0) * (czm_projection * clippedPositionEC).w;
// }
// vec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)
// {
// vec4 positionEC = czm_modelViewRelativeToEye * position;
// vec4 prevEC = czm_modelViewRelativeToEye * previous;
// vec4 nextEC = czm_modelViewRelativeToEye * next;
// return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);
// }
// attribute vec3 position3DHigh;
// attribute vec3 position3DLow;
// attribute vec3 prevPosition3DHigh;
// attribute vec3 prevPosition3DLow;
// attribute vec3 nextPosition3DHigh;
// attribute vec3 nextPosition3DLow;
// attribute vec2 expandAndWidth;
// attribute vec2 st;
// attribute float batchId;
// varying float v_width;
// varying vec2 v_st;
// varying float v_polylineAngle;
// void main()
// {
// float expandDir = expandAndWidth.x;
// float width = abs(expandAndWidth.y) + 0.5;
// bool usePrev = expandAndWidth.y < 0.0;
// vec4 p = czm_computePosition();
// vec4 prev = czm_computePrevPosition();
// vec4 next = czm_computeNextPosition();
// float angle;
// vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);
// gl_Position = czm_viewportOrthographic * positionWC;
// v_width = width;
// v_st.s = st.s;
// v_st.t = czm_writeNonPerspective(st.t, gl_Position.w);
// v_polylineAngle = angle;
// }`,
// fragmentShaderSource: `#ifdef VECTOR_TILE
// uniform vec4 u_highlightColor;
// #endif
// varying vec2 v_st;
// void main()
// {
// czm_materialInput materialInput;
// vec2 st = v_st;
// st.t = czm_readNonPerspective(st.t, gl_FragCoord.w);
// materialInput.s = st.s;
// materialInput.st = st;
// materialInput.str = vec3(st, 0.0);
// czm_material material = czm_getMaterial(materialInput);
// gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);
// #ifdef VECTOR_TILE
// gl_FragColor *= u_highlightColor;
// #endif
// czm_writeLogDepth();
// }`
// }),
// }));
console.log(entity)
// let entity = this.sdk.viewer.entities.add({
// corridor: {
// positions: Cesium.Cartesian3.fromDegreesArray(fromDegreesArray),
// width: 20000.0,
// cornerType: Cesium.CornerType.MITERED,
// material: new Cesium.RoadMaterialProperty({
// image: this.getSourceRootPath() + '/img/asphaltRoad.jpg',
// color: this.options.color,
// repeat: new Cesium.CallbackProperty(() => {
// let positionProperty = entity.corridor.positions;
// let positions = positionProperty.getValue(this.sdk.viewer.clock.currentTime);
// if (!Cesium.defined(positions)) {
// return new Cesium.Cartesian2(1.0, 1.0);
// }
// let distance = 0;
// for (let i = 0; i < positions.length - 1; ++i) {
// distance += Cesium.Cartesian3.distance(positions[i], positions[i + 1]);
// }
// let imgProportion = 945 / 411 // 图片长宽比例
// let repeatX = distance / 20000;
// repeatX = repeatX / imgProportion
// return new Cesium.Cartesian2(repeatX, 1.0);
// }, false),
// duration: 0,
// rotate: new Cesium.CallbackProperty(() => {
// return t
// }),
// })
// },
// });
// console.log(entity)
let initposition = []
for (let i = 0; i < geometry.attributes.position.values.length; i += 3) {
console.log(geometry.attributes.position.values[i], geometry.attributes.position.values[i + 1], geometry.attributes.position.values[i + 2])
initposition.push(new Cesium.Cartesian3(geometry.attributes.position.values[i], geometry.attributes.position.values[i + 1], geometry.attributes.position.values[i + 2]))
}
console.log(initposition, Cesium.Cartesian3.fromDegrees(91.08567036051947, 24.990201656481236))
let flag = true
let bearing
this.entityArray = []
// 创建一个矩形实体,顶点坐标为世界坐标
const rectangle = this.sdk.viewer.entities.add({
rectangle: {
coordinates: Cesium.Rectangle.fromDegrees(-100.0, 20.0, -90.0, 30.0),
material: new Cesium.ImageMaterialProperty({
image: this.options.image,
repeat: new Cesium.Cartesian2(10, 1.0),
}),
},
});
for (let i = 0; i < geometry.indices.length; i += 3) {
// console.log(bearing)
let angleInDegrees
let theta
if (flag) {
let a = this.cartesian3Towgs84(initposition[geometry.indices[i]], this.sdk.viewer)
let b = this.cartesian3Towgs84(initposition[geometry.indices[i + 2]], this.sdk.viewer)
let point1 = turf.point([a.lng, a.lat]);
let point2 = turf.point([b.lng, b.lat]);
bearing = turf.bearing(point1, point2);
// 计算两点之间的角度
let angle = Cesium.Cartesian3.angleBetween(initposition[geometry.indices[i]], initposition[geometry.indices[i + 2]]);
// 转换角度为角度而不是弧度
angleInDegrees = Cesium.Math.toDegrees(angle)
//以a点为原点建立局部坐标系东方向为x轴,北方向为y轴,垂直于地面为z轴得到一个局部坐标到世界坐标转换的变换矩阵
let localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(initposition[geometry.indices[i]]);
//求世界坐标到局部坐标的变换矩阵
let worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4());
//a点在局部坐标的位置其实就是局部坐标原点
let localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, initposition[geometry.indices[i]], new Cesium.Cartesian3());
//B点在以A点为原点的局部的坐标位置
let localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, initposition[geometry.indices[i + 2]], new Cesium.Cartesian3());
//弧度
let angle2 = Cesium.Math.fastApproximateAtan2((localPosition_B.y - localPosition_A.y), (localPosition_B.x - localPosition_A.x))
//角度
theta = angle2 * (180 / Cesium.Math.PI);
}
else {
let a = this.cartesian3Towgs84(initposition[geometry.indices[i + 1]], this.sdk.viewer)
let b = this.cartesian3Towgs84(initposition[geometry.indices[i + 2]], this.sdk.viewer)
let point1 = turf.point([a.lng, a.lat]);
let point2 = turf.point([b.lng, b.lat]);
bearing = turf.bearing(point1, point2);
// 计算两点之间的角度
let angle = Cesium.Cartesian3.angleBetween(initposition[geometry.indices[i + 1]], initposition[geometry.indices[i + 2]]);
// 转换角度为角度而不是弧度
angleInDegrees = Cesium.Math.toDegrees(angle)
//以a点为原点建立局部坐标系东方向为x轴,北方向为y轴,垂直于地面为z轴得到一个局部坐标到世界坐标转换的变换矩阵
let localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(initposition[geometry.indices[i + 1]]);
//求世界坐标到局部坐标的变换矩阵
let worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4());
//a点在局部坐标的位置其实就是局部坐标原点
let localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, initposition[geometry.indices[i + 1]], new Cesium.Cartesian3());
//B点在以A点为原点的局部的坐标位置
let localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, initposition[geometry.indices[i + 2]], new Cesium.Cartesian3());
//弧度
let angle2 = Cesium.Math.fastApproximateAtan2((localPosition_B.y - localPosition_A.y), (localPosition_B.x - localPosition_A.x))
//角度
theta = angle2 * (180 / Cesium.Math.PI);
}
let point1 = Cesium.Cartesian3.fromDegrees(91, 24.990201656481236);
let point2 = Cesium.Cartesian3.fromDegrees(91, 24.626517401118033);
// 计算两点之间的角度
let angle = Cesium.Cartesian3.angleBetween(point1, point2);
// 转换角度为角度而不是弧度
let xx = Cesium.Math.toDegrees(angle)
flag = !flag
bearing = bearing - 90 + 0.145
console.log(bearing, angleInDegrees, angle, xx, theta)
//以a点为原点建立局部坐标系东方向为x轴,北方向为y轴,垂直于地面为z轴得到一个局部坐标到世界坐标转换的变换矩阵
let localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(point1);
//求世界坐标到局部坐标的变换矩阵
let worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4());
//a点在局部坐标的位置其实就是局部坐标原点
let localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, point1, new Cesium.Cartesian3());
//B点在以A点为原点的局部的坐标位置
let localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, point2, new Cesium.Cartesian3());
//弧度
let angle2 = Cesium.Math.fastApproximateAtan2((localPosition_B.z - localPosition_A.z), (localPosition_B.x - localPosition_A.x))
//角度
let theta2 = angle2 * (180 / Cesium.Math.PI);
// alert(theta2)
// let entity = this.sdk.viewer.entities.add({
// show: this.options.show,
// polygon: {
// hierarchy: new Cesium.PolygonHierarchy([initposition[geometry.indices[i]], initposition[geometry.indices[i + 1]], initposition[geometry.indices[i + 2]]]),
// perPositionHeight: false,
// // material: new PolylineImageTrailMaterialProperty({
// // image: this.options.image,
// // repeat: new Cesium.Cartesian2(10, 1.0),
// // color: Cesium.Color.TOMATO,
// // rotate: 0
// // }),
// material: new Cesium.ImageMaterialProperty({
// image: this.options.image,
// repeat: new Cesium.Cartesian2(1000, 1.0),
// }),
// stRotation: Cesium.Math.toRadians(theta - 90 - 0.0128),
// outline: true,
// outlineColor: Cesium.Color.BLACK,
// }
// })
let aa = 0
const shader = `
uniform sampler2D image;
uniform vec4 color;
uniform vec2 repeat;
czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material=czm_getDefaultMaterial(materialInput);
vec2 st=repeat*materialInput.st;
float time=fract(czm_frameNumber);
vec4 colorImage=texture2D(image,vec2(fract(st.s-time),st.t));
material.alpha=colorImage.a;
material.diffuse=colorImage.rgb;
return material;
}`
console.log(Cesium.Math.toRadians(theta - 90))
// let entity = this.sdk.viewer.scene.primitives.add(new Cesium.Primitive({
// geometryInstances : new Cesium.GeometryInstance({
// geometry : new Cesium.PolylineGeometry({
// positions : Cesium.Cartesian3.fromDegreesArray([
// 0.0, 0.0,
// 5.0, 0.0
// ]),
// width : 10.0,
// vertexFormat : Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
// })
// }),
// appearance: new Cesium.PolylineMaterialAppearance({
// aboveGroud: true,
// material: new Cesium.Material({
// fabric: {
// uniforms: {
// image: this.options.image,
// repeat: new Cesium.Cartesian2(1000, 1.0),
// color: new Cesium.Color(1.0, 0.0, 0.0, 0.1)
// },
// source: shader,
// },
// }),
// vertexShaderSource: `#define CLIP_POLYLINE
// void clipLineSegmentToNearPlane(
// vec3 p0,
// vec3 p1,
// out vec4 positionWC,
// out bool clipped,
// out bool culledByNearPlane,
// out vec4 clippedPositionEC)
// {
// culledByNearPlane = false;
// clipped = false;
// vec3 p0ToP1 = p1 - p0;
// float magnitude = length(p0ToP1);
// vec3 direction = normalize(p0ToP1);
// float endPoint0Distance = czm_currentFrustum.x + p0.z;
// float denominator = -direction.z;
// if (endPoint0Distance > 0.0 && abs(denominator) < czm_epsilon7)
// {
// culledByNearPlane = true;
// }
// else if (endPoint0Distance > 0.0)
// {
// float t = endPoint0Distance / denominator;
// if (t < 0.0 || t > magnitude)
// {
// culledByNearPlane = true;
// }
// else
// {
// p0 = p0 + t * direction;
// p0.z = min(p0.z, -czm_currentFrustum.x);
// clipped = true;
// }
// }
// clippedPositionEC = vec4(p0, 1.0);
// positionWC = czm_eyeToWindowCoordinates(clippedPositionEC);
// }
// vec4 getPolylineWindowCoordinatesEC(vec4 positionEC, vec4 prevEC, vec4 nextEC, float expandDirection, float width, bool usePrevious, out float angle)
// {
// #ifdef POLYLINE_DASH
// vec4 positionWindow = czm_eyeToWindowCoordinates(positionEC);
// vec4 previousWindow = czm_eyeToWindowCoordinates(prevEC);
// vec4 nextWindow = czm_eyeToWindowCoordinates(nextEC);
// vec2 lineDir;
// if (usePrevious) {
// lineDir = normalize(positionWindow.xy - previousWindow.xy);
// }
// else {
// lineDir = normalize(nextWindow.xy - positionWindow.xy);
// }
// angle = atan(lineDir.x, lineDir.y) - 1.570796327;
// angle = floor(angle / czm_piOverFour + 0.5) * czm_piOverFour;
// #endif
// vec4 clippedPrevWC, clippedPrevEC;
// bool prevSegmentClipped, prevSegmentCulled;
// clipLineSegmentToNearPlane(prevEC.xyz, positionEC.xyz, clippedPrevWC, prevSegmentClipped, prevSegmentCulled, clippedPrevEC);
// vec4 clippedNextWC, clippedNextEC;
// bool nextSegmentClipped, nextSegmentCulled;
// clipLineSegmentToNearPlane(nextEC.xyz, positionEC.xyz, clippedNextWC, nextSegmentClipped, nextSegmentCulled, clippedNextEC);
// bool segmentClipped, segmentCulled;
// vec4 clippedPositionWC, clippedPositionEC;
// clipLineSegmentToNearPlane(positionEC.xyz, usePrevious ? prevEC.xyz : nextEC.xyz, clippedPositionWC, segmentClipped, segmentCulled, clippedPositionEC);
// if (segmentCulled)
// {
// return vec4(0.0, 0.0, 0.0, 1.0);
// }
// vec2 directionToPrevWC = normalize(clippedPrevWC.xy - clippedPositionWC.xy);
// vec2 directionToNextWC = normalize(clippedNextWC.xy - clippedPositionWC.xy);
// if (prevSegmentCulled)
// {
// directionToPrevWC = -directionToNextWC;
// }
// else if (nextSegmentCulled)
// {
// directionToNextWC = -directionToPrevWC;
// }
// vec2 thisSegmentForwardWC, otherSegmentForwardWC;
// if (usePrevious)
// {
// thisSegmentForwardWC = -directionToPrevWC;
// otherSegmentForwardWC = directionToNextWC;
// }
// else
// {
// thisSegmentForwardWC = directionToNextWC;
// otherSegmentForwardWC = -directionToPrevWC;
// }
// vec2 thisSegmentLeftWC = vec2(-thisSegmentForwardWC.y, thisSegmentForwardWC.x);
// vec2 leftWC = thisSegmentLeftWC;
// float expandWidth = width * 0.5;
// if (!czm_equalsEpsilon(prevEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1) && !czm_equalsEpsilon(nextEC.xyz - positionEC.xyz, vec3(0.0), czm_epsilon1))
// {
// vec2 otherSegmentLeftWC = vec2(-otherSegmentForwardWC.y, otherSegmentForwardWC.x);
// vec2 leftSumWC = thisSegmentLeftWC + otherSegmentLeftWC;
// float leftSumLength = length(leftSumWC);
// leftWC = leftSumLength < czm_epsilon6 ? thisSegmentLeftWC : (leftSumWC / leftSumLength);
// vec2 u = -thisSegmentForwardWC;
// vec2 v = leftWC;
// float sinAngle = abs(u.x * v.y - u.y * v.x);
// expandWidth = clamp(expandWidth / sinAngle, 0.0, width * 2.0);
// }
// vec2 offset = leftWC * expandDirection * expandWidth * czm_pixelRatio;
// return vec4(clippedPositionWC.xy + offset, -clippedPositionWC.z, 1.0) * (czm_projection * clippedPositionEC).w;
// }
// vec4 getPolylineWindowCoordinates(vec4 position, vec4 previous, vec4 next, float expandDirection, float width, bool usePrevious, out float angle)
// {
// vec4 positionEC = czm_modelViewRelativeToEye * position;
// vec4 prevEC = czm_modelViewRelativeToEye * previous;
// vec4 nextEC = czm_modelViewRelativeToEye * next;
// return getPolylineWindowCoordinatesEC(positionEC, prevEC, nextEC, expandDirection, width, usePrevious, angle);
// }
// attribute vec3 position3DHigh;
// attribute vec3 position3DLow;
// attribute vec3 prevPosition3DHigh;
// attribute vec3 prevPosition3DLow;
// attribute vec3 nextPosition3DHigh;
// attribute vec3 nextPosition3DLow;
// attribute vec2 expandAndWidth;
// attribute vec2 st;
// attribute float batchId;
// varying float v_width;
// varying vec2 v_st;
// varying float v_polylineAngle;
// void main()
// {
// float expandDir = expandAndWidth.x;
// float width = abs(expandAndWidth.y) + 0.5;
// bool usePrev = expandAndWidth.y < 0.0;
// vec4 p = czm_computePosition();
// vec4 prev = czm_computePrevPosition();
// vec4 next = czm_computeNextPosition();
// float angle;
// vec4 positionWC = getPolylineWindowCoordinates(p, prev, next, expandDir, width, usePrev, angle);
// gl_Position = czm_viewportOrthographic * positionWC;
// v_width = width;
// v_st.s = st.s;
// v_st.t = czm_writeNonPerspective(st.t, gl_Position.w);
// v_polylineAngle = angle;
// }`,
// fragmentShaderSource: `#ifdef VECTOR_TILE
// uniform vec4 u_highlightColor;
// #endif
// varying vec2 v_st;
// void main()
// {
// czm_materialInput materialInput;
// vec2 st = v_st;
// st.t = czm_readNonPerspective(st.t, gl_FragCoord.w);
// materialInput.s = st.s;
// materialInput.st = st;
// materialInput.str = vec3(st, 0.0);
// czm_material material = czm_getMaterial(materialInput);
// gl_FragColor = vec4(material.diffuse + material.emission, material.alpha);
// #ifdef VECTOR_TILE
// gl_FragColor *= u_highlightColor;
// #endif
// czm_writeLogDepth();
// }`
// }),
// }));
// console.log(entity)
// let geometryInstances2 = new Cesium.GeometryInstance({
// geometry: new Cesium.PolygonGeometry({
// polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray([100, 1, 101, 1, 101, -1, 100, -1])),
// }),
// })
// let entity2 = this.sdk.viewer.scene.primitives.add(new Cesium.GroundPrimitive({
// geometryInstances: geometryInstances2,
// appearance: new Cesium.EllipsoidSurfaceAppearance({
// aboveGroud: true,
// material: new Cesium.Material({
// fabric: {
// uniforms: {
// color: new Cesium.Color(1.0, 0.0, 0.0, 0.1),
// image: this.options.image,
// repeat: new Cesium.Cartesian2(1000, 1.0),
// rotate: 0
// },
// source: shader
// },
// }),
// }),
// }));
// console.log(geometryInstances2)
// // 获取多边形的边界矩形
// let boundingSphere = geometryInstances2.geometry.boundingSphere;
// // 创建一个矩阵,它表示多边形的本地坐标到世界坐标的转换
// let matrix = Cesium.Transforms.eastNorthUpToFixedFrame(boundingSphere.center);
// console.log(entity2, matrix)
// setInterval(() => {
// }, 100);
// this.entityArray.push(entity)
console.log(entity)
}
// let entity = this.sdk.viewer.entities.add({
// show: this.options.show,
// polygon: {
// hierarchy: new Cesium.PolygonHierarchy([
// new Cesium.Cartesian3(1201222.3498141132, 5794200.4246190665, 2372132.932514765),
// new Cesium.Cartesian3(1200929.6921250424, 5794615.962987943, 2371271.7244476764),
// new Cesium.Cartesian3(1199139.8791256004, 5794316.892300814, 2372896.7988495603)]),
// perPositionHeight: true,
// material: new PolylineImageTrailMaterialProperty({
// image: this.options.image,
// repeat: new Cesium.Cartesian2(10, 1.0),
// color: Cesium.Color.TOMATO,
// rotate: 0
// }),
// outline: true,
// outlineColor: Cesium.Color.BLACK,
// }
// })
// console.log(entity)
// 创建新材质
let newMaterial = new Cesium.Material({
fabric: {
type: 'Color',
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 1.0) // 红色
}
}
});
console.log(newMaterial)
// this.entity = this.sdk.viewer.entities.add({
// show: this.options.show,
// polygon: {
// hierarchy: new Cesium.PolygonHierarchy(initposition),
// perPositionHeight: false,
// material: new Cesium.ImageMaterialProperty({
// image: this.options.image,
// repeat: new Cesium.Cartesian2(100, 1.0),
// color: Cesium.Color.AQUA
// })
// }
// })
for (let i = 0; i < initposition.length; i++) {
let entity = this.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
index: i,
position: initposition[i],
billboard: {
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
label: {
text: '' + i,
pixelOffset: { x: 0, y: -20 },
},
})
}
this.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
position: Cesium.Cartesian3.fromDegrees(91.08567036051947, 24.990201656481236),
billboard: {
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
this.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
position: Cesium.Cartesian3.fromDegrees(91.08588488854294, 24.626517401118033),
billboard: {
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
}
test(v) {
for (let i = 0; i < this.entityArray.length; i++) {
this.entityArray[i].polygon.stRotation = Cesium.Math.toRadians(v)
}
}
}
export default Corridor