千家信息网

HTML5怎么实现多视角3D可旋转的标志动画

发表于:2025-01-17 作者:千家信息网编辑
千家信息网最后更新 2025年01月17日,这篇"HTML5怎么实现多视角3D可旋转的标志动画"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起
千家信息网最后更新 2025年01月17日HTML5怎么实现多视角3D可旋转的标志动画

这篇"HTML5怎么实现多视角3D可旋转的标志动画"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"HTML5怎么实现多视角3D可旋转的标志动画"文章吧。

HTML代码

XML / HTML代码将内容复制到文本

< div class = "链接叠加" >

< canvas id = " canvas" style = " background-color:#ddd" >

JavaScript代码

JavaScript代码将内容复制到

//绑定到窗口onload处理程序

window.addEventListener('load' ,onloadHandler, false );

/ **

*窗口加载处理程序

* /

函数 onloadHandler()

{

var canvas = document.getElementById('canvas' );

canvas.width = window.innerWidth;

canvas.height = window.innerHeight;

var k3dmain = new K3D.Controller(canvas, true );

//生成3D对象

var obj1 = new K3D.K3DObject();

与 (obj1)

{

drawmode = " solid" ;

shademode = " lightsource" ;

sortmode = "未排序" ;

addphi = -0.5;

大约= -90;

perslevel = 1000;

在里面(

[{x:-80,y:180,z:0},{x:0,y:180,z:-80},{x:0,y:0,z:-80},{x:- 80,y:20,z:0},{x:-50,y:150,z:-30},{x:0,y:150,z:-80},{x:0,y:130 ,z:-80},{x:-30,y:130,z:-50},{x:-28,y:110,z:-52},{x:0,y:110,z: -80},{x:0,y:90,z:-80},{x:-45,y:90,z:-35},{x:-44,y:80,z:-36} ,{x:-25,y:80,z:-55},{x:-22,y:66,z:-58},{x:0,y:60,z:-80},{x :0,y:40,z:-80},{x:-40,y:50,z:-40}],

[],

[{颜色:[227,76,38],顶点:[0,1,2,3,0]},{颜色:[235,235,235],顶点:[4,5,6,7,8,9,10 ,11,4]},{颜色:[235,235,235],顶点:[12,13,14,15,16,17,12]}]

);

}

k3dmain.addK3DObject(obj1);

var obj2 = new K3D.K3DObject();

与 (obj2)

{

drawmode = " solid" ;

shademode = " lightsource" ;

sortmode = "未排序" ;

addphi = -0.5;

大约= -90;

perslevel = 1000;

在里面(

[{x:0,y:180,z:-80},{x:80,y:180,z:0},{x:80,y:20,z:0},{x:0,y :0,z:-80},{x:0,y:165,z:-80},{x:68,y:165,z:-12},{x:55,y:35,z: -25},{x:0,y:20,z:-80},{x:0,y:150,z:-80},{x:50,y:150,z:-30},{ x:47,y:130,z:-33},{x:0,y:130,z:-80},{x:0,y:110,z:-80},{x:45,y :110,z:-35},{x:40,y:50,z:-40},{x:0,y:40,z:-80},{x:0,y:60,z: -80},{x:20,y:66,z:-60},{x:23,y:90,z:-57},{x:0,y:90,z:-80}]],

[],

[{颜色:[227,76,38],顶点:[0,1,2,3,0]},{颜色:[240,101,41],顶点:[4,5,6,7,4]} ,{颜色:[235,235,235],顶点:[8,9,10,11,8]}},{颜色:[235,235,235],顶点:[12,13,14,15,16,17,18,19,12 ]}]

);

}

k3dmain.addK3DObject(obj2);

var obj3 = new K3D.K3DObject();

与 (obj3)

{

drawmode = " solid" ;

shademode = " lightsource" ;

sortmode = "未排序" ;

addphi = -0.5;

大约= -90;

perslevel = 1000;

在里面(

[{x:80,y:180,z:0},{x:0,y:180,z:80},{x:0,y:0,z:80},{x:80,y: 20,z:0},{x:50,y:150,z:30},{x:0,y:150,z:80},{x:0,y:130,z:80},{ x:30,y:130,z:50},{x:28,y:110,z:52},{x:0,y:110,z:80},{x:0,y:90, z:80},{x:45,y:90,z:35},{x:44,y:80,z:36},{x:25,y:80,z:55},{x: 22,y:66,z:58},{x:0,y:60,z:80},{x:0,y:40,z:80},{x:40,y:50,z: 40}],

[],

[{颜色:[227,76,38],顶点:[0,1,2,3,0]},{颜色:[235,235,235],顶点:[4,5,6,7,8,9,10 ,11,4]},{颜色:[235,235,235],顶点:[12,13,14,15,16,17,12]}]

);

}

k3dmain.addK3DObject(obj3);

var obj4 = new K3D.K3DObject();

与 (obj4)

