本文章分为两部分:
第一部分为实现效果展示,第二部分是实现跳动爱心源码。
关注微信公众号: 先取个名字吧

跳动的爱心效果展示


关注微信公众号(先取个名字吧)获取完整源码,回复爱心代码

实现步骤

1.建一个html文件,代码如下:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>爱心跳动,3D拖拽搬</title><link rel="stylesheet" href="./css/style.css"></head><body><script src='./js/three.min.js'></script><!-- <script src='./js/MeshSurfaceSampler.js'></script> --><script src='./js/TrackballControls.js'></script><script src='./js/simplex-noise.js'></script><script src='./js/OBJLoader.js'></script><script src='./js/gsap.min.js'></script><script src="./js/script.js"></script><script>(function () {const _face = new THREE.Triangle();const _color = new THREE.Vector3();class MeshSurfaceSampler {constructor(mesh) {let geometry = mesh.geometry;if (!geometry.isBufferGeometry || geometry.attributes.position.itemSize !== 3) {throw new Error('THREE.MeshSurfaceSampler: Requires BufferGeometry triangle mesh.');}if (geometry.index) {console.warn('THREE.MeshSurfaceSampler: Converting geometry to non-indexed BufferGeometry.');geometry = geometry.toNonIndexed();}this.geometry = geometry;this.randomFunction = Math.random;this.positionAttribute = this.geometry.getAttribute('position');this.colorAttribute = this.geometry.getAttribute('color');this.weightAttribute = null;this.distribution = null;}setWeightAttribute(name) {this.weightAttribute = name ? this.geometry.getAttribute(name) : null;return this;}build() {const positionAttribute = this.positionAttribute;const weightAttribute = this.weightAttribute;const faceWeights = new Float32Array(positionAttribute.count / 3); // Accumulate weights for each mesh face.for (let i = 0; i < positionAttribute.count; i += 3) {let faceWeight = 1;if (weightAttribute) {faceWeight = weightAttribute.getX(i) + weightAttribute.getX(i + 1) + weightAttribute.getX(i + 2);}_face.a.fromBufferAttribute(positionAttribute, i);_face.b.fromBufferAttribute(positionAttribute, i + 1);_face.c.fromBufferAttribute(positionAttribute, i + 2);faceWeight *= _face.getArea();faceWeights[i / 3] = faceWeight;} // Store cumulative total face weights in an array, where weight index// corresponds to face index.this.distribution = new Float32Array(positionAttribute.count / 3);let cumulativeTotal = 0;for (let i = 0; i < faceWeights.length; i++) {cumulativeTotal += faceWeights[i];this.distribution[i] = cumulativeTotal;}return this;}setRandomGenerator(randomFunction) {this.randomFunction = randomFunction;return this;}sample(targetPosition, targetNormal, targetColor) {const cumulativeTotal = this.distribution[this.distribution.length - 1];const faceIndex = this.binarySearch(this.randomFunction() * cumulativeTotal);return this.sampleFace(faceIndex, targetPosition, targetNormal, targetColor);}binarySearch(x) {const dist = this.distribution;let start = 0;let end = dist.length - 1;let index = - 1;while (start <= end) {const mid = Math.ceil((start + end) / 2);if (mid === 0 || dist[mid - 1] <= x && dist[mid] > x) {index = mid;break;} else if (x < dist[mid]) {end = mid - 1;} else {start = mid + 1;}}return index;}sampleFace(faceIndex, targetPosition, targetNormal, targetColor) {let u = this.randomFunction();let v = this.randomFunction();if (u + v > 1) {u = 1 - u;v = 1 - v;}_face.a.fromBufferAttribute(this.positionAttribute, faceIndex * 3);_face.b.fromBufferAttribute(this.positionAttribute, faceIndex * 3 + 1);_face.c.fromBufferAttribute(this.positionAttribute, faceIndex * 3 + 2);targetPosition.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));if (targetNormal !== undefined) {_face.getNormal(targetNormal);}if (targetColor !== undefined && this.colorAttribute !== undefined) {_face.a.fromBufferAttribute(this.colorAttribute, faceIndex * 3);_face.b.fromBufferAttribute(this.colorAttribute, faceIndex * 3 + 1);_face.c.fromBufferAttribute(this.colorAttribute, faceIndex * 3 + 2);_color.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));targetColor.r = _color.x;targetColor.g = _color.y;targetColor.b = _color.z;}return this;}}THREE.MeshSurfaceSampler = MeshSurfaceSampler;})();</script><script>(function () {const _object_pattern = /^[og]\s*(.+)?/; // mtllib file_referenceconst _material_library_pattern = /^mtllib /; // usemtl material_nameconst _material_use_pattern = /^usemtl /; // usemap map_nameconst _map_use_pattern = /^usemap /;const _vA = new THREE.Vector3();const _vB = new THREE.Vector3();const _vC = new THREE.Vector3();const _ab = new THREE.Vector3();const _cb = new THREE.Vector3();function ParserState() {const state = {objects: [],object: {},vertices: [],normals: [],colors: [],uvs: [],materials: {},materialLibraries: [],startObject: function (name, fromDeclaration) {// If the current object (initial from reset) is not from a g/o declaration in the parsed// file. We need to use it for the first parsed g/o to keep things in sync.if (this.object && this.object.fromDeclaration === false) {this.object.name = name;this.object.fromDeclaration = fromDeclaration !== false;return;}const previousMaterial = this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined;if (this.object && typeof this.object._finalize === 'function') {this.object._finalize(true);}this.object = {name: name || '',fromDeclaration: fromDeclaration !== false,geometry: {vertices: [],normals: [],colors: [],uvs: [],hasUVIndices: false},materials: [],smooth: true,startMaterial: function (name, libraries) {const previous = this._finalize(false); // New usemtl declaration overwrites an inherited material, except if faces were declared// after the material, then it must be preserved for proper MultiMaterial continuation.if (previous && (previous.inherited || previous.groupCount <= 0)) {this.materials.splice(previous.index, 1);}const material = {index: this.materials.length,name: name || '',mtllib: Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',smooth: previous !== undefined ? previous.smooth : this.smooth,groupStart: previous !== undefined ? previous.groupEnd : 0,groupEnd: - 1,groupCount: - 1,inherited: false,clone: function (index) {const cloned = {index: typeof index === 'number' ? index : this.index,name: this.name,mtllib: this.mtllib,smooth: this.smooth,groupStart: 0,groupEnd: - 1,groupCount: - 1,inherited: false};cloned.clone = this.clone.bind(cloned);return cloned;}};this.materials.push(material);return material;},currentMaterial: function () {if (this.materials.length > 0) {return this.materials[this.materials.length - 1];}return undefined;},_finalize: function (end) {const lastMultiMaterial = this.currentMaterial();if (lastMultiMaterial && lastMultiMaterial.groupEnd === - 1) {lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;lastMultiMaterial.inherited = false;} // Ignore objects tail materials if no face declarations followed them before a new o/g started.if (end && this.materials.length > 1) {for (let mi = this.materials.length - 1; mi >= 0; mi--) {if (this.materials[mi].groupCount <= 0) {this.materials.splice(mi, 1);}}} // Guarantee at least one empty material, this makes the creation later more straight forward.if (end && this.materials.length === 0) {this.materials.push({name: '',smooth: this.smooth});}
.....
</body></html>
  1. 建立一个css文件
body {background: rgb(0, 0, 0);overflow: hidden;margin: 0;/* background-color: #000 !important; */
}
  1. 运行html文件

获取源码直接运行

关注微信公众号「 先取个名字吧」 更多惊喜等待你的发掘

跳动的爱心代码--李峋爱心代码(完整源码)相关推荐

  1. 跳动爱心代码-李峋爱心代码(手把手教学)

    电视剧 点燃我,温暖你 打火机与公主裙 李洵爱心跳动效果. 获取完整代码,公众号「先取个名字吧」 回复爱心代码. 本文分为两种方式讲解如何运行代码,第一种方式比较简单推荐新手(完全不懂编程的),第二种 ...

  2. html转盘游戏代码,html5 转盘 例子 附完整源码 有截图 亲测通过

    [实例简介]html5 转盘实例 可直接拿来做 抽奖程序 [实例截图]  [核心代码] var colors = ["#B8D430", "#3AB745", ...

  3. 李峋爱心Python代码

    李峋爱心Python代码: # coding=gbk import random from math import sin, cos, pi, log from tkinter import * CA ...

  4. 《点燃我,温暖你》朱韵李峋爱心代码

    闲来无事,找了下<点燃我,温暖你>中朱韵的期中考试作业,在上面又删删改改,发现小猪猪的确有两下子(比我期中考试时水平高多了) 代码双手奉上: #include<bits/stdc++ ...

  5. java华容道代码_Java 华容道完整源码

    时间:2018-12-19 概述:华容道 Java 华容道完整源码,本代码实现华容道游戏的整体功能.程序执行后,点击相应的人物,然后按上下左右键可以移动.点击重新开始按钮,可以将各个人物的位置重置.如 ...

  6. java毕业生设计爱心公益网站设计与制作计算机源码+系统+mysql+调试部署+lw

    java毕业生设计爱心公益网站设计与制作计算机源码+系统+mysql+调试部署+lw java毕业生设计爱心公益网站设计与制作计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B ...

  7. HBase的java代码开发(完整源码)

    熟练掌握通过使用java代码实现HBase数据库当中的数据增删改查的操作,特别是各种查询,熟练运用 源码在最后!! 第一步:创建maven工程,导入jar包 <dependencies>& ...

  8. 微信小程序 - [完整源码] 全屏左右菜单联动效果,左侧分类与右侧内容联动,类似美团饿了么的点餐页面 “左边菜单,右边内容“ 效果(开箱即用的示例源码,代码干净整洁且注释详细)

    前言 您可能需要:微信小程序 - 外卖点餐的左右联动功能界面(购物车加减商品,购物车自动计算金额等电商功能) 网上的教程样式和逻辑都太乱了(而且 BUG 一堆.各种真机运行不兼容),直接复制下来后代码 ...

  9. Python:30行代码,使用POST登录山大的教务处系统(附完整源码)

    一.抓包分析 首先我们打开浏览器的开发者工具,随便输入一个用户名和密码登录,抓包分析: 显然,我们登录的时候发送了一个POST请求,而Data里面有六个数据,分别是rsa.ul.pl.lt.execu ...

最新文章

  1. 可视化LassoCV的最佳alpha值
  2. 干货丨一文看懂什么是知识图谱!
  3. 公司技术部门内部的发展变化过程。
  4. pandas loc 正则匹配字符串_一场pandas与SQL的巅峰大战(二)
  5. 计算机新建用户会不会速度快,创建帐户让电脑系统速度比重装还快
  6. mcollective的web控制台---mcomaster搭建
  7. 网络对抗技术实验二,第一部分,第二部分
  8. mysql主从数据库不同步的2种解决方法(转)
  9. 1.1.27 word表格里的文字不显示
  10. css3 Gradient背景
  11. less文件的样式无法生效的一个原因,通过WEB浏览器访问服务器less文件地址返回404错误...
  12. 长视频鏖战15年后 爱奇艺这份财报窥见“新蓝海“
  13. 项目部署发布CruiseControl工具介绍
  14. python实现qq空间自动点赞
  15. ESP8266 WIFI模块学习之路(9)——C++实现通过电脑串口读取ESP8266数据
  16. 接口测试用例设计:常见问题和风险
  17. 孩子为什么不愿意再跟家长沟通?家长该怎么办
  18. OpenGL之glut、glfw、glew、glad等库之间的关系
  19. 计算机 游戏第24级,全国计算机一级考试题库-全国计算机等级考试题(24页)-原创力文档...
  20. Office 365 函数之Right函数

热门文章

  1. 怎样优雅劝退他人做自媒体?
  2. Neutron DHCP-Agent问题分析定位(2)
  3. 黄哥python培训怎样
  4. 在线影视网站分享(持续更新)
  5. C++的内联函数和非内联函数的区别
  6. torch.sin() - torch.cos() - v1.5.0
  7. 十一、MySQL触发器
  8. react-native连接夜神模拟器
  9. html实现点赞效果,HTML+CSS入门 点赞功能实现 $(tag).css('属性', '样式')
  10. 羽素携手维琪共展科研实力,造护肤“芯”产链