我與three.js一起去。我想將圖像作爲紋理應用於對象,但由於某種原因,當我應用圖像時,我似乎只能獲得圖像的主色。我環顧網絡,找不到有類似問題的人。Three.js使用圖像主色而不是圖像本身
你可以從JSON文件看,我利用「mapDiffuse」可變圖像試過,然後我嘗試使用的代碼應用的質地和我得到相同的結果
這將在JSON對象文件:
{
"metadata" :
{
"formatVersion" : 3.1,
"sourceFile" : "newBox.obj",
"generatedBy" : "OBJConverter",
"vertices" : 8,
"faces" : 6,
"normals" : 6,
"colors" : 0,
"uvs" : 0,
"materials" : 1
},
"scale" : 1.000000,
"materials": [ {
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "Material.002",
"colorDiffuse" : [0.64, 0.64, 0.64],
"colorSpecular" : [0.5, 0.5, 0.5],
"illumination" : 2,
"mapDiffuse" : "test.JPG",
"opacity" : 1.0,
"opticalDensity" : 1.0,
"specularCoef" : 96.078431
}],
"vertices": [1.000000,-1.000000,-1.000000,1.000000,-1.000000,1.000000,-1.000000,-1.000000,1.000000,-1.000000,-1.000000,-1.000000,1.000000,1.000000,-0.999999,0.999999,1.000000,1.000001,-1.000000,1.000000,1.000000,-1.000000,1.000000,-1.000000],
"morphTargets": [],
"morphColors": [],
"normals": [0,-1,0,0,1,0,1,0,0,-0,-0,1,-1,-0,-0,0,0,-1],
"colors": [],
"uvs": [[]],
"faces": [35,0,1,2,3,0,0,0,0,0,35,4,7,6,5,0,1,1,1,1,35,0,4,5,1,0,2,2,2,2,35,1,5,6,2,0,3,3,3,3,35,2,6,7,3,0,4,4,4,4,35,4,0,3,7,0,5,5,5,5]
}
這是我的javascript:
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer({alpha:true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
var mesh;
/**
* Texture
*/
var texture = THREE.ImageUtils.loadTexture("/files/test/Three-js-examples-images-crate.jpg");
var material = new THREE.MeshBasicMaterial({ map : texture });
// instantiate a loader
var loader = new THREE.JSONLoader();
// load a resource
loader.load(
// resource URL
'/files/test/untitled.json',
// Function when resource is loaded
function (geometry) {
mesh = new THREE.Mesh(geometry,material);
mesh.scale.x = 0.8;
mesh.scale.y = 0.8;
mesh.scale.z = 0.8;
scene.add(mesh);
}
);
camera.position.z = 5;
function render() {
requestAnimationFrame(render);
mesh.rotation.x += 0.0001;
mesh.rotation.y += 0.01;
renderer.render(scene, camera);
}
render();
這是我得到的結果(從Photoshop其streched)
這是我想用
這是我可以在攪拌機內指定的東西嗎? – Vilius
是的。快速搜索會出現一系列教程。 – user01