web上构建3d效果 基于three.js的实例

这篇具有很好参考价值的文章主要介绍了web上构建3d效果 基于three.js的实例。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

web页面上提供3D效果,可以为页面提供不少色彩,H5之后canvas 为webgl提供了基础,使得在web页面使用JS也能写出3D的效果,其中three.js作为封装了图形函数 的框架,为入门提供了方便,效果图如下。

web上构建3d效果 基于three.js的实例

 web上构建3d效果 基于three.js的实例web上构建3d效果 基于three.js的实例

以上是官方例子中其中的三个,没接触过的朋友肯定会觉得很神奇,事实上three.js能做的远不止这些,入门容易,如果灵活运用到项目中就只能看各自的发挥了。

下面这个是自己做的一个项目中的效果

web上构建3d效果 基于three.js的实例

 地图JSON如下,自己封装了对室内墙体生成的封装,后期有空会详细讲解。

绘制3D室内 案例

var zallMap2 = [
    {
        title: '',
        floorType:floorTypes[1],
        x: 0,
        y: 80,
        z: 0,
        width: 962,
        height: 866,
        color: "#142B46",
        textcolor: "black",
        bordercolor: "rgba(76, 181, 216, 0.85)",
        imageurl: 'images/Escalator.png',
    },
    {
        title: '',
        x: 480,
        y: 80,
        z: 0,
        width: 2,
        height: 866,
        color: "#30B2BB",
        textcolor: "black",
        bordercolor: "rgba(76, 181, 216, 0.85)",
        bspMesh: [

            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 82,
                width: 38,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 17,
                width: 2,
                height: 73.7,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 120,
                width: 38,
                height: 5,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 187.5,
                width: 2,
                height: 106.5,
                positionY: 0,
            },
             {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 213,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 26.5,
                y: 80,
                z: 213,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 270,
                width: 11.5,
                height: 2,
                positionY: 0,
            }, 
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 26.5,
                y: 80,
                z: 270,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 270,
                width: 2,
                height: 92,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 360,
                width: 36,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 360,
                width: 2,
                height: 59,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 402,
                width: 17,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 66,
                y: 80,
                z: 402,
                width: 2,
                height: 30,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 431,
                width: 2,
                height: 18,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 462,
                width: 36,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 461,
                width: 2,
                height: 69,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 525,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 26.5,
                y: 80,
                z: 525,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 648,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 26.5,
                y: 80,
                z: 648,
                width: 11.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 648,
                width: 2,
                height: 106.5,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 738,
                width: 36,
                height: 5,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 0,
                y: 80,
                z: 779,
                width: 36,
                height: 2,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 36,
                y: 80,
                z: 772,
                width: 2,
                height: 73.5,
                positionY: 0,
            },
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 17,
                width: 2,
                height: 73.5,
                positionY: 0,
            },
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 82,
                width: 38,
                height: 2,
                positionY: 0,
            }, 
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 108.5,
                width: 2,
                height: 106.5,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 120,
                width: 38,
                height: 5,
                positionY: 0,
            },  
                {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 213,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
                {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 950.5,
                y: 80,
                z: 213,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            
                {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 269,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            
                {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 950.5,
                y: 80,
                z: 269,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
                    {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 269,
                width: 2,
                height: 149,
                positionY: 0,
            },  
                    {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 359,
                width: 38,
                height: 2,
                positionY: 0,
            },  
                    {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 909,
                y: 80,
                z: 401,
                width: 17,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 896,
                y: 80,
                z: 401,
                width: 2,
                height: 30,
                positionY: 0,
            },  
                {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 430,
                width: 2,
                height: 18,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 460,
                width: 38,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 459,
                width: 2,
                height: 69,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 526,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 950.5,
                y: 80,
                z: 526,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 649,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 950.5,
                y: 80,
                z: 649,
                width: 11.5,
                height: 2,
                positionY: 0,
            },  
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 649,
                width: 2,
                height: 106.5,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 739,
                width: 38,
                height: 5,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 773.5,
                width: 2,
                height: 73.5,
                positionY: 0,
            }, 
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 924,
                y: 80,
                z: 780,
                width: 38,
                height: 2,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 400,
                y: 80,
                z: 0,
                width: 2,
                height: 42,
                positionY: 0,
            }, 
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 400,
                y: 80,
                z: 40,
                width: 172,
                height: 2,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 570,
                y: 80,
                z: 0,
                width: 2,
                height: 42,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 400,
                y: 80,
                z: 824,
                width: 2,
                height: 42,
                positionY: 0,
            }, 
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 400,
                y: 80,
                z: 824,
                width: 172,
                height: 2,
                positionY: 0,
            }, 
            
            {
                type: 'union',
                geometryType: 'box', color: '#fff',

                x: 570,
                y: 80,
                z: 824,
                width: 2,
                height: 42,
                positionY: 0,
            },
            
            
            
            
            
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 480,
                y: 80,
                z: 141.5,
                width: 2,
                height: 37.6,
                positionY: 0,
            },
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 480,
                y: 80,
                z: 374.2,
                width: 2,
                height: 37.6,
                positionY: 0,
            },
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 480,
                y: 80,
                z: 454.6,
                width: 2,
                height: 37.6,
                positionY: 0,
            },
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 480,
                y: 80,
                z: 686,
                width: 2,
                height: 45,
                positionY: 0,
            }]
    },
    {
        title: '',
        x: 0,
        y: 80,
        z: 432,
        width: 962,
        height: 2,
        color: "#30B2BB",
        textcolor: "black",
        bordercolor: "rgba(76, 181, 216, 0.85)",
        bspMesh: [
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 72.8,
                y: 80,
                z: 432,
                width: 37.8,
                height: 2,
                positionY: 0,
            },
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 420,
                y: 80,
                z: 432,
                width: 37.5,
                height: 2,
                positionY: 0,
            },
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 502.5,
                y: 80,
                z: 432,
                width: 37.5,
                height: 2,
                positionY: 0,
            }
            ,
            {
                type: 'subtract',//门
                geometryType: 'box', color: '#fff',

                x: 848,
                y: 80,
                z: 432,
                width: 40,
                height: 2,
                positionY: 0,
            }
        ]
    },
    {
        title: '',//wall 一层北墙体
        x: 0,
        y: 80,
        z: 0,
        width: 962,
        height: 2,
        color: "#30B2BB",
        textcolor: "black",
    },
    {
        title: '',//wall 西
        x: 0,
        y: 80,
        z: 2,
        width: 2,
        height: 864,
        color: "#30B2BB",
        textcolor: "black",
       
    }
    ,
    {
        title: '',//wall 东
        x: 960,
        y: 80,
        z: 0,
        width: 2,
        height: 864,
        color: "#30B2BB",
        textcolor: "black",
    }
    ,
    {
        title: '',//wall 南
        x: 0,
        y: 80,
        z: 864,
        width: 962,
        height: 2,
        color: "#30B2BB",
        textcolor: "black",
   
    }
];文章来源地址https://www.toymoban.com/news/detail-454040.html

