1 Star 0 Fork 1

游侠 / cesiumdemo

forked from Dl12345 / cesiumdemo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index4.html 6.02 KB
一键复制 编辑 原始数据 按行查看 历史
nxycdl 提交于 2021-02-16 15:40 . first commit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="./script/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="./script/Cesium/Widgets/widgets.css" />
<style>
html,
body {
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="cesiumContainer" style="width: 100%"></div>
<script>
const viewer = new Cesium.Viewer("cesiumContainer", {
baseLayerPicker: false,
navigationHelpButton: false,
sceneModePicker: false,
});
function getCzml() {
const czml = [
{
id: "document",
name: "box",
version: "1.0",
},
{
id: "launchvehicle",
name: "launchvehicle box",
position: {
cartographicDegrees: [-114.0, 40.0, 300000.0],
},
model: {
//gltf: "https://assets.agi.com/models/launchvehicle.glb",
gltf: "./assets/launchvehicle.glb",
scale: 2.0,
minimumPixelSize: 128,
runAnimations: false,
color: {
rgba: [102, 255, 255, 128],
},
},
},
{
id: "airOne",
name: "airOne box with black outline",
position: {
cartographicDegrees: [-107.0, 40.0, 300000.0],
},
model: {
//gltf: "https://assets.agi.com/models/launchvehicle.glb",
gltf: "./assets/SampleData/models/CesiumAir/Cesium_Air.glb",
scale: 2.0,
minimumPixelSize: 128,
runAnimations: false,
color: {
rgba: [255, 0, 0, 128],
},
},
},
{
id: "airTwo",
name: "airTwo box with black outline",
position: {
cartographicDegrees: [-100.0, 40.0, 300000.0],
},
model: {
//gltf: "https://assets.agi.com/models/launchvehicle.glb",
gltf: "./assets/SampleData/models/CesiumAir/Cesium_Air.glb",
scale: 2.0,
minimumPixelSize: 128,
runAnimations: false,
color: {
rgba: [255, 255, 0, 128],
},
},
},
];
return czml;
}
function setRotate(entity, rotate) {
console.log(entity, rotate);
const { rotateX, rotateY, rotateZ } = rotate;
const origin = entity.position.getValue();
console.log(origin, "xxxx");
const heading = Cesium.Math.toRadians(this.rotateX);
const pitch = Cesium.Math.toRadians(this.rotateY);
const roll = Cesium.Math.toRadians(this.rotateZ);
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
const orientation = Cesium.Transforms.headingPitchRollQuaternion(
origin,
hpr
);
entity.orientation = orientation;
}
const params = {
tx: -121, //模型中心X轴坐标(经度,单位:十进制度)
ty: 45, //模型中心Y轴坐标(纬度,单位:十进制度)
tz: 300000, //模型中心Z轴坐标(高程,单位:米)
rx: 90, //X轴(经度)方向旋转角度(单位:度)
ry: 90, //Y轴(纬度)方向旋转角度(单位:度)
rz: 90, //Z轴(高程)方向旋转角度(单位:度)
};
function update3dtilesMaxtrix(tileset) {
//旋转
var mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(params.rx));
var my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(params.ry));
var mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(params.rz));
var rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
var rotationY = Cesium.Matrix4.fromRotationTranslation(my);
var rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
//平移
var position = Cesium.Cartesian3.fromDegrees(
params.tx,
params.ty,
params.tz
);
var m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
//旋转、平移矩阵相乘
Cesium.Matrix4.multiply(m, rotationX, m);
Cesium.Matrix4.multiply(m, rotationY, m);
Cesium.Matrix4.multiply(m, rotationZ, m);
//赋值给tileset
tileset.modelMatrix = m;
}
function startUp() {
console.log("x");
const czml = getCzml();
const dataSourcePromise = Cesium.CzmlDataSource.load(czml);
dataSourcePromise.then((dataSource) => {
const entity = dataSource.entities.getById("launchvehicle");
console.log(entity);
//setRotate(entity, { rotateX: 100, rotateY: 100, rotateZ: 100 });
//update3dtilesMaxtrix(entity);
setModelMatrix(entity);
});
viewer.dataSources.add(dataSourcePromise);
viewer.zoomTo(dataSourcePromise);
}
function setModelMatrix(entity) {
console.log(entity.modelMatrix, "aaaaaa");
const params = {
height: 300000.0,
heading: 0.0,
pitch: Cesium.Math.toRadians(10.0),
roll: Cesium.Math.toRadians(-20.0),
};
//const height = Cesium.defaultValue(params.height, 0.0);
const heading = Cesium.defaultValue(params.heading, 0.0);
const pitch = Cesium.defaultValue(params.pitch, 0.0);
const roll = Cesium.defaultValue(params.roll, 0.0);
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var origin = Cesium.Cartesian3.fromDegrees(-114, 40, params.height);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
origin,
hpr
);
entity.modelMatrix = modelMatrix;
}
startUp();
</script>
</body>
</html>
1
https://gitee.com/shuhairun/cesiumdemo.git
git@gitee.com:shuhairun/cesiumdemo.git
shuhairun
cesiumdemo
cesiumdemo
master

搜索帮助