本机上使用Three.js载入纹理
怎样载入纹理
var mapUrl = "../images/molumen_small_funny_angry_monster.jpg";
var map = THREE.ImageUtils.loadTexture(mapUrl);
//然后, 创建phong 材质来显示光影效果,把纹理传给该材质
var material = new THREE.MeshPhongMaterial({ map: map });
// 创建几何对象
var geometry = new THREE.CubeGeometry(1, 1, 1);
// 把几何体对象和纹理材质整合到一个面片集合中
cube = new THREE.Mesh(geometry, material);
怎样使用本地文件
WebGL默认情况下不同意使用本机上的纹理、模型文件的。
假设你仅仅是在使用WebGL绘制几何图形什么的,没有纹理载入直接点击html文件以文件协议訪问就可以。地址栏显示的格式如右:file:///C:/dir/to/example.html
载入外部文件
若想载入外部模型和纹理文件,由于同源策略的安全限制从文件系统载入文件会由于安全异常而失败。
只是有两个办法能够解决:
1、减少浏览器的安全级别
2、在本机上建立一个server。把外部文件放到该server作为网络文件訪问。
If you use option 1, be aware that you may open yourself to some vulnerabilities if using the same browser for a regular web surfing. You may want to create a separate browser profile / shortcut used just for local development to be safe.
Change local files security policy
Safari
Enable the develop menu using the preferences panel, under Advanced -> "Show develop menu in menu bar"
Then from the safari "Develop" menu, select "Disable local file restrictions", it is also worth noting safari has some odd behaviour with caches, so it is advisable to use the "Disable caches" option in the same menu; if you are editing & debugging using safari.
Chrome
Close all running chrome instances first. Then start Chrome executable with a command line flag:
chrome --allow-file-access-from-files
On Windows, the easiest is probably to create a special shortcut which has added flag (right-click on shortcut -> properties -> target).
Firefox
Go to about:config
Find security.fileuri.strict_origin_policy parameter
Set it to false
Run local server
The simplest probably is to use Python's built-in http server.
If you have Python installed, it should be enough to run this from a command line:
# Python 2.x
python -m SimpleHTTPServer
# Python 3.x
python -m http.server
This will serve files from the current directory at localhost under port 8000:
http://localhost:8000/
If you have Ruby installed, you can get the same result running this instead:
ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"
PHP also has a built-in web server, starting with php 5.4.0:
php -S localhost:8000
Node.js has a simple HTTP server package. To install:
npm install http-server -g
To run:
http-server .
Other simple alternatives are discussed here on Stack Overflow.
Of course, you can use any other regular full-fledged web server like Apache or nginx.
Example with lighttpd, which is a very lightweight general purpose webserver (on MAC OSX):
Install it via homebrew brew install lighttpd
Create a configuration file called lighttpd.conf in the directory where you want to run your webserver. There is a sample in this page.
In the conf file, change the server.document-root with the directory you want to serve
Start it with lighttpd -f lighttpd.conf
Navigate to http://localhost:3000/ and it will serve static files from the directory you chose.
本机上使用Three.js载入纹理的更多相关文章
- Arcgis for js载入天地图
综述:本节讲述的是用Arcgis for js载入天地图的切片资源. 天地图的切片地图能够通过esri.layers.TiledMapServiceLayer来载入.在此将之进行了一定的封装,例如以下 ...
- three.js 加入纹理(texture)的方法及注意事项
var texture = new THREE.TextureLoader().load( './img/1.png' ); var box_show = new THREE.CubeGeometry ...
- 解密javascript模块载入器require.js
require.config require.config设置require.js模板载入选项 // 定义config req.config = function (config) { return ...
- threejs深入纹理,立体场景cubeResolution(四)
在这个课程里主要完成讲解两个demo: 一个是电视墙:用视频做纹理 一,用视频做纹理 首先我们用video标签把视频源引入: <video id="video" autopl ...
- cocos2dx 纹理优化
description: 为什么要谈纹理的问题,游戏的画面无时无刻不充斥着图像,通俗意义上一款精致的游戏都有着非常精美的画面.这样往往能给玩家带来更好的游戏体验,这一点也是对于游戏制作者来说所尽力追求 ...
- js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf
Js 问题分析--js 影响页面性能现状分析:问题陈述分析问题:抽象问题根源,通过实例或推理证明问题的严重性问题引申:以现有问题为点开始扩散,这将导致其它什么问题,或同一类型的问题问题总结:从分散开始 ...
- 折腾一两天,终于学会使用grunt压缩合并混淆JS脚本,小激动,特意记录一下+spm一点意外收获
很长时间没有更新博客了,实在是太忙啦...0.0 ,以下的东西纯粹是记录,不是我原创,放到收藏夹还担心不够,这个以后常用,想来想去,还是放到这里吧,,丢不了..最后一句废话,网上搜集也好原创也罢,能解 ...
- grunt压缩js文件
grunt是node中很好的管理项目的工具,利用它可以实现对整个项目的管理,避免很多重复性的工作如合并.压缩,检查语法等. 使用grunt首先要安装node环境,nodejs官网http://node ...
- IOS 中openGL使用教程3(openGL ES 入门篇 | 纹理贴图(texture)使用)
在这篇文章中,我们将学习如何在openGL中使用纹理贴图. penGL中纹理可以分为1D,2D和3D纹理,我们在绑定纹理对象的时候需要指定纹理的种类.由于本文将以一张图片为例,因此我们为我们的纹理对象 ...
随机推荐
- SCOI 2010 滑雪
题目描述 a180285非常喜欢滑雪.他来到一座雪山,这里分布着 MM 条供滑行的轨道和 NN 个轨道之间的交点(同时也是景点),而且每个景点都有一编号 ii ( 1 \le i \le N1≤i≤N ...
- grunt-nodemon参数配置
grunt-nodemon参数配置 nodemon0.2.0版本后参数名称做了较大改动,调整了下nodemon的参数配置,有需要的同学可以参考下: 1 2 3 4 5 6 7 8 9 10 11 12 ...
- 安装adb工包
下载android sdk (很大) 从D:\AndroidSdk\platform-tools目录可以看到: 将adb工具包: adb.exe,AdbWinapi.dll,AdbWinUSBapi. ...
- 二进制<1>
Matrix67:位运算简介及实用技巧(一) 基础篇 什么是位运算? 程序中的所有数在计算机内存中都是以二进制的形式储存的.位运算说穿了,就是直接对整数在内存中的二进制位进行操作.比如,and运 ...
- sklearn python API
sklearn python API LinearRegression from sklearn.linear_model import LinearRegression # 线性回归 # modul ...
- SJTU Summer Camp
Day -2,-1 提前坐飞机来到了上海,在旁边的酒店住下来,晚上去了外滩,在黄浦江边吹着晚风,依旧感慨万千,在衡中高三的一年竟然已经过去,经常出现在噩梦中的高考也已成为历史,然而命运可能并未就此改变 ...
- How to resolve mysql problem when you get code 2003(10061) and 1130
When I use Navicate to connect to mysql on Ubuntu, I got message 2003(10061) firstly. To resovle thi ...
- UVa11361 Investigating Div-Sum Property
数位DP f[位数][自身模k余数][各位数字之和模k余数][当前位是否有上限]=方案数 k<10000,空间不够,如何优化? 不必优化,2^31以内,数字最多只有10位,各位数字之和最多为99 ...
- Atcoder CODE FESTIVAL 2017 qual B D - 101 to 010 dp
题目链接 题意 对于一个\(01\)串,如果其中存在子串\(101\),则可以将它变成\(010\). 问最多能进行多少次这样的操作. 思路 官方题解 转化 倒过来考虑. 考虑,最终得到的串中的\(' ...
- serializeObject 的应用
function sendForm() { var invOrderModelWrapper = {}; // 头 var objHeader = $('#invOrderForm').seriali ...