{

drawmode = " solid" ;

shademode = " lightsource" ;

sortmode = "未排序" ;

addphi = -0.5;

大约= -90;

perslevel = 1000;

在里面(

[{x:0,y:180,z:80},{x:-80,y:180,z:0},{x:-80,y:20,z:0},{x:0, y:0,z:80},{x:0,y:165,z:80},{x:-68,y:165,z:12},{x:-55,y:35,z: 25},{x:0,y:20,z:80},{x:0,y:150,z:80},{x:-50,y:150,z:30},{x:- 47,y:130,z:33},{x:0,y:130,z:80},{x:0,y:110,z:80},{x:-45,y:110,z :35},{x:-40,y:50,z:40},{x:0,y:40,z:80},{x:0,y:60,z:80},{x: -20,y:66,z:60},{x:-23,y:90,z:57},{x:0,y:90,z:80}],

[],

[{颜色:[227,76,38],顶点:[0,1,2,3,0]},{颜色:[240,101,41],顶点:[4,5,6,7,4]} ,{颜色:[235,235,235],顶点:[8,9,10,11,8]}},{颜色:[235,235,235],顶点:[12,13,14,15,16,17,18,19,12 ]}]

);

}

k3dmain.addK3DObject(obj4);

var objBase = new K3D.K3DObject();

与 (objBase)

{

drawmode = " solid" ;

shademode = " lightsource" ;

sortmode = "未排序" ;

addphi = -0.5;

大约= -90;

perslevel = 1000;

在里面(

[{x:0,y:0,z:-80},{x:-80,y:20,z:0},{x:0,y:0,z:80},{x:80, y:20,z:0}],

[],

[{颜色:[227,76,38],顶点:[0,2,1,0]},{颜色:[227,76,38],顶点:[0,3,2,0]}]

);

}

k3dmain.addK3DObject(objBase);

var objHtml = 新的 K3D.K3DObject();

与 (objHtml)

{

drawmode = " solid" ;

shademode = " lightsource" ;

// sortmode =" unsorted";

颜色= [64,64,64];

双面= 真;

addphi = -0.5;

大约= 100;

比例= 0.75;

perslevel = 1000;

在里面(

[{x:-80,y:40,z:0},{x:-70,y:40,z:0},{x:-70,y:30,z:0},{x:- 60,y:30,z:0},{x:-60,y:40,z:0},{x:-50,y:40,z:0},{x:-50,y:10 ,z:0},{x:-60,y:10,z:0},{x:-60,y:20,z:0},{x:-70,y:20,z:0} ,{x:-70,y:10,z:0},{x:-80,y:10,z:0},{x:-40,y:40,z:0},{x:- 10,y:40,z:0},{x:-10,y:30,z:0},{x:-20,y:30,z:0},{x:-20,y:10 ,z:0},{x:-30,y:10,z:0},{x:-30,y:30,z:0},{x:-40,y:30,z:0} ,{x:0,y:40,z:0},{x:10,y:40,z:0},{x:20,y:30,z:0},{x:30,y: 40,z:0},{x:40,y:40,z:0},{x:40,y:10,z:0},{x:30,y:10,z:0},{ x:30,y:30,z:0},{x:20,y:20,z:0},{x:10,y:30,z:0},{x:10,y:10, z:0},{x:0,y:10,z:0},{x:50,y:40,z:0},{x:60,y:40,z:0},{x: 60,y:20,z:0},{x:80,y:20,z:0},{x:80,y:10,z:0},{x:50,y:10,z: 0}],

[],

[{vertices:[0,1,2,3,4,5,6,7,8,9,10,11,0]} ,, {vertices:[12,13,14,15,16,17,18 ,19,12]},{顶点:[20,21,22,23,24,25,26,27,28,29,30,31,20]},{顶点:[32,33,34,35 ,36,37,32]}]

);

}

k3dmain.addK3DObject(objHtml);

//添加渲染循环回调

var ctx = canvas.getContext('2d' );

var rotationOffset = 0;

var len =(canvas.height> canvas.width?canvas.height:canvas.width)* 0.7;

k3dmain.clearBackground = false ;

k3dmain.callback = 函数()

