相关技术和实现分析

  • 3D模型
  • 帧动画
  • threejs
  1. 推荐用blender创建3d模型,k帧实现从上到下翻转的帧动画
  2. threejs 中执行帧动画,并关联滚动条
  3. threejs 模型材质

Blender 建模

logo模型用的是glb格式,也可以使用已有模型
导出logo模型可以压缩一下,占用资源更小

Blender 动画k帧

用一个空立方体关联logo主体,k帧主要就是立方体的翻转动画,logo是静止的,自转的动画这块可以代码中实现
整个动画总共做了14个关键帧





导出带动画模型(导出时勾选动画信息)

编码

创建场景

<div id="container">
<div id="bg"></div>
</div>
import * as THREE from 'three';

// ...

// 基础数据
const container = document.getElementById('container');
const winHeight = 12000; // 页面高度,可按实际获取
container.style.height = winHeight + 'px'; // antialias 抗锯齿属性; alpha 透明背景
const renderer = window.WebGLRenderingContext
? new THREE.WebGLRenderer({ antialias: true, alpha: true })
: new THREE.CanvasRenderer(); //设置渲染的尺寸大小
renderer.setSize(window.innerWidth, window.innerHeight);
// 添加webgl渲染的canves内容
document.getElementById('bg').appendChild(renderer.domElement); // 创建场景
const scene = new THREE.Scene(); scene.background = null;
// 创建相机
const camera = new THREE.PerspectiveCamera(
50,
window.innerWidth / window.innerHeight,
0.0001, // 近端视角尽量小 可避免相机穿模
1000
); //透视相机(角度,宽高比,近端,远端) // 相机位置
const baseCameraPos = { x: 0, y: 0, z: 1.25 }; camera.position.set(baseCameraPos.x, baseCameraPos.y, baseCameraPos.z); function render() {
requestAnimationFrame(render); // 使用渲染器,通过相机,将场景渲染进来
renderer.render(scene, camera);
} render()

材质准备

材质数据

貌似不同版Threejs 材质参数设置表现不太一样,可以具体情况调整


// LOGO材质
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x3069c7, // 颜色
metalness: 0, // 金属贴图
roughness: 0.4, // 表层粗糙程度 磨砂质感
transparent: false, // 透明度
opacity: 0.98, // 设置透明度
envMapIntensity: 0.51, //需要搭配transparent
transmission: 0.9, // 折射度,表示光线经过材料时的衰减程度 越大越透光
clearcoat: 0.8, // 光亮层的程度
clearcoatRoughness: 0.9, // 光泽层的粗糙程度0-1 越大越粗糙
refractionRatio: 0.9, // 折射率,控制光的折射程度
side: THREE.DoubleSide,
}); // 外框材质
const wrapMaterial = new THREE.MeshPhysicalMaterial({
transparent: true, // 透明度设置为 true
opacity: 0, // 设置透明度
});

读取模型

import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader'; // 模型动画相关
let AnimationAction = null;
let mixer = null;
let clip = null;
let AnimatDuration = 0;
let timeProgress = 0;
let newtimeProgress = 0;
let innerObj = null; function loadGLB() {
// 创建外层物体
const group = new THREE.Group();
const parent = new THREE.Mesh(new THREE.BoxGeometry(5, 5, 5), wrapMaterial);
// 外层模型名称
parent.name = '隐形框'; const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath(
'https://www.gstatic.com/draco/versioned/decoders/1.5.6/'
);
glbLoader.setDRACOLoader(dracoLoader);
glbLoader.load(
'static/model/G/logo.glb', // 可用网络地址
function (gltf) {
// 获取3D网格Mesh节点
const logoMesh = gltf.scene.children[0]; innerObj = logoMesh; // 组合结构
parent.add(logoMesh);
group.add(parent);
// 场景中加入
scene.add(group); parent.animations = [];
// animatInfo 帧动画数据
const tracks = animatInfo.tracks[0];
const tracks1 = animatInfo.tracks[1]; AnimatDuration = animatInfo.duration; const rotationKeyFrame = new THREE.QuaternionKeyframeTrack(
// 固定格式 [模型名称+'.quaternion']
parent.name + '.quaternion',
tracks.times,
tracks.values
);
const VectorKeyFrame = new THREE.VectorKeyframeTrack(
// 固定格式 [模型名称+'.position']
parent.name + '.position',
tracks1.times,
tracks1.values
); clip = new THREE.AnimationClip(animatInfo.name, animatInfo.duration, [
rotationKeyFrame,
VectorKeyFrame,
]); group.animations = [clip]; // group.scale.set(1.2, 1.2, 1.2); // 缩放设置 if (group.animations.length) {
mixer = new THREE.AnimationMixer(group); //创建动画clipAction对象
AnimationAction = mixer.clipAction(clip); // 单帧播放
AnimationAction.loop = THREE.LoopOnce;
AnimationAction.clampWhenFinished = true;
animatPlay(scrollRate);
}
},
function (xhr) {
console.log((xhr.loaded / xhr.total) * 100 + '% loaded');
},
function (error) {
console.log(error, 'An error happened');
}
);
} loadGLB()

