User uploaded textures in three.js

后端 未结 3 607
-上瘾入骨i
-上瘾入骨i 2021-01-05 20:17

Here you will find a jsFiddle adaptation of the problem.

I would like to create a 3d web application in which the user is able to select an image file on their local

3条回答
  •  没有蜡笔的小新
    2021-01-05 20:45

    The solution actually turns out to be commonly used to preview local images prior to, say, uploading them a server. The image you are trying to render is converted to a data url where restrictions about cross origin policies do not apply. The corrected code is located here. What follows is the meat of it:

    userImage = $("#userImage")[0];
    if (userImage.files && userImage.files[0]) {
        var reader = new FileReader();
    
        reader.onload = function (e) {
            image.src = e.target.result;
        };
    
        reader.readAsDataURL(userImage.files[0]);
    }
    

提交回复
热议问题