模型一直向上運(yùn)動(dòng)的正常效果:
問題場(chǎng)景:
1.new mars3d.graphic.ModelPrimitive({使用addDynamicPosition(設(shè)置并添加動(dòng)畫軌跡位置,按“指定時(shí)間”運(yùn)動(dòng)到達(dá)“指定位置”時(shí)發(fā)現(xiàn),如果是同一個(gè)點(diǎn)位不同高度值的y軸豎直向上方向的運(yùn)動(dòng)。
指定pitch:270偏轉(zhuǎn)角度的時(shí)候,會(huì)出現(xiàn)模型的角度值異常的問題。
錯(cuò)誤代碼:
相關(guān)api文檔:
ModelPrimitive - V3.7.0 - Mars3D API文檔
相關(guān)示例演示鏈接:
功能示例(原生JS版) | Mars3D三維可視化平臺(tái) | 合肥火星科技有限公司
復(fù)現(xiàn)代碼:
? function addDemoGraphics() {
? ? ? ? for (var i = 0; i < 1; i++) {
? ? ? ? ? var graphic = new mars3d.graphic.ModelPrimitive({
? ? ? ? ? ? // forwardExtrapolationType: Cesium.ExtrapolationType.HOLD,
? ? ? ? ? ? style: {
? ? ? ? ? ? ? url: "http://data.mars3d.cn/gltf/mars/qiche.gltf",
? ? ? ? ? ? ? scale: 0.5,
? ? ? ? ? ? ? minimumPixelSize: 20,
? ? ? ? ? ? ? pitch: 270,
? ? ?
? ? ? ? ? ? ? // 高亮?xí)r的樣式(默認(rèn)為鼠標(biāo)移入,也可以指定type:'click'單擊高亮),構(gòu)造后也可以openHighlight、closeHighlight方法來手動(dòng)調(diào)用
? ? ? ? ? ? ? highlight: {
? ? ? ? ? ? ? ? type: mars3d.EventType.click,
? ? ? ? ? ? ? ? silhouette: true,
? ? ? ? ? ? ? ? silhouetteColor: "#ff0000",
? ? ? ? ? ? ? ? silhouetteSize: 4
? ? ? ? ? ? ? },
? ? ?
? ? ? ? ? ? ? label: {
? ? ? ? ? ? ? ? // 不需要文字時(shí),去掉label配置即可
? ? ? ? ? ? ? ? text: "皖A(yù)000" + i,
? ? ? ? ? ? ? ? font_size: 16,
? ? ? ? ? ? ? ? color: "#ffffff",
? ? ? ? ? ? ? ? outline: true,
? ? ? ? ? ? ? ? outlineColor: "#000000",
? ? ? ? ? ? ? ? pixelOffsetY: -20,
? ? ? ? ? ? ? ? distanceDisplayCondition: true,
? ? ? ? ? ? ? ? distanceDisplayCondition_far: 50000,
? ? ? ? ? ? ? ? distanceDisplayCondition_near: 0
? ? ? ? ? ? ? }
? ? ? ? ? ? },
? ? ? ? ? ? attr: { index: i, name: "ModelPrimitive" }
? ? ? ? ? })
? ? ? ? ? graphicLayer.addGraphic(graphic)
? ? ? ? }
? ? ?
? ? ?
? ? ?
? ? ? ? // 設(shè)置動(dòng)態(tài)位置
? ? ? ? changePosition(0)
? ? ?
? ? ? ? // 定時(shí)更新動(dòng)態(tài)位置(setInterval為演示)
? ? ? ? var interval = 30
? ? ? ? changePosition(interval)
? ? ? ? setInterval(() => {
? ? ? ? ? changePosition(interval)
? ? ? ? }, interval * 1000)
? ? ? }
? ? ?
? ? ? // 改變位置
? ? ? function changePosition(time) {
? ? ? ? graphicLayer.eachGraphic((graphic) => {
? ? ? ? ? if (graphic.isPrivate) {
? ? ? ? ? ? return
? ? ? ? ? }
? ? ? ? ? graphic.addDynamicPosition(randomPoint(time), time) // 按time秒運(yùn)動(dòng)至指定位置
? ? ? ? })
? ? ? }
? ? ?
? ? ? // 取區(qū)域內(nèi)的隨機(jī)點(diǎn)
? ? ? function randomPoint(time) {
? ? ? ? return Cesium.Cartesian3.fromDegrees(117.207666, 31.817099, time)
? ? ? }
? ? ? function random(min, max) {
? ? ? ? return Math.floor(Math.random() * (max - min + 1) + min)
? ? ? }
關(guān)鍵代碼說明:
1. return Cesium.Cartesian3.fromDegrees(117.207666, 31.817099, time)是實(shí)現(xiàn)小車模型隨著時(shí)間沿著y軸豎直上升的效果
2.加入? ? pitch: 270,之后,發(fā)現(xiàn)在固定的點(diǎn)位不同高度值運(yùn)動(dòng),cesium底層會(huì)出現(xiàn)相同坐標(biāo),不同高度的2個(gè)點(diǎn)的屬性機(jī)制坐標(biāo)會(huì)角度值異常的效果。
解決方案:
1.在mars3d中,場(chǎng)景中初始化的時(shí)候固定好模型的姿態(tài)信息hpr
? ? ?????????? pitch: 270,
? ? ? ? ? ? ? heading:0,
? ? ? ? ? ? ? roll:0,
相關(guān)代碼:
? ? var graphic = new mars3d.graphic.ModelPrimitive({
? ? ? ? ? ? // forwardExtrapolationType: Cesium.ExtrapolationType.HOLD,
? ? ? ? ? ? style: {
? ? ? ? ? ? ? url: "http://data.mars3d.cn/gltf/mars/qiche.gltf",
? ? ? ? ? ? ? scale: 0.5,
? ? ? ? ? ? ? minimumPixelSize: 20,
? ? ? ? ? ? ? pitch: 90,
? ? ? ? ? ? ? heading:0,
? ? ? ? ? ? ? roll:0,
? ? ?
? ? ? ? ? ? ? // 高亮?xí)r的樣式(默認(rèn)為鼠標(biāo)移入,也可以指定type:'click'單擊高亮),構(gòu)造后也可以openHighlight、closeHighlight方法來手動(dòng)調(diào)用
? ? ? ? ? ? ? highlight: {
? ? ? ? ? ? ? ? type: mars3d.EventType.click,
? ? ? ? ? ? ? ? silhouette: true,
? ? ? ? ? ? ? ? silhouetteColor: "#ff0000",
? ? ? ? ? ? ? ? silhouetteSize: 4
? ? ? ? ? ? ? },
? ? ?
? ? ? ? ? ? ? label: {
? ? ? ? ? ? ? ? // 不需要文字時(shí),去掉label配置即可
? ? ? ? ? ? ? ? text: "皖A(yù)000" + i,
? ? ? ? ? ? ? ? font_size: 16,
? ? ? ? ? ? ? ? color: "#ffffff",
? ? ? ? ? ? ? ? outline: true,
? ? ? ? ? ? ? ? outlineColor: "#000000",
? ? ? ? ? ? ? ? pixelOffsetY: -20,
? ? ? ? ? ? ? ? distanceDisplayCondition: true,
? ? ? ? ? ? ? ? distanceDisplayCondition_far: 50000,
? ? ? ? ? ? ? ? distanceDisplayCondition_near: 0
? ? ? ? ? ? ? }
? ? ? ? ? ? },
? ? ? ? ? ? attr: { index: i, name: "ModelPrimitive" }
? ? ? ? ? })
? ? ? ? ? graphicLayer.addGraphic(graphic)
文章來源:http://www.zghlxwxcb.cn/news/detail-801309.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-801309.html
到了這里,關(guān)于cesium內(nèi)部相同坐標(biāo)在不同高度的2個(gè)點(diǎn)的屬性機(jī)制坐標(biāo)會(huì)gltf模型角度值異常問題mars3d的處理辦法的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!