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 ...
随机推荐
- HTML- 标签语法
HTML 标签语言 概念 超文本标记语言, 是一种用于创建网页的标记语言 ps: 不是编程语言 利用标签来描述网页 扩展名:.html .htm 语法规范 标签不区分大小写, 推荐小写 双标签必须写 ...
- ant在windows及linux环境下安装
ant下载 http://ant.apache.org/ https://ant.apache.org/bindownload.cgi 历史版本 ant在windows下安装 解压到D盘 新建系统变量 ...
- day08读取文件
可参考;https://www.cnblogs.com/gengcx/p/6713646.html主要内容: 1.只读 2.只写 3.追加 4.r+读写 5.w+写读 6.a+写读 7.其他一.使用p ...
- 简单的实现HTTP密码验证登陆
1.首先需要安装 httpd-tools yum install -y httpd-tools 2.安装完成后设置用户名密码,我这里用的是NGINX htpasswd -bc /mypath/ngin ...
- Ajax与JSON共同使用的小实例
实现的效果: 点击“点击”按钮,可以通过Ajax从服务器调过来相应的文档文件,而不需重新加载页面. 通过json可以将调过来的文档(String)转换为相应的json对象,从而对文档中数据进行操作. ...
- Fiddler状态栏
Fiddler状态栏显示了Fiddler的一些配置信息,我们也可以点击这些配置信息进行快速配置. 以下图为例: 状态栏一共显示了四项信息:1.Capturing/空:2.过滤进程类型:3.Web Se ...
- Linux记录-open-falcon开源监控系统部署
参考https://book.open-falcon.org/zh_0_2/quick_install/prepare.html一.安装后端1.环境准备yum -y install redisyum ...
- Dubbo学习笔记8:Dubbo的线程模型与线程池策略
Dubbo默认的底层网络通讯使用的是Netty,服务提供方NettyServer使用两级线程池,其中 EventLoopGroup(boss) 主要用来接受客户端的链接请求,并把接受的请求分发给 Ev ...
- [物理学与PDEs]第5章习题7 各向同性材料时稳定性条件的等价条件
在线性弹性时, 证明各向同性材料, 稳定性条件 (5. 27) 等价于 Lam\'e 常数满足 $$\bex \mu>0,\quad \lm+\cfrac{2}{3}\mu>0. \ee ...
- linux 远程 telnet
linux 远程 telnet [ root@test1 ~]# yum install telnet* (安装的三个包 xinetd . telnet-server.telnet) [ roo ...