Cesium 动态更换模型贴图方法
参考资料
示例代码
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var imagePath = '../../../../Apps/SampleData/models/CesiumAir/0_Cesium_Air.png';
var model = createModel('../../../../Apps/SampleData/models/CesiumBalloon/CesiumBalloon.glb');
// New texture must be the same size as the original texture
model.readyPromise.then(function() {
var textureIndexToReplace = 0;
var textures = model._rendererResources.textures;
var texture = textures[textureIndexToReplace];
Cesium.Resource.fetchImage({
url : imagePath
}).then(function(image) {
texture.copyFrom(image);
texture.generateMipmap(); // Also replaces textures in mipmap
});
});
function createModel(url) {
var origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 0.0);
var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll(0.0, 0.0, 0.0));
var model = scene.primitives.add(Cesium.Model.fromGltf({
url : url,
modelMatrix : modelMatrix,
minimumPixelSize : 128,
incrementallyLoadTextures : false
}));
model.readyPromise.then(function(model) {
var camera = viewer.camera;
// Zoom to model
var controller = scene.screenSpaceCameraController;
var r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near);
controller.minimumZoomDistance = r * 0.5;
var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, model.boundingSphere.center, new Cesium.Cartesian3());
var heading = Cesium.Math.toRadians(230.0);
var pitch = Cesium.Math.toRadians(-20.0);
camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, r * 2.0));
}).otherwise(function(error){
window.alert(error);
});
return model;
}
/*
// Alernate approach - but requires fix in DelayLoadedTextureUniform to return this._textures[this._textureId] instead of this._value
model.readyPromise.then(function() {
var textureIndexToReplace = 0;
var textures = model._rendererResources.textures;
var oldTexture = textures[textureIndexToReplace];
Cesium.Resource.fetchImage({
url : imagePath
}).then(function(image) {
var newTexture = new Cesium.Texture({
context : viewer.scene.frameState.context,
source : image
});
textures[textureIndexToReplace] = newTexture;
oldTexture.destroy();
});
});
*/
方法现阶段存在的问题
无法更改单个实例的贴图,所有实例的贴图都会同步发生更改
Cesium 动态更换模型贴图方法的更多相关文章
- Unreal Engine 4 动态切割模型实现
转自:http://gad.qq.com/article/detail/33199 <合金装备:复仇>里面,有一个很有趣的设定,游戏里大部分的场景和物件都可以用主角的刀动态切割. UE4中 ...
- 分析业务模型-类图(Class Diagram)
分析业务模型-类图(Class Diagram) 分析业务模型-类图(Class Diagram)(上) 摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并 ...
- 评价指标的局限性、ROC曲线、余弦距离、A/B测试、模型评估的方法、超参数调优、过拟合与欠拟合
1.评价指标的局限性 问题1 准确性的局限性 准确率是分类问题中最简单也是最直观的评价指标,但存在明显的缺陷.比如,当负样本占99%时,分类器把所有样本都预测为负样本也可以获得99%的准确率.所以,当 ...
- 【转】【iOS】动态更换App图标
原文网址:http://www.cocoachina.com/ios/20170619/19557.html 前言 动态更换App图标这件事,在用户里总是存在需求的:有些用户喜欢“美化”自己的手机.至 ...
- u3d动态加入模型
楼层一层一层的加,把模型分开,弄成prefab放到Resourse文件夹里,在代码里用Instantiate(Resources.Load("模型名字") as GameObjec ...
- WPF通过DynamicResource实现给界面动态更换皮肤
在我们的程序中有时候需要去实现动态更换皮肤的效果,从而完成一些个性化的设置,那么我们究竟怎样去实现动态换皮肤的效果呢?那么我们经常用到的就是设置不同的Style,并且在主程序的xaml文件中通过Dyn ...
- 关于2-sat的建图方法及解决方案
转载增减: https://blog.csdn.net/qq_24451605/article/details/47126143 https://blog.csdn.net/u012915516/ar ...
- Unity3D 动态地创建识别图
前面介绍了EasyAR的单图识别,它是提前在Unity设置好图片路径的,那么如果我们的图片是存储在服务器上的,那么我们肯定不能直接把服务的图片地址填上去了.这个时候我们可以动态地创建识别图.步骤如下: ...
- js动态更换img的src问题
在本地开发测试过程中,通过js动态更换img的src没有问题,图片正常切换,但是放在服务器上后测试发现,图片不显示,解决方法为:在对应onclick事件执行切换图片的js函数后加上一个return f ...
随机推荐
- docker的安装,升级,与删除(最新版)
docker安装在ubuntu上 以前叫做 Docker engine安装现在叫做docker-ce的 第一种安装办法: root下执行,sudo su - root apt-get update - ...
- Red Hat Enterprise Linux AS4, C++ OCCI connect Oracle 9i
前提是已经安装好Oracle 9i. 1. 下载对应的ORACLE client安装. http://www.oracle.com/technetwork/database/features/inst ...
- GiBbook实用配置以及插件
GitBook可以在您的计算机上用于构建本地书籍,,可以本地预览 安装gitbook 环境要求: 安装GitBook,您的系统需要安装NodeJS(推荐v4.0.0及以上版本) NodeJS下载地址 ...
- IDEA或Webstorm设置Terminal终端字体大小
File---Settings
- pta寒假作业2
题目二币值转换 题目代码 #include<stdio.h> int main (void) { int n, initial_n; scanf("%d", & ...
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- 从浅入深详解独立ip网站域名恶意解析的解决方案
立IP空间的好处想必大家都能耳熟闻详,稳定性强,利于seo等让大家选择了鼎峰网络香港独立IP空间.那么, 网站独享服务器IP地址,独立IP空间利于百度收录和权重的积累.不受牵连.稳定性强等诸多优势为一 ...
- Vue(小案例_vue+axios仿手机app)_图片列表操作
一.前言 1.让图片还没有被完全加载出来的时候给用户提示 2.图片查看器 二.主要内容 1.让图片还没有被完全加载出来的时候 ...
- Typora使用说明(记录总结)
目录 区域元素 YAML FONT Matters 菜单 段落 标题 引注 序列 可选序列 代码块 数学块 表格 脚注 水平线 特征元素 链接 超链接 内链接 相关链 URLs 图片 斜体 加粗 删除 ...
- MD1——2 Corner
基本句型 被分为 5 种全然因为[动词] 造成的. 那么补语 就是因为 动词被解释成“是”的时候所需要的一种补足. [补语 Complement 传统的毒瘤说法] 不完全不及物动词 不完全及物动词~~ ...