zoukankan      html  css  js  c++  java
  • 本机上使用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 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.

  • 相关阅读:
    football statistics
    频繁模式挖掘 Apriori算法 FP-tree
    回首页---用通用底部栏,不用回退键,且多次点击,刷新首页
    对剪切板的失控异常的处理---多半的时间再处理剪切板的失控---冗余操作
    登陆
    搜狗输入法APP的2个剪切板内容获取入口
    实现对屏幕指定内容的操作
    定时删除clientmqueue
    局部优化与整体效果 新增时间>节省时间 权衡利弊
    实时系统的目标
  • 原文地址:https://www.cnblogs.com/yxysuanfa/p/6858182.html
Copyright © 2011-2022 走看看