怎样载入纹理

// 首先, 创建一个纹理

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. TensorFlow学习笔记(6):TensorBoard之Embeddings

    本文基于TensorFlow官网的How-Tos写成. TensorBoard是TensorFlow自带的一个可视化工具,Embeddings是其中的一个功能,用于在二维或三维空间对高维数据进行探索. ...

  2. Python hash、xml、configparser、sheve、shutil模块讲解 以及 面向对象初识

    今日内容: 1.hash模块2.xml模块3.configparser模块4.sheve 模块5.shutil模块 知识点一:hash什么是hash: hash是一种算法,该算法接受传入的的内容,经过 ...

  3. hdu6035[dfs+思维] 2017多校1

    /*hdu6035[dfs+思维] 2017多校1*/ //合并色块, 妙啊妙啊 #include<bits/stdc++.h> using namespace std; ; const ...

  4. 用Javascript实现图片的缓慢缩放效果

    <body> <!--页面布局:一张图片两个按钮--> <div style = "width:400px;margin:0 auto"> &l ...

  5. POJ——1195Mobile phones(二维树状数组点修改矩阵查询)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 17764   Accepted: 8213 De ...

  6. 刷题总结——棘手的操作(bzoj2333)

    题目: 题目背景 SCOI2011 DAY2 T1 题目描述 有 N 个节点,标号从 1 到 N ,这 N 个节点一开始相互不连通.第i个节点的初始权值为 a[i] ,接下来有如下一些操作:U x y ...

  7. Windows cmd 生成目录结构 dir /b,tree /f,xcopy

    >dir *.sh *.ksh *.java /s/b > list.txt >tree /f > list.txt >xcopy C:\folder\from_fold ...

  8. P1266 速度限制 (最短路,图论)

    题目链接 Solution 在最短路转移的时候在队列或者堆中记录状态为 \(f[u][v]\) 代表上一个节点为 \(u\) ,速度为 \(v\) . 然后按部就班转移即可... Code #incl ...

  9. linux监控平台搭建-cpu

    linux监控平台搭建-cpu 目前服务器的主流CPU是intel或者AMD.到底主频是什么.多核.多线程.并发.并行.超频.一级缓存.二级缓存.三级缓存.i386.x86 cpu:含有算术逻辑.控制 ...

  10. Linux System Programming 学习笔记(七) 线程

    1. Threading is the creation and management of multiple units of execution within a single process 二 ...