三个J中图像未加载到planeGeometry上

发布于 2025-01-12 02:24:04 字数 3126 浏览 2 评论 0原文

社区您好 我有 1 个关于图像未显示在 三个 JS 中的 PlaneGeometry 上的问题。每当我加载图像时,飞机都会变黑,并且此处不会进行图像反射,并且控制台中不会显示任何错误。

请给我正确的直接信息,我可以在planeGeometry上加载图像。

黑盒是 PlaneGeometry,白盒也是 PlaneGeometry

function init(){
console.log("inner Function");

const canvas = document.querySelector('#c');

// renderer
const renderer = new THREE.WebGLRenderer({
    canvas,
    alpha: true,
});
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild(renderer.domElement);
    
// Scene
const scene = new THREE.Scene();

// camera
const camera = new THREE.PerspectiveCamera(
    60, 
    window.innerWidth / window.innerHeight, 
    1, 
    1000
    );
    camera.position.set(0, 0, 4);

// Load image locally method-1
// const textureLoader = new THREE.TextureLoader();
// scene.background = textureLoader.load('../asset/Backgound.png');

// Load Image method-2
// const textureLoader = new THREE.TextureLoader();
// loader.load('./asset/Backgound.png' , function(texture)
//             {
//             scene.background = textureLoader;  
//             });

const planeGeometry = new THREE.PlaneGeometry(2, 2);
// const texture = new THREE.TextureLoader().load('./asset/Set.png');
// const planeMaterial = new THREE.MeshBasicMaterial({color: 0xffffff});
// const planeMaterial = new THREE.MeshBasicMaterial({map: texture});
// const planeMaterial = new THREE.MeshBasicMaterial({color: "rgb(100%, 0%, 0%)"});

const planeMaterial = new THREE.MeshBasicMaterial({
    color: "#fafafa",
    side: THREE.DoubleSide,
    // visible: false,
});

// const planeMaterial = new THREE.MeshLambertMaterial({map: new THREE.TextureLoader().load("./asset/Set.png") })

const plane = new THREE.Mesh(planeGeometry, planeMaterial);
scene.add(plane)

plane.position.x = 1.5
plane.position.y = -0.7
// plane.position.z = -4

// const textureImage = '../asset/ping_pong_ball.png';
const texture2 = new THREE.TextureLoader().load('./asset/ping_pong_ball.png');

const plane2Geometry = new THREE.PlaneGeometry(2, 2);
// // const plane2Material = new THREE.MeshBasicMaterial({color: 0xffffff});
// var img = new THREE.MeshBasicMaterial({ //CHANGED to MeshBasicMaterial
//     map:THREE.ImageUtils.loadTexture('./asset/Set.png')
//     // map:THREE.TextureLoader('../asset/ping_pong_ball.png')
// });
// img.map.needsUpdate = true; //ADDED

const plane2Material = new THREE.MeshBasicMaterial({map: texture2});
const plane2 = new THREE.Mesh(plane2Geometry, plane2Material);
plane2.overdraw = true;
scene.add(plane2);

plane2.position.x = -1.5
plane2.position.y = -0.7

// const axesHelper = new THREE.AxesHelper(10);
// scene.add(axesHelper);



renderer.render(scene, camera)

window.addEventListener('resize', function(){
    camera.aspect = window.innerWidth /window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight)

})

} 初始化();

在此图像中,黑色平面实际上存在图像,但由于图像加载,平面变为黑色请帮忙。

Hello Community
I have 1 issue Regarding Image is not showing on the PlaneGeometry in Three JS. Whenever i am load image the plane is going to black and not image refection is done here and with it no error are showing in console.

Please Give me Right Direct though which i can load image on planeGeometry.

Black Box is PlaneGeometry and white Box is also PlaneGeometry

function init(){
console.log("inner Function");

const canvas = document.querySelector('#c');

// renderer
const renderer = new THREE.WebGLRenderer({
    canvas,
    alpha: true,
});
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild(renderer.domElement);
    
// Scene
const scene = new THREE.Scene();

// camera
const camera = new THREE.PerspectiveCamera(
    60, 
    window.innerWidth / window.innerHeight, 
    1, 
    1000
    );
    camera.position.set(0, 0, 4);

// Load image locally method-1
// const textureLoader = new THREE.TextureLoader();
// scene.background = textureLoader.load('../asset/Backgound.png');

// Load Image method-2
// const textureLoader = new THREE.TextureLoader();
// loader.load('./asset/Backgound.png' , function(texture)
//             {
//             scene.background = textureLoader;  
//             });

const planeGeometry = new THREE.PlaneGeometry(2, 2);
// const texture = new THREE.TextureLoader().load('./asset/Set.png');
// const planeMaterial = new THREE.MeshBasicMaterial({color: 0xffffff});
// const planeMaterial = new THREE.MeshBasicMaterial({map: texture});
// const planeMaterial = new THREE.MeshBasicMaterial({color: "rgb(100%, 0%, 0%)"});

const planeMaterial = new THREE.MeshBasicMaterial({
    color: "#fafafa",
    side: THREE.DoubleSide,
    // visible: false,
});

// const planeMaterial = new THREE.MeshLambertMaterial({map: new THREE.TextureLoader().load("./asset/Set.png") })

const plane = new THREE.Mesh(planeGeometry, planeMaterial);
scene.add(plane)

plane.position.x = 1.5
plane.position.y = -0.7
// plane.position.z = -4

// const textureImage = '../asset/ping_pong_ball.png';
const texture2 = new THREE.TextureLoader().load('./asset/ping_pong_ball.png');

const plane2Geometry = new THREE.PlaneGeometry(2, 2);
// // const plane2Material = new THREE.MeshBasicMaterial({color: 0xffffff});
// var img = new THREE.MeshBasicMaterial({ //CHANGED to MeshBasicMaterial
//     map:THREE.ImageUtils.loadTexture('./asset/Set.png')
//     // map:THREE.TextureLoader('../asset/ping_pong_ball.png')
// });
// img.map.needsUpdate = true; //ADDED

const plane2Material = new THREE.MeshBasicMaterial({map: texture2});
const plane2 = new THREE.Mesh(plane2Geometry, plane2Material);
plane2.overdraw = true;
scene.add(plane2);

plane2.position.x = -1.5
plane2.position.y = -0.7

// const axesHelper = new THREE.AxesHelper(10);
// scene.add(axesHelper);



renderer.render(scene, camera)

window.addEventListener('resize', function(){
    camera.aspect = window.innerWidth /window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight)

})

}
init();

in This image where is black plane the actually there is image but due to image load the plane is change to black color please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文