Three.js_加载透明贴图模型

本文介绍了如何使用Three.js库加载带有透明贴图的3D模型,通过关键代码展示实现透明效果的过程,并提供了完整的源码供读者参考。
摘要由CSDN通过智能技术生成

关键代码

var texture= THREE.ImageUtils.loadTexture("000874.png", null, function(t) {
   });
      // 基础Basic网格材质,不受光照影响   Phong网格材质受光照影响
      obj.children[0].material= new THREE.MeshBasicMaterial({
   
//         map:texture,//设置颜色纹理贴图
            map: texture,transparent: true,side:THREE.DoubleSide
      })

	  
	  obj.traverse(function(child)
	  {
   
	                  if (child instanceof THREE.Mesh)
	                  {
   
	                      //将贴图赋于材质
	                      child.material.map = texture;
	                      //重点,没有该句会导致PNG无法正确显示透明效果
	                      child.material.transparent = true;
	                      child.material.alphaTest = 0.7;
                          child.material.depthWrite = true;
	                  }
	   });
	  
      scene.add(obj);
      obj.children[0].scale.set(8,8,8);//网格模型缩放
    });

在这里插入图片描述

全部源码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta http-equiv="x-ua-compatible" content="IE=edge" />


    <title>文物鉴赏</title>
    <style>
        *{
   
            touch-action: none;
            touch-action: pan-y;
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值