怎样载入纹理

// 首先, 创建一个纹理

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. 【IOI1998】Polygon 区间DP

    题意翻译 题目可能有些许修改,但大意一致 多边形是一个玩家在一个有n个顶点的多边形上的游戏,如图所示,其中n=4.每个顶点用整数标记,每个边用符号+(加)或符号*(乘积)标记. 第一步,删除其中一条边 ...

  2. PHP-7.1 源代码学习:字节码在 Zend 虚拟机中的解释执行 之 概述

    本文简要介绍 zend 虚拟机解释执行字节码的基本逻辑以及相关的数据结构,关于 PHP 源代码的下载,编译,调试可以参考之前的系列文章 execute_ex 我们来看看执行一个简单的脚本 test.p ...

  3. [adb 学习篇] python将adb命令集合到一个工具上

    https://testerhome.com/topics/6938 qzhi的更全面,不过意思是一样的,另外补充一个开源的https://github.com/264768502/adb_wrapp ...

  4. PHP变量的生命周期

    变量不仅有其特定的作用范围,还有其存活的周期--生命周期.变量的生命周期指的是变量可被使用的一个时间段,在这个时间段内变量是有效的,一旦超出这个时间段变量就会失效,我们就不能够再访问到该变量的值了. ...

  5. Timer和TimerTask详解

    1.概览 Timer是一种定时器工具,用来在一个后台线程计划执行指定任务.它可以计划执行一个任务一次或反复多次.TimerTask一个抽象类,它的子类代表一个可以被Timer计划的任务. 简单的一个例 ...

  6. hdu6098[RMQ+筛法] 2017多校6

    /*hdu6098[RMQ+筛法] 2017多校6*/ #include <bits/stdc++.h> using namespace std; ][], len[], a[]; voi ...

  7. 【CF52C】Circular RMQ(线段树区间加减,区间最值)

    给定一个循环数组a0, a1, a2, …, an-1,现在对他们有两个操作: Inc(le, ri, v):表示区间[le, ri]范围的数值增加v Rmq(le, ri):表示询问区间[le, r ...

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

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

  9. 标准C程序设计七---60

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

  10. 拼题 L2-001 紧急救援 最短路计数+记录路径

    https://pintia.cn/problem-sets/994805046380707840/problems/994805073643683840 L2-001 紧急救援 (25 分)   作 ...