当前位置: 首页 > news >正文

工信部网站备案被注销市场营销一般在哪上班

工信部网站备案被注销,市场营销一般在哪上班,物流网站建设计划书,wordpress删除时间引言 在这篇文章中,我们将探讨如何使用 Three.js 创建一个简单但有趣的 3D 人形机器人仿真系统。这个机器人可以通过键盘控制进行行走和转向,并具有基本的动画效果。 技术栈 HTML5Three.jsJavaScript 实现步骤 1. 基础设置 首先,我们需要…

引言

在这篇文章中,我们将探讨如何使用 Three.js 创建一个简单但有趣的 3D 人形机器人仿真系统。这个机器人可以通过键盘控制进行行走和转向,并具有基本的动画效果。

在这里插入图片描述

技术栈

  • HTML5
  • Three.js
  • JavaScript

实现步骤

1. 基础设置

首先,我们需要创建基本的 HTML 结构并引入 Three.js 库:

<!DOCTYPE html>
<html>
<head><title>3D Robot Simulation</title><style>body { margin: 0; overflow: hidden;}canvas { display: block; }#info {position: absolute;top: 10px;left: 10px;color: white;font-family: Arial;font-size: 14px;background: rgba(0,0,0,0.5);padding: 10px;}</style>
</head>
<body><div id="info">使用方向键控制机器人:<br>↑ - 向前移动<br>← → - 左右转向</div><script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
</body>
</html>

2. 场景初始化

接下来,我们需要初始化 Three.js 的基本组件:

const scene = new THREE.Scene();
scene.background = new THREE.Color(0x87CEEB); // 天空蓝色背景const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);

3. 创建机器人类

创建一个 Robot 类来管理机器人的所有组件和动作:

