分享three.js实现粒子背景

three.js中粒子效果的实现方式大概分为三种:
1、Javascript直接计算粒子的状态变化,即基于CPU实现;
2、Javascript通知顶点着色器粒子的生命周期,由顶点着色器运行,即基于GPU实现;
3、粒子生成与状态维护全部由片元着色器负责,即屏幕特效,同样是基于GPU中实现。

9a674d5348ee4deeb63f5475900ffb4d.png

粒子特效可以实现非常多的效果,如星空、烟雾、雨、灰尘、火等。粒子特效的优势是即使使用了成百上千的例子,也能保证比较高的帧率。

42a3522119674b61b15273d81a3a95c1.png

缺点是每个粒子都由一个始终面向相机的平面(两个三角形)组成。

点材质也是three.js最简单的类之一,相对于基类Material,它多做的事情只是传递了size,即点的尺寸这个值。

申明type是Points,执行渲染时,WebGL会绘制Point,即调用gl.drawArrays(gl.POINTS)。
type为Mesh时,three.js会调用gl.drawArrays(gl.TRIANGLES)。

着色器1

79272992e02646d58ad7c35db2da1a7a.png

<script id="vertex-shader" type="x-shader/x-vertex">//// GLSL textureless classic 2D noise "cnoise",// with an RSL-style periodic variant "pnoise".// Author:  Stefan Gustavson (stefan.gustavson@liu.se)// Version: 2011-08-22//// Many thanks to Ian McEwan of Ashima Arts for the// ideas for permutation and gradient selection.//// Copyright (c) 2011 Stefan Gustavson. All rights reserved.// Distributed under the MIT license. See LICENSE file.// https://github.com/ashima/webgl-noise//vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}vec4 permute(vec4 x){return mod289(((x*34.0)+1.0)*x);}vec4 taylorInvSqrt(vec4 r){return 1.79284291400159 - 0.85373472095314 * r;}vec2 fade(vec2 t) {return t*t*t*(t*(t*6.0-15.0)+10.0);}// Classic Perlin noisefloat cnoise(vec2 P){vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);Pi = mod289(Pi); // To avoid truncation effects in permutationvec4 ix = Pi.xzxz;vec4 iy = Pi.yyww;vec4 fx = Pf.xzxz;vec4 fy = Pf.yyww;vec4 i = permute(permute(ix) + iy);vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;vec4 gy = abs(gx) - 0.5 ;vec4 tx = floor(gx + 0.5);gx = gx - tx;vec2 g00 = vec2(gx.x,gy.x);vec2 g10 = vec2(gx.y,gy.y);vec2 g01 = vec2(gx.z,gy.z);vec2 g11 = vec2(gx.w,gy.w);vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));g00 *= norm.x;g01 *= norm.y;g10 *= norm.z;g11 *= norm.w;float n00 = dot(g00, vec2(fx.x, fy.x));float n10 = dot(g10, vec2(fx.y, fy.y));float n01 = dot(g01, vec2(fx.z, fy.z));float n11 = dot(g11, vec2(fx.w, fy.w));vec2 fade_xy = fade(Pf.xy);vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);float n_xy = mix(n_x.x, n_x.y, fade_xy.y);return 2.3 * n_xy;}float map(float value, float oldMin, float oldMax, float newMin, float newMax) {return newMin + (newMax - newMin) * (value - oldMin) / (oldMax - oldMin);}varying vec3 vUv;varying float vTime;varying float vZ;uniform float time;void main(){vUv = position;vTime = time;vec3 newPos = position;vec2 peak = vec2(1.0 - abs(.5 - uv.x), 1.0 - abs(.5 - uv.y));vec2 noise = vec2(map(cnoise(vec2(0.3 * time + uv.x * 5., uv.y * 5.)), 0., 1., -2., (peak.x * peak.y * 30.)),map(cnoise(vec2(-0.3 * time + uv.x * 5., uv.y * 5.)), 0., 1., -2., 25.));//newPos.x += noise.x * 10.;newPos.z += noise.x * .06 * noise.y;vZ = newPos.z;vec4 mvPosition = modelViewMatrix * vec4( newPos, 1.0 );gl_PointSize = 5.0;gl_Position = projectionMatrix * mvPosition;}</script><script id="fragment-shader" type="x-shader/x-fragment">varying vec3 vUv;varying float vTime;varying float vZ;uniform sampler2D texture;float map(float value, float oldMin, float oldMax, float newMin, float newMax) {return newMin + (newMax - newMin) * (value - oldMin) / (oldMax - oldMin);}void main(){vec3 colorA = vec3(.6, 0.17, 0.17);vec3 colorB = vec3(0.17, 0.8, .7); //vec3 color = mix(colorA, colorB, vUv.x * vUv.y);float alpha = map(vZ / 2., -1. / 2., 30. / 2., 0.17, 1.); vec3 color = vec3(.5, .5, .6);gl_FragColor = vec4( color, alpha);//gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );}</script>

