怎样载入纹理

// 首先, 创建一个纹理

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 Up and Running by Tony Parisi

怎样使用本地文件

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载入纹理的更多相关文章

  1. Arcgis for js载入天地图

    综述:本节讲述的是用Arcgis for js载入天地图的切片资源. 天地图的切片地图能够通过esri.layers.TiledMapServiceLayer来载入.在此将之进行了一定的封装,例如以下 ...

  2. three.js 加入纹理(texture)的方法及注意事项

    var texture = new THREE.TextureLoader().load( './img/1.png' ); var box_show = new THREE.CubeGeometry ...

  3. 解密javascript模块载入器require.js

    require.config require.config设置require.js模板载入选项 // 定义config req.config = function (config) { return ...

  4. threejs深入纹理,立体场景cubeResolution(四)

    在这个课程里主要完成讲解两个demo: 一个是电视墙:用视频做纹理 一,用视频做纹理 首先我们用video标签把视频源引入: <video id="video" autopl ...

  5. cocos2dx 纹理优化

    description: 为什么要谈纹理的问题,游戏的画面无时无刻不充斥着图像,通俗意义上一款精致的游戏都有着非常精美的画面.这样往往能给玩家带来更好的游戏体验,这一点也是对于游戏制作者来说所尽力追求 ...

  6. js 的一些知识 摘自http://img0.pconline.com.cn/Pc_intranet/1105/13/313647_7.pdf

    Js 问题分析--js 影响页面性能现状分析:问题陈述分析问题:抽象问题根源,通过实例或推理证明问题的严重性问题引申:以现有问题为点开始扩散,这将导致其它什么问题,或同一类型的问题问题总结:从分散开始 ...

  7. 折腾一两天,终于学会使用grunt压缩合并混淆JS脚本,小激动,特意记录一下+spm一点意外收获

    很长时间没有更新博客了,实在是太忙啦...0.0 ,以下的东西纯粹是记录,不是我原创,放到收藏夹还担心不够,这个以后常用,想来想去,还是放到这里吧,,丢不了..最后一句废话,网上搜集也好原创也罢,能解 ...

  8. grunt压缩js文件

    grunt是node中很好的管理项目的工具,利用它可以实现对整个项目的管理,避免很多重复性的工作如合并.压缩,检查语法等. 使用grunt首先要安装node环境,nodejs官网http://node ...

  9. IOS 中openGL使用教程3(openGL ES 入门篇 | 纹理贴图(texture)使用)

    在这篇文章中,我们将学习如何在openGL中使用纹理贴图. penGL中纹理可以分为1D,2D和3D纹理,我们在绑定纹理对象的时候需要指定纹理的种类.由于本文将以一张图片为例,因此我们为我们的纹理对象 ...

随机推荐

  1. 使用SpringMVC参数传递时,解决get请求时中文乱码的问题

    问题描述: 使用SpringMVC参数传递时, 遇到get请求中文信息时,页面应答会显示中文乱码. 解决办法: 一,  我们需要把request.getParameter(“参数名”)获取到的字符串先 ...

  2. Spider爬虫-get、post请求

    1:概念: 爬虫就是通过编写程序,模拟浏览器上网,然后让其去互联网上抓取数据的过程. 2:python爬虫与其他语言的比较: (1)php爬虫弊端:多进程多线程支持的不好 (2)java:代码臃肿,重 ...

  3. AtCoder Regular Contest 091

    数学场,做到怀疑人生系列 C - Flip,Flip, and Flip...... Time limit : 2sec / Memory limit : 256MB Score : 300 poin ...

  4. C遇到的编译错误整理

    1: Permission denied collect2.exe: error: ld returned exit status c:/mingw/bin/../lib/gcc/mingw32/6. ...

  5. ACM程序设计选修课——Problem E:(ds:图)公路村村通(优先队列或sort+克鲁斯卡尔+并查集优化)

    畅通工程 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  6. 学习javascript设计模式之代理模式

    1.代理模式为一个对象提供一个代用品或占位符,以便控制对它的访问. 2.不用代理模式: 客户 -> 本体  使用代理模式:  客户 -> 代理 -> 本体 3.例子场景1 点击操作与 ...

  7. vue.js源码学习分享(五)

    //配置项var config = { /** * Option merge strategies (used in core/util/options)//选项合并策略 */ optionMerge ...

  8. 【Visual Studio】Windows program compatibility mode is on, turn it off……

    [问题描述]Windows 10上安装 Visual Studio Ultimate 2013,出现下面错误: [解决方案]将.iso文件解压到硬盘再安装.

  9. 《Linux命令行与shell脚本编程大全 第3版》

    第一部分 Linux 命令行 第1章  初识Linux she1.1   什么是Linux 21.1.1 深入探究Linux 内核 31.1.2 GNU 工具 61.1.3 Linux 桌面环境 81 ...

  10. 标准C程序设计七---72

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...