动画数据获取

分离动画数据的好处是可以降低引入模型大小,还能将动画数据复用到任何模型上

glbLoader.load(
'static/model/G/logoAnimat.glb', // 包含动画数据模型
function (gltf) {
// 读取 animatInfo
animatInfo = gltf.animations[0]
})

单帧控制

// 时间相关
var clock = new THREE.Clock();
var deltaTime = 0;
var newTime = new Date().getTime();
var oldTime = new Date().getTime(); // 监听滚动条
window.onscroll = function () {
const nextScrollTop =
document.documentElement.scrollTop || document.body.scrollTop;
scrollTop = nextScrollTop;
scrollRate = scrollTop / totalHeight;
// 帧动画播放进度
animatPlay(scrollRate);
}; // 帧动画 播放进度
function animatPlay(scrollRate) {
newtimeProgress = AnimatDuration * scrollRate; // 目标进度时间
} // 平滑播放动画
function updateGroup() {
if (!AnimationAction) return;
timeProgress += (newtimeProgress - timeProgress) * deltaTime * 0.005;
AnimationAction.time = timeProgress; //操作对象设置开始播放时间
clip.duration = AnimationAction.time; //剪辑对象设置播放结束时间
AnimationAction.play(); //开始播放
camera.updateProjectionMatrix();
} function render() {
newTime = new Date().getTime();
deltaTime = newTime - oldTime;
oldTime = newTime; // logo自转
if (innerObj) {
innerObj.rotation.z += 0.01;
} // 一定要在这里面获取delta时间才能持续更新
if (mixer) mixer.update(clock.getDelta());
updateGroup(); // ...
}

至此可以获得一个3d动画logo,只是好像还缺点啥

神说,要有光!

光照的设置非常影响玻璃质感,这里给的都是固定角度光,实际有光照是运动的,效果更好

// 环境光
const light0 = new THREE.AmbientLight(0x404040, 1); scene.add(light0); // 添加光照 设置角度和强度
lightPingXing(0, -5, 0, 5);
lightPingXing(10, 0, 2, 1);
lightPingXing(0, 2, 0, 20);
lightPingXing(0, -2, -8, 1); // 平行光
function lightPingXing(x, y, z, energy = 1) {
const directionalLight = new THREE.DirectionalLight('#fff', energy);
directionalLight.position.set(x, y, z);
directionalLight.castShadow = true;
directionalLight.visible = true;
scene.add(directionalLight);
}

打光后效果

其他细节

  • 浮动效果

这块没有想到好的实现方式,目前是让镜头略微移动,感觉凑合;

  • 背景和虚化效果

实现起来不难,也可自行发挥

  • 背景小logo

可复制logo按需展示