到了这里,关于web上构建3d效果 基于three.js的实例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Three.js中的3D文字效果

    Three.js中的3D文字效果

    对于一些设计网页中经常会出现一些3D的文字效果,本文将利用Three.js实现各种动画WebGL文本输入效果。 示例效果 原文章 通常情况下,文本网格是2D的平面形状,我们所要实现的3D文本形状则是要在2D的平面下,再生成z值形成一个立体的效果。 首先,我们创建一个canvas元素,

    2024年02月02日
    浏览(8)
  • Three.js--》实现3D汽车展厅效果展示

    Three.js--》实现3D汽车展厅效果展示

    目录 项目搭建 初始化three.js基础代码 加载汽车模型 设置展厅效果 设置GUI面板动态控制车身操作 车门操作与车身视角展示 设置手动点击打开关闭车门 设置图片背景 今天简单实现一个three.js的小Demo,加强自己对three知识的掌握与学习,只有在项目中才能灵活将所学知识运用起

    2024年02月09日
    浏览(48)
  • Three.js--》实现图片转3D效果展示

    Three.js--》实现图片转3D效果展示

    目录 项目搭建 初始化three.js基础代码 加载图片纹理 设置着色器 今天简单实现一个three.js的小Demo,加强自己对three知识的掌握与学习,只有在项目中才能灵活将所学知识运用起来,话不多说直接开始。 项目搭建 本案例还是借助框架书写three项目,借用vite构建工具搭建vue项目

    2024年02月08日
    浏览(46)
  • vue 项目使用three.js 实现3D看房效果

    vue 项目使用three.js 实现3D看房效果

    0.前言 该教程能帮助直接写出vue项目的3D看房效果!!! 先上效果图 1.安装依赖 2.vue代码 这里文件名为three.vue 代码非原创,出处 vue3+threejs实现全景看房 (异步加载 BOLLROOM 部件为对原代码的修改) 注意这里的hdr 文件必须要放在assets文件夹中,且要通过import模块的形式导入!

    2024年02月13日
    浏览(47)
  • vue2+three.js实现类似VR、3D全景效果

    vue2+three.js实现类似VR、3D全景效果

    效果图: 俩图标是我自己加的前进后退按钮,也是百度了好久,再加上GPT的帮助,才给搞出来。因为需求急,都不看官方文档,百度到一个能跑的demo之后改吧改吧,就先用着了。 下面是代码: 这里 代码有很多用不到的地方和需要优化的地方,我是来不及改了,就先这样吧

    2024年02月15日
    浏览(41)
  • WEB 3D技术 three.js 阴影属性

    WEB 3D技术 three.js 阴影属性

    上文 WEB 3D技术 three.js 光照与阴影 我们说了阴影 那么 我们继续将阴影的属性 目前 我们的代码 目前阴影效果是这样的 我们可以设置它的一个模糊度 我们官网搜索 LightShadow 下面找到 radius 模糊度的一个属性 这里 我们可以 设置 20 的一个模糊度 运行代码 然后看我们的模糊度

    2024年01月22日
    浏览(43)
  • WEB 3D技术 three.js 点光源

    WEB 3D技术 three.js 点光源

    本文的话 我们来设置一下点光源 点光源其实最直观的就是可以做萤火虫 也可以做星光 点点的效果 我们可以直接在官网中搜索 Pointlight 大家可以在官网这里看一下 其实 SpotLight 聚关灯中的属性 Pointlight 点光源也有的 我们先编写代码如下 PointLight 创建一个点光源 这里我们给了

    2024年01月19日
    浏览(45)
  • vue2+three.js+blender(实现3d 模型引入并可点击效果)

    vue2+three.js+blender(实现3d 模型引入并可点击效果)

    2023.9.13今天我学习了如何把3d建模里面的模型引入到vue中,并可以实现拖动,点击的效果: 首先安装: npm install three 相关代码如下:  如果没有图片可以去 Three.js--》建模软件如何加载外部3D模型?_threejs加载3d模型_亦世凡华、的博客-CSDN博客

    2024年02月03日
    浏览(48)
  • WEB 3D技术 three.js 聚光灯

    WEB 3D技术 three.js 聚光灯

    本文 我们来说说 点光源和聚光灯 点光源 就像一个电灯泡一样 想四周发散光 而聚光灯就像手电筒一样 像一个方向射过去 距离越远范围越大 光越弱 我们先来看一个聚光灯的效果 我们可以编写代码如下 SpotLight 聚光灯 然后通过 position 设置一下光的位置 运行代码如下 目前看

    2024年01月21日
    浏览(45)
  • WEB 3D技术 three.js 3D贺卡(1) 搭建基本项目环境

    WEB 3D技术 three.js 3D贺卡(1) 搭建基本项目环境

    好 今天 我也是在网上学的 带着大家一起来做个3D贺卡 首先 我们要创建一个vue3的项目、 先创建一个文件夹 装我们的项目 终端执行 vue create 项目名称 例如 我的名字想叫 greetingCards 就是 因为这个名录 里面是全部都小写的 然后 下面选择 vue3 然后按下回车 等待项目创建完成

    2024年01月19日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包