着色器2

89d5593710154beb88e0de3cba39b888.png

<!-- built files will be auto injected --><!--粒子背景相关脚本--><script id="vertexShader" type="x-shader/x-vertex">attribute vec4 position;attribute float scale;uniform mat4 modelViewMatrix;uniform mat4 projectionMatrix;void main() {vec4 mvPosition = modelViewMatrix * position;gl_PointSize = scale*1.0 * ( 200.0 / - mvPosition.z );gl_Position = projectionMatrix * mvPosition;}</script><script id="fragmentShader" type="x-shader/x-fragment">void main() {if ( length( gl_PointCoord - vec2( 0.5, 0.5 ) ) > 0.49 ) discard;//gl_FragColor = vec4(0.0,1.0,1.0,1.0);// 根据片元的x坐标,来设置片元的像素值if(gl_FragCoord.x < 120.0){// canvas画布上[0,20)之间片元像素值设置//gl_FragColor = vec4(1.0,0.0,0.0,1.0);// 片元沿着x方向渐变gl_FragColor = vec4(gl_FragCoord.x/1000.0*0.1,1.0,1.0,0.1);}else if (gl_FragCoord.x <= 1800.0) {// canvas画布上(20,1900]之间片元像素值设置//gl_FragColor = vec4(0.0,1.0,0.0,1.0);// 片元沿着y方向渐变gl_FragColor = vec4(0.0,gl_FragCoord.y/3000.0*1.0,1.0,0.1);}else {// canvas画布上(1900,1920]之间片元像素值设置//gl_FragColor = vec4(0.0,0.0,1.0,1.0);// 片元沿着z方向渐变gl_FragColor = vec4(0.0,1.0,gl_FragCoord.z/1000.0*1.0,0.1);}}</script>

依赖importmap

<script type="importmap">{"imports": {"three": "https://cdn.jsdelivr.net/npm/three@0.162.0/+esm","three/addons/": "https://cdn.jsdelivr.net/npm/three@0.162.0/examples/jsm/","lil-gui": "https://threejsfundamentals.org/3rdparty/dat.gui.module.js","@tweenjs/tween.js": "https://cdn.jsdelivr.net/npm/@tweenjs/tween.js@23.1.1/dist/tween.esm.js","canvas-confetti": "https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.2/+esm"}}</script>

模块module代码

<script type="module">import * as THREE from 'three';import * as TWEEN from '@tweenjs/tween.js';import confetti from 'canvas-confetti';import { GUI } from 'lil-gui';import { OrbitControls } from 'three/addons/controls/OrbitControls.js';function drawWaveParticle(){let div = document.getElementById('webgl');let canvasWebgl = document.createElement('canvas');canvasWebgl.width = parseInt(window.innerWidth);canvasWebgl.height = parseInt(window.innerHeight);canvasWebgl.style.position = 'absolute';canvasWebgl.style.zIndex = -1;div.appendChild(canvasWebgl);let gl = canvasWebgl.getContext('webgl');let vertexShaderSource = document.getElementById('vertexShader').innerText;let fragShaderSource = document.getElementById('fragmentShader').innerText;let program = initShader(gl, vertexShaderSource, fragShaderSource);let aposLocation = gl.getAttribLocation(program, 'position');let scale = gl.getAttribLocation(program, 'scale');let modelViewMatrixLoc = gl.getUniformLocation(program, 'modelViewMatrix');let projectionMatrixLoc = gl.getUniformLocation(program, 'projectionMatrix');let SEPARATION = 100,AMOUNTX = 50,AMOUNTY = 50;let numParticles = AMOUNTX * AMOUNTY;let positions = new Float32Array(numParticles * 3);let scales = new Float32Array(numParticles);let i = 0, j = 0;for (let ix = 0; ix < AMOUNTX; ix++) {for (let iy = 0; iy < AMOUNTY; iy++) {positions[i] = ix * SEPARATION - ((AMOUNTX * SEPARATION) / 2); // xpositions[i + 1] = 0; // ypositions[i + 2] = iy * SEPARATION - ((AMOUNTY * SEPARATION) / 2); // zscales[j] = 1;i += 3;j++;}}let colorBuffer = gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);gl.bufferData(gl.ARRAY_BUFFER, scales, gl.STATIC_DRAW);gl.vertexAttribPointer(scale, 1, gl.FLOAT, false, 0, 0);gl.enableVertexAttribArray(scale);let buffer = gl.createBuffer();gl.bindBuffer(gl.ARRAY_BUFFER, buffer);gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);gl.vertexAttribPointer(aposLocation, 3, gl.FLOAT, false, 0, 0);gl.enableVertexAttribArray(aposLocation);gl.enable(gl.DEPTH_TEST);let width = window.innerWidth; let height = window.innerHeight; let camera = new THREE.PerspectiveCamera(60, width / height, 1, 10000);camera.position.set(200, 300, 200); camera.position.set(944, 206, -262);camera.lookAt(new THREE.Vector3(0, 0, 0)); camera.updateProjectionMatrix()camera.updateMatrixWorld(true)let mat4 = new THREE.Matrix4();mat4.copy(camera.projectionMatrix)let mxArr = new Float32Array(mat4.elements);gl.uniformMatrix4fv(projectionMatrixLoc, false, mxArr);let mat4y = new THREE.Matrix4();mat4y.copy(camera.matrixWorldInverse);//console.log(camera.matrixWorldInverse);let myArr = new Float32Array(mat4y.elements);gl.uniformMatrix4fv(modelViewMatrixLoc, false, myArr);let count = 0;let mouseX = 0,mouseY = 0;let windowHalfX = window.innerWidth / 2;let windowHalfY = window.innerHeight / 2;function draw() {camera.position.x += (mouseX - camera.position.x) * 0.001;camera.updateMatrixWorld(true)mat4y.copy(camera.matrixWorldInverse);let myArr = new Float32Array(mat4y.elements);gl.uniformMatrix4fv(modelViewMatrixLoc, false, myArr);let i = 0,j = 0;for (let ix = 0; ix < AMOUNTX; ix++) {for (let iy = 0; iy < AMOUNTY; iy++) {positions[i + 1] = (Math.sin((ix + count) * 0.3) * 50) +(Math.sin((iy + count) * 0.5) * 50);scales[j] = (Math.sin((ix + count) * 0.3) + 1.3) * 8 +(Math.sin((iy + count) * 0.5) + 1.3) * 8;i += 3;j++;}}count += 0.1;gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);gl.bufferData(gl.ARRAY_BUFFER, scales, gl.STATIC_DRAW);gl.bindBuffer(gl.ARRAY_BUFFER, buffer);gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW);requestAnimationFrame(draw);gl.drawArrays(gl.POINTS, 0, 2500);}draw();function initShader(gl, vertexShaderSource, fragmentShaderSource) {let vertexShader = gl.createShader(gl.VERTEX_SHADER);let fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);gl.shaderSource(vertexShader, vertexShaderSource);gl.shaderSource(fragmentShader, fragmentShaderSource);gl.compileShader(vertexShader);gl.compileShader(fragmentShader);let program = gl.createProgram();gl.attachShader(program, vertexShader);gl.attachShader(program, fragmentShader);gl.linkProgram(program);gl.useProgram(program);return program;}document.addEventListener('mousemove', onDocumentMouseMove, false);document.addEventListener('touchstart', onDocumentTouchStart, false);document.addEventListener('touchmove', onDocumentTouchMove, false);function onDocumentMouseMove(event) {mouseX = event.clientX - windowHalfX;mouseY = event.clientY - windowHalfY;}function onDocumentTouchStart(event) {if (event.touches.length === 1) {event.preventDefault();mouseX = event.touches[0].pageX - windowHalfX;mouseY = event.touches[0].pageY - windowHalfY;}}function onDocumentTouchMove(event) {if (event.touches.length === 1) {event.preventDefault();mouseX = event.touches[0].pageX - windowHalfX;mouseY = event.touches[0].pageY - windowHalfY;}}}class SceneViewer {constructor(options) {this.$el = options.el;this.time = 0;this.bindAll();this.init();}bindAll() {this.render = this.render.bind(this);this.resize = this.resize.bind(this);}init() {this.textureLoader = new THREE.TextureLoader();this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);this.camera.lookAt(new THREE.Vector3(0, 0, 0));let boxSize = {width: 1,height: 1, thickness: 1};const fov = 45;const angle = fov / 2;  // 夹角const rad = THREE.MathUtils.degToRad(angle);  // 转为弧度值const distanceZ = boxSize.width / 2 / Math.tan(rad) * 10;/*** 调整相机的 X 轴位置,让视野能同时看到盒子顶部和侧面* 调整相机的 Z 轴位置,使盒子完整显示到场景 */this.camera.position.set(0, 1, distanceZ);this.scene = new THREE.Scene();this.renderer = new THREE.WebGLRenderer({antialias: true, alpha: true});this.renderer.setPixelRatio(window.devicePixelRatio);this.renderer.setSize(window.innerWidth, window.innerHeight);let geometry = new THREE.BoxGeometry(boxSize.width, boxSize.height, boxSize.tickness);let material = new THREE.MeshNormalMaterial();this.mesh = new THREE.Mesh(geometry, material);this.scene.add(this.mesh);/* 相机轨道控制器 */new OrbitControls(this.camera, this.renderer.domElement);const axesHelper = new THREE.AxesHelper(10);  // 辅助坐标轴const gridHelper = new THREE.GridHelper(10, 10);  // 辅助网格线this.scene.add(axesHelper, gridHelper);const ambientLight = new THREE.AmbientLight('#fff', 1);  // 环境光const directLight = new THREE.DirectionalLight('#fff', 3);  // 平行光this.scene.add(ambientLight, directLight);const cubeMaterial = new THREE.MeshLambertMaterial({'color': 'gray',})const cubeGeometry = new THREE.CylinderGeometry(0.5, 1, 1)const cube = new THREE.Mesh(cubeGeometry, cubeMaterial)this.scene.add(cube)this.$el.appendChild(this.renderer.domElement);this.createParticles();this.createLights();this.bindEvents();this.resize();this.render();}createLights(){let directionX = 10, directionY = 10, directionZ = 10;const hemisphere = new THREE.HemisphereLight(0xffffff, 0xffffff, 0.6);// move the light right, up, and towards ushemisphere.position.set(10, 10, 10);const ambient = new THREE.AmbientLight(0xffffff, 1);  // 环境光const spot = new THREE.SpotLight(0xfdf4d5);spot.position.set(5, directionY * 4, 0);spot.angle = Math.PI / 2;spot.power = 2000;// eslint-disable-next-line @typescript-eslint/no-unused-varsconst spotLightHelper = new THREE.SpotLightHelper(spot, 0x00f);const direct = new THREE.DirectionalLight(0xffffff, 3);  // 平行光direct.position.set(-directionX / 3, directionY * 4, directionZ * 1.5);direct.castShadow = true;direct.shadow.camera.left = -directionX;direct.shadow.camera.right = directionX;direct.shadow.camera.top = directionZ;direct.shadow.camera.bottom = -directionZ;// eslint-disable-next-line @typescript-eslint/no-unused-varsconst directLightHelper = new THREE.DirectionalLightHelper(direct, 1, 0xf00);this.scene.add(hemisphere)this.scene.add(ambient)this.scene.add(spot)this.scene.add(direct)}createParticles() {//const plane = new THREE.PlaneBufferGeometry(500, 250, 250, 125);const plane = new THREE.PlaneGeometry(500, 250, 250, 125);const textureLoader = new THREE.TextureLoader();textureLoader.crossOrigin = '';const material = new THREE.ShaderMaterial({uniforms: {time: { value: 1.0 },texture: { value: textureLoader.load("https://s3-us-west-2.amazonaws.com/s.cdpn.io/1081752/spark1.png") },resolution: { value: new THREE.Vector2() } },vertexShader: document.getElementById('vertex-shader').textContent,fragmentShader: document.getElementById('fragment-shader').textContent,blending: THREE.AdditiveBlending,depthTest: false,transparent: true });//console.log(material.uniforms.texture);//const material = new THREE.PointsMaterial( { size: 1 } );this.particles = new THREE.Points(plane, material);this.particles.rotation.x = this.degToRad(-90);this.scene.add(this.particles);}bindEvents() {// window.addEventListener('mousemove', this.mousemove);window.addEventListener('resize', this.resize);}resize() {const w = window.innerWidth;const h = window.innerHeight;this.renderer.setSize(w, h);this.camera.aspect = w / h;this.camera.updateProjectionMatrix();}moveParticles() {this.particles.material.uniforms.time.value = this.time;this.particles.material.needsUpdate = true;}// Animationsrender() {requestAnimationFrame(this.render);this.time += .01;this.mesh.rotation.x += 0.01;this.mesh.rotation.y += 0.02;this.moveParticles();this.renderer.render(this.scene, this.camera);}// UtilsdegToRad(angle) {return angle * Math.PI / 180;}}initViewer = ()=>{drawWaveParticle();//let container = document.getElementById(domId);let container = document.querySelector('#webgl');let element = {el: container};new SceneViewer(element);}</script>

挂载到DOM渲染

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="#000000" /><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="renderer" content="webkit"><meta name="force-rendering" content="webkit"><meta name="google-site-verification" content="FTeR0c8arOPKh8c5DYh_9uu98_zJbaWw53J-Sch9MTg"><meta data-rh="true" name="keywords" content="three.js实现粒子动画"><meta data-rh="true" name="description" content="three.js实现粒子动画"><meta data-rh="true" property="og:title" content="three.js实现粒子动画"><link rel="icon" href="./favicon.ico"><title>three.js实现粒子动画</title><style>body {padding: 0;margin: 0;font: normal 14px/1.42857 Tahoma;background: radial-gradient(#a1b2c3, #123456);}.container {position: relative;}.mask{width: 100vw;height: 100vh;position: absolute;left: 0;background: radial-gradient(#123456, #c1d1e1);z-index: -1;}#webgl{position: absolute;left: 0;z-index: 1;}</style>
</head>
<body onload="initViewer()"><div class="container"><!-- 遮罩 --><div class="mask"></div><div id="webgl"></div></div><script>let initViewer = null</script></body>
</html>

粒子场景效果

e42ae32527264230b0e4e7c154632d5b.png

5ed99cf765834902a903a142448d17ad.png

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/297080.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++基础13:C++输入输出

此专栏为移动机器人知识体系下的编程语言中的 C {\rm C} C从入门到深入的专栏&#xff0c;参考书籍&#xff1a;《深入浅出 C {\rm C} C》(马晓锐)和《从 C {\rm C} C到 C {\rm C} C精通面向对象编程》(曾凡锋等)。 12.C输入/输出 12.1 C流类 计算机的输入和输出是数据传送的过…

大数据学习第十一天(复习linux指令3)

1、su和exit su命令就是用于账户切换的系统命令 基本语法&#xff1a;su[-] [用户名] 1&#xff09;-表示是否在切换用户后加载变量&#xff0c;建议带上 2&#xff09;参数&#xff1a;用户名&#xff0c;表示切换用户 3&#xff09;切换用户后&#xff0c;可以通过exit命令退…

Delphi 是一种内存安全的语言吗?

上个月&#xff0c;美国政府发布了 "回到基石 "报告&#xff1a; 通往安全和可衡量软件之路 "的报告。该报告是美国网络安全战略的一部分&#xff0c;重点关注多个领域&#xff0c;包括内存安全漏洞和质量指标。 许多在线杂志都对这份报告进行了评论&#xff0…

信息传播的AI时代:机器学习赋能新闻出版业的数字化之旅

&#x1f9d1; 作者简介&#xff1a;阿里巴巴嵌入式技术专家&#xff0c;深耕嵌入式人工智能领域&#xff0c;具备多年的嵌入式硬件产品研发管理经验。 &#x1f4d2; 博客介绍&#xff1a;分享嵌入式开发领域的相关知识、经验、思考和感悟,欢迎关注。提供嵌入式方向的学习指导…

中间件复习之-RPC框架

什么是RPC框架&#xff1f; RPC(Remote Procedure Call):远程过程调用。当多个应用部署在多个服务器上时&#xff0c;由于他们不在一个内存空间上&#xff0c;因此需要网络来进行通信&#xff0c;而RPC允许它像调用本地方法一样调用远程服务。 RPC原理 服务消费方通过RPC客户…

数据结构—堆

什么是堆 堆是一种特殊的树形结构&#xff0c;其中每个节点都有一个值。堆可以分为两种类型&#xff1a;最大堆和最小堆。在最大堆中&#xff0c;每个节点的值都大于等于其子节点的值&#xff1b;而在最小堆中&#xff0c;每个节点的值都小于等于其子节点的值。这种特性使得堆…

leetcode题库练习9\268\771

Leetcode: 9 回文数 简单的想法就是将数字转化为字符进行比较&#xff0c;但是这样占空间 class Solution { public:bool isPalindrome(int x) {if(x < 0) return false;if(x < 10 && x > 0) return true;vector<int> num;while(x > 9){num.push_b…

Three.js——scene场景、几何体位置旋转缩放、正射投影相机、透视投影相机

个人简介 &#x1f440;个人主页&#xff1a; 前端杂货铺 &#x1f64b;‍♂️学习方向&#xff1a; 主攻前端方向&#xff0c;正逐渐往全干发展 &#x1f4c3;个人状态&#xff1a; 研发工程师&#xff0c;现效力于中国工业软件事业 &#x1f680;人生格言&#xff1a; 积跬步…

Vue tree自定义滚动条位置

贴一张效果图&#xff0c;我的效果不方便贴出来 实现支持&#xff1a; 1、懒加载 2、普通加载 下面贴关键思想&#xff1a; document有一个获取element元素的方法。 let element document.getElementById(tree); let arr document.querySelectorAll(".nodelModel&quo…

用JSch实现远程传输文件并打包成jar

本文将简单介绍一下 JSch 这个Java的第三方库的一个简单用法&#xff0c;并以此为实例&#xff0c;讲解 IntelliJ 中打包成 jar 包的2种方式。 实现目标 我们的目标是&#xff0c;做出一个jar包&#xff0c;它能够实现类似于 scp 命令的远程传输文件的功能。用法如下&#xf…

arm的状态寄存器

目录 一、arm 的 PSRs二、CPSR2.1 CPSR_cxsf 三、SPSR四、APSR 一、arm 的 PSRs arm 中有很多程序状态寄存器&#xff08;Program Status Registers&#xff0c;PSRs&#xff09;用于存储处理器的状态信息&#xff0c;包括 CPSR\SPSR\FPSR\APSR 等&#xff1a; CPSR&#xff…

OpenHarmony实战:Makefile方式组织编译的库移植

以yxml库为例&#xff0c;其移植过程如下文所示。 源码获取 从仓库获取yxml源码&#xff0c;其目录结构如下表&#xff1a; 表1 源码目录结构 名称描述yxml/bench/benchmark相关代码yxml/test/测试输入输出文件&#xff0c;及测试脚本yxml/Makefile编译组织文件yxml/.gitat…

计算机网络-从输入网址到访问网站的全过程

当我们在浏览器中输入一个网址并按下回车键时&#xff0c;会发生一系列复杂的过程&#xff0c;最终使我们能够看到网页的内容。以下是这个过程的详细步骤&#xff1a; 客户端&#xff1a;首先&#xff0c;用户在浏览器中键入网址&#xff0c;然后浏览器会根据这个网址生成一个H…

MySQL count函数的使用

count&#xff08;&#xff09;函数在使用时参数好像不能设置为表达式&#xff0c;只能设置成指定字段或* 比如在查询性别为男的成员数目时不能写&#xff1a; select count(gendermale) from user_profile ; 否则直接得到6&#xff0c;也就是等价于select count(gender) fro…

java子集(力扣Leetcode78)

子集 力扣原题链接 问题描述 给定一个整数数组 nums&#xff0c;数组中的元素互不相同。返回该数组所有可能的子集&#xff08;幂集&#xff09;。解集不能包含重复的子集。可以按任意顺序返回解集。 示例 示例 1&#xff1a; 输入&#xff1a;nums [1,2,3] 输出&#x…

LabVIEW专栏三、探针和断点

探针和断点是LabVIEW调试的常用手段&#xff0c;该节以上一节的"测试耗时"为例 探针可以打在有线条的任何地方&#xff0c;打上后&#xff0c;经过这条线的所有最后一次的数值都会显示在探针窗口。断点可以打在程序框图的所有G代码对象&#xff0c;包括结构&#xf…

NVIDIA Jetson Xavier NX入门-镜像为jetpack5(3)——pytorch和torchvision安装

NVIDIA Jetson Xavier NX入门-镜像为jetpack5&#xff08;3&#xff09;——pytorch和torchvision安装 镜像为jetpack5系列&#xff1a; NVIDIA Jetson Xavier NX入门-镜像为jetpack5&#xff08;1&#xff09;——镜像烧写 NVIDIA Jetson Xavier NX入门-镜像为jetpack5&#…

第14章 数据结构与集合源码

一 数据结构剖析 我们举一个形象的例子来理解数据结构的作用&#xff1a; 战场&#xff1a;程序运行所需的软件、硬件环境 战术和策略&#xff1a;数据结构 敌人&#xff1a;项目或模块的功能需求 指挥官&#xff1a;编写程序的程序员 士兵和装备&#xff1a;一行一行的代码 …

代码随想录-力扣刷题-总结笔记02

代码随想录&#xff1a;代码随想录力扣&#xff1a;力扣 (LeetCode) 全球极客挚爱的技术成长平台 代码随想录-力扣刷题-总结笔记01代码随想录-力扣刷题-总结笔记02 目录 01、代码随想录 00、其他 ArrayList转数组 07、二叉树 7.0、递归法 7.1、二叉树的层序遍历模板 7.2…

vite.config.js

Vue3vite vite和webpack区别&#xff1f; 1.vite服务器启动速度比webpack快&#xff0c;由于vite启动的时候不需要打包&#xff0c;也就无需分析模块依赖、编译&#xff0c;所以启动速度非常快。当浏览器请求需要的模块时&#xff0c;再对模块进行编译&#xff0c;这种按需动态…