3D网站LOGO动画的更多相关文章

  1. Logo小变动,心境大不同,SVG矢量动画格式网站Logo图片制作与实践教程(Python3)

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_207 曾几何时,SVG(Scalable Vector Graphics)矢量动画图被坊间称之为一种被浏览器诅咒的技术,只因为糟糕 ...

  2. Three.js实现脸书元宇宙3D动态Logo

    背景 Facebook 近期将其母公司改名为 Meta,宣布正式开始进军 元宇宙 领域.本文主要讲述通过 Three.js + Blender 技术栈,实现 Meta 公司炫酷的 3D 动态 Logo ...

  3. jQuery鼠标悬停3d菜单展开动画

    效果体验:http://hovertree.com/texiao/jquery/93/ 竖直的主菜单贴着页面左侧,当光标移入菜单项时,以3D动画的方式弹出对应的二级菜单.采用jQuery和CSS3实现 ...

  4. Qt Creator中的3D绘图及动画教程(参照NeHe)

    Qt Creator中的3D绘图及动画教程(参照NeHe) http://blog.csdn.net/cly116/article/details/47184729 刚刚学习了Qt Creator,发 ...

  5. Python3.7将普通图片(png)转换为SVG图片格式并且让你的网站Logo(图标)从此”动”起来

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_148 在之前的几篇文章中,介绍了业界中比较火爆的图片技术SVG(Scalable Vector Graphics),比如Iconf ...

  6. 网站logo正确写法,个人拙见,不喜勿喷

    网站logo既要考虑seo又需要用图片代替网站名字,所有H1标签带来的权重还是需要使用 有些人喜欢直接把<H1></H1>标签直接hidden掉,个人喜欢使用css Text- ...

  7. css3 3D变换和动画

    3D变换和动画 建立3D空间,transform-style: preserve-3d perspective: 100px; 景深 perspective-origin:center center ...

  8. 【翻译】我如何使用CSS来制作bitsofcode Logo动画

    翻译文章,翻译不好,还望大家指出 原文地址:How I Animated the bitsofcode Logo with CSS 我是css动画的新手,这样说是因为我只在有限的案例中使用过他们,而且 ...

  9. 在百度搜索里展现网站LOGO

    我们经常在百度搜索一些网站可以看到一个网站在百度上展示的三个部分: 网站的名称 如(趣学车) 网站的描述 一段比较详细的对网站的介绍 网站的logo,一张logo图片 如下图 ------ 接下来我们 ...

  10. WordPress 后台上传自定义网站Logo

    需求: 众所周知一般网站的logo都是固定的所以我在做网站时也是使用的静态logo文件,但最近用wp给一个客户做的网站时,因为网站现在的logo可能会需要重新设计,所以客户提出了需要在后台可以自己修改 ...

随机推荐

  1. 面霸的自我修养:volatile专题

    王有志,一个分享硬核Java技术的互金摸鱼侠 加入Java人的提桶跑路群:共同富裕的Java人 今天是<面霸的自我修养>第4篇文章,我们一起来看看面试中会问到哪些关于volatile的问题 ...

  2. Andrew Ng 机器学习&深度学习课程 代码作业解答 集合

    写在最前 ​ 2018年是对自己来说是崭新的一年,在过去的3个多月里,从最基础的lr, 学到现在的LSTM, GAN..感觉第一次追上了计算机科学飞速发展的浪潮.虽然很多地方都仍是一知半解,但时间还长 ...

  3. Markdown初识

    1.标题 一级标题 ctrl+1......六级标题 ctrl+6 2.字体 加粗 ctrl+B 斜体 ctrl+I 下划线 ctrl+ U 3.引用 大于号加任意键 4.分割线 "---& ...

  4. Redis从入门到放弃(12):pipeline管道技术

    1.引言 在现代应用程序中,高性能和低延迟是至关重要的因素.而在处理大规模数据操作时,Redis作为一种快速.可靠的内存数据库,成为了许多开发人员的首选. 在Redis中,每个操作都需要与服务器进行往 ...

  5. 每日一库:lumberjack -- 日志轮换和管理

    在开发应用程序时,记录日志是一项关键的任务,以便在应用程序运行时追踪问题.监视性能和保留审计记录.Go 语言提供了灵活且强大的日志记录功能,可以通过多种方式配置和使用.其中一个常用的日志记录库是 gi ...

  6. Three.js中实现一个OBBHelper

    1. 引言 Three.js中,Box3对象指的是AABB式的包围盒,这种包围盒会随物体的旋转而变换大小,精度较差 Three.js中还有OBB对象,这是一种能表现物体主要特征的.不随物体的旋转而变换 ...

  7. Chapter 6. Build Script Basics

    Chapter 6. Build Script Basics 6.1. Projects and tasks Everything in Gradle sits on top of two basic ...

  8. 数据重整:用Java实现精准Excel数据排序的实用策略

    摘要:本文由葡萄城技术团队原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 在数据处理或者数据分析的场景中,需要对已有的数据进行排序,在Ex ...

  9. Python3中的printable

    import string characters = string.printable # printable 是用作字符串常量的预初始化字符串.里面包含所有的标点符号,数字 print(charac ...

  10. centos7 oracle11gR2安装

    CentOS7安装Oracle 11gR2 图文详解 摘自: http://www.linuxidc.com/Linux/2016-04/130559.htm 最近要运维一个项目,准备在家办公,公司无 ...