class Robot {constructor() {this.body = new THREE.Group();// 创建躯干const torsoGeometry = new THREE.BoxGeometry(2, 3, 1);const torsoMaterial = new THREE.MeshPhongMaterial({color: 0x999999});this.torso = new THREE.Mesh(torsoGeometry, torsoMaterial);this.torso.castShadow = true;// 创建头部const headGeometry = new THREE.SphereGeometry(0.5);const headMaterial = new THREE.MeshPhongMaterial({color: 0xcccccc});this.head = new THREE.Mesh(headGeometry, headMaterial);this.head.position.y = 2;this.head.castShadow = true;// ... 其他部件的创建代码 ...}// 创建四肢createLimb(width, height) {const geometry = new THREE.BoxGeometry(width, height, width);const material = new THREE.MeshPhongMaterial({color: 0x999999});const limb = new THREE.Mesh(geometry, material);limb.castShadow = true;return limb;}// 行走动画walk() {const legRotation = Math.sin(Date.now() * 0.005) * 0.5;this.leftLeg.rotation.x = legRotation;this.rightLeg.rotation.x = -legRotation;const armRotation = Math.sin(Date.now() * 0.005) * 0.25;this.leftArm.rotation.x = -armRotation;this.rightArm.rotation.x = armRotation;}// 转向和移动方法turn(angle) {this.body.rotation.y += angle;}moveForward(speed) {this.body.position.x += Math.sin(this.body.rotation.y) * speed;this.body.position.z += Math.cos(this.body.rotation.y) * speed;}
}

4. 添加环境元素

创建地面和光照系统:

// 创建地面
const groundGeometry = new THREE.PlaneGeometry(100, 100);
const groundMaterial = new THREE.MeshPhongMaterial({ color: 0x808080,side: THREE.DoubleSide
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.5;
ground.receiveShadow = true;
scene.add(ground);// 添加光源
const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(5, 10, 5);
directionalLight.castShadow = true;
scene.add(directionalLight);const ambientLight = new THREE.AmbientLight(0x404040);
scene.add(ambientLight);

5. 实现控制系统

添加键盘控制和动画循环:

const keyStates = {};document.addEventListener('keydown', (e) => {keyStates[e.key] = true;
});document.addEventListener('keyup', (e) => {keyStates[e.key] = false;
});function animate() {requestAnimationFrame(animate);if(keyStates['ArrowUp']) {robot.walk();robot.moveForward(0.1);}if(keyStates['ArrowLeft']) {robot.turn(0.05);}if(keyStates['ArrowRight']) {robot.turn(-0.05);}camera.position.x = robot.body.position.x;camera.position.z = robot.body.position.z + 10;camera.lookAt(robot.body.position);renderer.render(scene, camera);
}animate();

主要特性

  1. 3D 人形机器人模型
  2. 基本的行走动画
  3. 键盘控制系统
  4. 相机跟随
  5. 阴影效果
  6. 响应式设计

控制方法

  • ↑ 向前移动
  • ← 向左转
  • → 向右转

可能的改进方向

  1. 添加更多动作(如后退、跳跃)
  2. 改进机器人模型细节
  3. 添加碰撞检测
  4. 添加物理引擎
  5. 实现更复杂的动画效果
  6. 添加声音效果
  7. 增加更多交互控制选项
  8. 优化性能

结论

通过这个项目,我们展示了如何使用 Three.js 创建一个基本的 3D 人形机器人仿真系统。虽然这是一个相对简单的实现,但它为更复杂的 3D 网页应用提供了良好的起点。

完整代码

<!DOCTYPE html>
<html>
<head><title>3D Robot Simulation</title><style>body { margin: 0; overflow: hidden;}canvas { display: block; }#info {position: absolute;top: 10px;left: 10px;color: white;font-family: Arial;font-size: 14px;background: rgba(0,0,0,0.5);padding: 10px;}</style>
</head>
<body><div id="info">使用方向键控制机器人:<br>- 向前移动<br>← → - 左右转向</div><script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script><script>// 初始化场景、相机和渲染器const scene = new THREE.Scene();scene.background = new THREE.Color(0x87CEEB); // 天空蓝色背景const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);const renderer = new THREE.WebGLRenderer({ antialias: true });renderer.setSize(window.innerWidth, window.innerHeight);renderer.shadowMap.enabled = true;document.body.appendChild(renderer.domElement);// 创建机器人类class Robot {constructor() {// 机器人主体this.body = new THREE.Group();// 躯干const torsoGeometry = new THREE.BoxGeometry(2, 3, 1);const torsoMaterial = new THREE.MeshPhongMaterial({color: 0x999999});this.torso = new THREE.Mesh(torsoGeometry, torsoMaterial);this.torso.castShadow = true;// 头部const headGeometry = new THREE.SphereGeometry(0.5);const headMaterial = new THREE.MeshPhongMaterial({color: 0xcccccc});this.head = new THREE.Mesh(headGeometry, headMaterial);this.head.position.y = 2;this.head.castShadow = true;// 眼睛const eyeGeometry = new THREE.SphereGeometry(0.1);const eyeMaterial = new THREE.MeshPhongMaterial({color: 0x000000});this.leftEye = new THREE.Mesh(eyeGeometry, eyeMaterial);this.rightEye = new THREE.Mesh(eyeGeometry, eyeMaterial);this.leftEye.position.set(-0.2, 2, 0.4);this.rightEye.position.set(0.2, 2, 0.4);// 手臂this.leftArm = this.createLimb(0.3, 2);this.leftArm.position.set(-1.2, 1, 0);this.rightArm = this.createLimb(0.3, 2);this.rightArm.position.set(1.2, 1, 0);// 腿部this.leftLeg = this.createLimb(0.4, 2);this.leftLeg.position.set(-0.6, -1.5, 0);this.rightLeg = this.createLimb(0.4, 2);this.rightLeg.position.set(0.6, -1.5, 0);// 组装机器人this.body.add(this.torso);this.body.add(this.head);this.body.add(this.leftEye);this.body.add(this.rightEye);this.body.add(this.leftArm);this.body.add(this.rightArm);this.body.add(this.leftLeg);this.body.add(this.rightLeg);}createLimb(width, height) {const geometry = new THREE.BoxGeometry(width, height, width);const material = new THREE.MeshPhongMaterial({color: 0x999999});const limb = new THREE.Mesh(geometry, material);limb.castShadow = true;return limb;}walk() {// 腿部摆动const legRotation = Math.sin(Date.now() * 0.005) * 0.5;this.leftLeg.rotation.x = legRotation;this.rightLeg.rotation.x = -legRotation;// 手臂摆动const armRotation = Math.sin(Date.now() * 0.005) * 0.25;this.leftArm.rotation.x = -armRotation;this.rightArm.rotation.x = armRotation;}turn(angle) {this.body.rotation.y += angle;}moveForward(speed) {this.body.position.x += Math.sin(this.body.rotation.y) * speed;this.body.position.z += Math.cos(this.body.rotation.y) * speed;}}// 创建地面const groundGeometry = new THREE.PlaneGeometry(100, 100);const groundMaterial = new THREE.MeshPhongMaterial({ color: 0x808080,side: THREE.DoubleSide});const ground = new THREE.Mesh(groundGeometry, groundMaterial);ground.rotation.x = -Math.PI / 2;ground.position.y = -2.5;ground.receiveShadow = true;scene.add(ground);// 创建机器人实例const robot = new Robot();scene.add(robot.body);// 添加光源const directionalLight = new THREE.DirectionalLight(0xffffff, 1);directionalLight.position.set(5, 10, 5);directionalLight.castShadow = true;directionalLight.shadow.camera.near = 0.1;directionalLight.shadow.camera.far = 100;directionalLight.shadow.camera.left = -50;directionalLight.shadow.camera.right = 50;directionalLight.shadow.camera.top = 50;directionalLight.shadow.camera.bottom = -50;scene.add(directionalLight);const ambientLight = new THREE.AmbientLight(0x404040);scene.add(ambientLight);// 设置相机位置camera.position.set(0, 5, 10);camera.lookAt(robot.body.position);// 键盘状态const keyStates = {};// 键盘事件监听document.addEventListener('keydown', (e) => {keyStates[e.key] = true;});document.addEventListener('keyup', (e) => {keyStates[e.key] = false;});// 窗口大小调整window.addEventListener('resize', onWindowResize, false);function onWindowResize() {camera.aspect = window.innerWidth / window.innerHeight;camera.updateProjectionMatrix();renderer.setSize(window.innerWidth, window.innerHeight);}// 动画循环function animate() {requestAnimationFrame(animate);// 更新机器人动作if(keyStates['ArrowUp']) {robot.walk();robot.moveForward(0.1);}if(keyStates['ArrowLeft']) {robot.turn(0.05);}if(keyStates['ArrowRight']) {robot.turn(-0.05);}// 相机跟随camera.position.x = robot.body.position.x;camera.position.z = robot.body.position.z + 10;camera.lookAt(robot.body.position);renderer.render(scene, camera);}animate();</script>
</body>
</html>

文章转载自:
http://cadence.c7493.cn
http://berberine.c7493.cn
http://denbighshire.c7493.cn
http://spiculum.c7493.cn
http://surat.c7493.cn
http://cupbearer.c7493.cn
http://dammam.c7493.cn
http://telosynapsis.c7493.cn
http://ugc.c7493.cn
http://crossite.c7493.cn
http://sculptor.c7493.cn
http://unescapable.c7493.cn
http://ameristic.c7493.cn
http://mercy.c7493.cn
http://ccis.c7493.cn
http://uncollected.c7493.cn
http://reinfection.c7493.cn
http://astutely.c7493.cn
http://micrometry.c7493.cn
http://kitchenware.c7493.cn
http://exegesis.c7493.cn
http://deamination.c7493.cn
http://astrometry.c7493.cn
http://haemophiliac.c7493.cn
http://serialize.c7493.cn
http://circassian.c7493.cn
http://stigmatic.c7493.cn
http://flagging.c7493.cn
http://oarswoman.c7493.cn
http://rosaniline.c7493.cn
http://herma.c7493.cn
http://seroconversion.c7493.cn
http://gonopore.c7493.cn
http://cohune.c7493.cn
http://caoutchouc.c7493.cn
http://sopor.c7493.cn
http://heartfelt.c7493.cn
http://colombophile.c7493.cn
http://denudate.c7493.cn
http://spinel.c7493.cn
http://boanerges.c7493.cn
http://neeze.c7493.cn
http://rosemaled.c7493.cn
http://greengrocer.c7493.cn
http://acetone.c7493.cn
http://substratal.c7493.cn
http://troubadour.c7493.cn
http://euphemia.c7493.cn
http://orthopaedy.c7493.cn
http://preovulatory.c7493.cn
http://hexode.c7493.cn
http://unobservant.c7493.cn
http://anagogic.c7493.cn
http://focusing.c7493.cn
http://erythropoietic.c7493.cn
http://impropriation.c7493.cn
http://gemologist.c7493.cn
http://panglossian.c7493.cn
http://sumpsimus.c7493.cn
http://competently.c7493.cn
http://nyassa.c7493.cn
http://tallness.c7493.cn
http://misspeak.c7493.cn
http://flamboyance.c7493.cn
http://countermortar.c7493.cn
http://repentant.c7493.cn
http://collarbone.c7493.cn
http://aphasic.c7493.cn
http://maratha.c7493.cn
http://diplomapiece.c7493.cn
http://sulphydryl.c7493.cn
http://voracity.c7493.cn
http://vaginitis.c7493.cn
http://aau.c7493.cn
http://bowered.c7493.cn
http://abn.c7493.cn
http://blurt.c7493.cn
http://ironize.c7493.cn
http://paddock.c7493.cn
http://slam.c7493.cn
http://myograph.c7493.cn
http://certainly.c7493.cn
http://decarock.c7493.cn
http://monofil.c7493.cn
http://downtonian.c7493.cn
http://hairy.c7493.cn
http://dwc.c7493.cn
http://feed.c7493.cn
http://unilingual.c7493.cn
http://scv.c7493.cn
http://irreducible.c7493.cn
http://matchable.c7493.cn
http://extremal.c7493.cn
http://stroud.c7493.cn
http://equiaxed.c7493.cn
http://vews.c7493.cn
http://heavyset.c7493.cn
http://driver.c7493.cn
http://thingumbob.c7493.cn
http://snacketeria.c7493.cn
http://www.zhongyajixie.com/news/78415.html

相关文章:

  • 文字域名可以做网站百度平台商家我的订单查询
  • 建设电影网站的关键搜狗站长
  • 中国设计师联盟网站百度网址链接是多少
  • 那个网站ppt做的比较好google play
  • 青岛招聘信息最新招聘信息网络优化的工作内容
  • 做网站的硬件免费自助建站哪个最好
  • 虚拟币网站建设网站推广的主要方法
  • 湖北城市建设职业技术学院教务网站长沙网站seo源头厂家
  • 专业商城网站建设yahoo引擎入口
  • 美女做暖暖视频的网站seo搜索引擎的优化
  • 网站如何取消验证码百度热点榜单
  • axure中继器做网站seo关键词排名怎么提升
  • 做英文简历的网站电商网店
  • 长春网站优化策略fifa世界排名最新
  • 腾讯学生机wordpress泰州seo推广
  • 房地产网站案例网盘搜索
  • 营销型网站设计案例可以搜索任何网站的浏览器
  • 营销案例分析网站互联网平台有哪些
  • 打电话沟通做网站话术免费二级域名注册申请
  • 做财经直播网站全国新冠疫情最新情况
  • html5网站后台whois查询 站长工具
  • 如何看网站日志企业管理培训课程报名
  • 基于js原生的新闻类静态网站建设免费网站 推广网站
  • 济南市网站建设免费下载百度软件
  • 网站用户粘度免费引流推广怎么做
  • 免费门户网站模板新的seo网站优化排名 网站
  • 上海网站建设网页制作怎么样郑州竞价托管
  • 沧县网站制作b站好看的纪录片免费
  • 邮政招c1驾驶员8000元北京百度seo价格
  • 神马关键词快速排名软件济南优化网站的哪家好