{

//手动清除bg-因为我们要渲染一些额外的东西

ctx.clearRect(0,0,canvas.width,canvas.height);

//在K3D进行3D渲染之前绘制bg效果

ctx.save();

ctx.translate(canvas.width / 2,canvas.height / 2);

ctx.rotate(rotationOffset);

//第一次填充-外部光线

var RAYCOUNT = 24;

ctx.fillStyle = " #eee" ;

ctx.beginPath();

对于 (var i = 0; i

{

//旋转上下文

ctx.rotate(TWOPI / RAYCOUNT);

ctx.moveTo(0,0);

ctx.lineTo(-20,len);

ctx.lineTo(20,len);

}

ctx.closePath();

ctx.fill();

//第二遍填充-内部光线

ctx.fillStyle = " #fff " ;

ctx.beginPath();

对于 (var i = 0; i

{

//旋转上下文

ctx.rotate(TWOPI / RAYCOUNT);

ctx.moveTo(0,0);

ctx.lineTo(-15,len);

ctx.lineTo(15,len);

}

ctx.closePath();

ctx.fill();

ctx.restore();

rotationOffset + = 0.005;

//将用户互动应用于轮播

对于 (var i = 0,objs = k3dmain.objects; i

{

objs [i] .ophi + = targetRotationX;

}

如果 (targetRotationX> -0.5)targetRotationX-= 0.05;

否则如果 (targetRotationX <-0.55)targetRotationX + = 0.05;

如果 (targetRotationX> -0.55 && targetRotationX <-0.5)targetRotationX = -0.5;

};

//开始演示循环

k3dmain.paused = true ;

setInterval(function (){k3dmain.tick()},1000/60);

}

//从Doob先生http://mrdoob.com/借来的漂亮的拖动/触摸事件捕获代码

var targetRotationX = 0;

var targetRotationOnMouseDownX = 0;

var mouseX = 0;

var mouseXOnMouseDown = 0;

var targetRotationY = 0;

var targetRotationOnMouseDownY = 0;

var mouseY = 0;

var mouseYOnMouseDown = 0;

var windowHalfX = window.innerWidth / 2;

var windowHalfY = window.innerHeight / 2;

document.addEventListener('mousedown' ,onDocumentMouseDown, false );

document.addEventListener('touchstart' ,onDocumentTouchStart, false );

document.addEventListener('touchmove' ,onDocumentTouchMove, false );

函数 onDocumentMouseDown(event){

event.preventDefault();

document.addEventListener('mousemove' ,onDocumentMouseMove, false );

document.addEventListener('mouseup' ,onDocumentMouseUp, false );

document.addEventListener('mouseout' ,onDocumentMouseOut, false );

mouseXOnMouseDown = event.clientX-windowHalfX;

targetRotationOnMouseDownX = targetRotationX;

mouseYOnMouseDown = event.clientY-windowHalfY;

targetRotationOnMouseDownY = targetRotationY;

}

函数 onDocumentMouseMove(event)

{

mouseX = event.clientX-windowHalfX;

targetRotationX = targetRotationOnMouseDownX +(mouseX-mouseXOnMouseDown)* 0.02;

mouseY = event.clientY-windowHalfY;

targetRotationY = targetRotationOnMouseDownY +(mouseY-mouseYOnMouseDown)* 0.02;

}

函数 onDocumentMouseUp(event)

{

document.removeEventListener('mousemove' ,onDocumentMouseMove, false );

document.removeEventListener('mouseup' ,onDocumentMouseUp, false );

document.removeEventListener('mouseout' ,onDocumentMouseOut, false );

}

函数 onDocumentMouseOut(event)

{

document.removeEventListener('mousemove' ,onDocumentMouseMove, false );

document.removeEventListener('mouseup' ,onDocumentMouseUp, false );

document.removeEventListener('mouseout' ,onDocumentMouseOut, false );

}

函数 onDocumentTouchStart(event)

{

如果 (event.touches.length == 1)

{

event.preventDefault();

mouseXOnMouseDown = event.touches [0] .pageX-windowHalfX;

targetRotationOnMouseDownX = targetRotationX;

mouseYOnMouseDown = event.touches [0] .pageY-windowHalfY;

targetRotationOnMouseDownY = targetRotationY;

}

}

函数 onDocumentTouchMove(event)

{

如果 (event.touches.length == 1)

{

event.preventDefault();

mouseX = event.touches [0] .pageX-windowHalfX;

targetRotationX = targetRotationOnMouseDownX +(mouseX-mouseXOnMouseDown)* 0.05;

mouseY = event.touches [0] .pageY-windowHalfY;

targetRotationY = targetRotationOnMouseDownY +(mouseX-mouseYOnMouseDown)* 0.05;

}

}

以上就是关于"HTML5怎么实现多视角3D可旋转的标志动画"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。

顶点 颜色 函数 内容 代码 排序 动画 标志 视角 上下 上下文 光线 文章 知识 程序 篇文章 处理 循环 漂亮 东西 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网安民警网络安全管理工作总结 阿里数据库首席架构师 计算机与网络技术上什么软件 彩通网络技术有限公司怎么样 新形势下网络安全我该怎么办 肇庆监控数据库 软件开发业发展趋势 北京工业互联网协会东土科技 泓海新网络技术有限公司 网络正常开票软件连接服务器失败 门禁服务器是什么样 郑州翼盈互联网科技有限公司 三级网络技术视频资源 高校网络安全法治建设 两个数据库同步数据接口的设计 数据库连接和嵌套实验报告 创新互联服务器 qq怎么断开远程连接服务器 商务局网络安全宣传内容 惠普g7服务器售后 软件开发如何去国外 sql清空字段数据库表 江西消费数据库 架设电视升级服务器 软件开发工作量明细表 大量游戏服务器管理 滦州口碑好的软件开发常见问题 qq怎么断开远程连接服务器 万方数据库整改了吗 广州聚大网络技术有限公司
0