亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

三.js顆粒不出現在形狀內

三.js顆粒不出現在形狀內

料青山看我應如是 2022-09-29 15:43:05
我一直在嘗試修改此演示。目前,粒子被放置在文本幾何體中,我在這里的最終目標是相反的。我想:將文本幾何圖形替換為方框、圓錐體和球體。用數字替換粒子。所以基本上,把數字放在其中一個形狀內,并對粒子進行動畫處理,以延遲形成下一個形狀。首先,我嘗試改變形狀,使粒子和其他所有東西保持原樣。但是,由于某種原因,粒子沒有出現。我不確定為什么粒子沒有渲染?控制臺不記錄任何錯誤。另外,將數字作為粒子的最快方法是什么?如果有人能給我指出正確的方向,那就太好了。謝謝!
查看完整描述

1 回答

?
胡子哥哥

TA貢獻1825條經驗 獲得超6個贊

抱歉,我實際上能夠修復未渲染的粒子。我正在迭代 而不是 .shapesparticleCount


// Particles

for (var i = 0; i < shapes; i++) {

                    ^^^^^^

  let vertex = new THREE.Vector3();

  vertex.x = 0;

  vertex.y = 0;

  vertex.z = 0;

  particles.vertices.push(vertex);

}

下面是加載粒子的更新代碼。

// Options

const shapes = [{

      "geoCode": new THREE.ConeGeometry(25, 50, 30),

      "color": 0x11659C,

    },

    {

      "geoCode": new THREE.SphereGeometry(25, 33, 33),

      "color": 0x8F3985,

    },

    {

      "geoCode": new THREE.BoxGeometry(50, 50, 50),

      "color": 0x029894,

    }

  ],

  triggers = document.getElementsByTagName('span'),

  particleCount = 1000,

  particleSize = 3,

  defaultAnimationSpeed = 1,

  morphAnimationSpeed = 18,

  color = '#FFFFFF';


// Renderer

const renderer = new THREE.WebGLRenderer({

  antialias: true

});

renderer.setPixelRatio(window.devicePixelRatio);

renderer.setSize(window.innerWidth, window.innerHeight);

document.body.appendChild(renderer.domElement);


// Ensure Full Screen on Resize

function fullScreen() {

  camera.aspect = window.innerWidth / window.innerHeight;

  camera.updateProjectionMatrix();


  renderer.setSize(window.innerWidth, window.innerHeight);

}


window.addEventListener('resize', fullScreen, false)


// Scene

const scene = new THREE.Scene();


// Camera and position

const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000);


camera.position.y = -45;

camera.position.z = 45;


// Lighting

const light = new THREE.AmbientLight(0xFFFFFF, 1);

scene.add(light);


// Particle Vars

const particles = new THREE.Geometry();


const pMaterial = new THREE.PointsMaterial({

  size: particleSize,

});


// Texts

const loader = new THREE.FontLoader();

const typeface = 'https://dl.dropboxusercontent.com/s/bkqic142ik0zjed/swiss_black_cond.json?';


//CONTINUE


loader.load(typeface, (font) => {

  Array.from(shapes).forEach((shape, idx) => {

    shapes[idx].geometry = shapes[idx].geoCode;

    const material = new THREE.MeshLambertMaterial({

      color: shapes[idx].color,

      opacity: .5,

      transparent: true,

      wireframe: true

    });

    const mesh = new THREE.Mesh(shapes[idx].geometry, material);

    //THREE.GeometryUtils.center(shapes[idx].geometry)

    scene.add(mesh);

    shapes[idx].particles = new THREE.Geometry();

    shapes[idx].points = THREE.GeometryUtils.randomPointsInGeometry(shapes[idx].geometry, particleCount);

    createVertices(shapes[idx].particles, shapes[idx].points)

    enableTrigger(shape, idx, triggers[idx]);

  });

});


// Particles

for (var i = 0; i < particleCount; i++) {


  const vertex = new THREE.Vector3();

  vertex.x = 0;

  vertex.y = 0;

  vertex.z = 0;

  particles.vertices.push(vertex);

}


function createVertices(emptyArray, points) {

  for (var p = 0; p < particleCount; p++) {

    const vertex = new THREE.Vector3();

    vertex.x = points[p]['x'];

    vertex.y = points[p]['y'];

    vertex.z = points[p]['z'];


    emptyArray.vertices.push(vertex);

  }

}


function enableTrigger(trigger, idx, el) {

  el.setAttribute('data-disabled', false);


  el.addEventListener('click', () => {

    morphTo(shapes[idx].particles, el.dataset.color);

  })


  if (idx == 0) {

    morphTo(shapes[idx].particles, el.dataset.color);

  }

}


let particleSystem = new THREE.Points(

  particles,

  pMaterial

);


particleSystem.sortParticles = true;


// Add the particles to the scene

scene.add(particleSystem);


// Animate

const normalSpeed = (defaultAnimationSpeed / 100),

  fullSpeed = (morphAnimationSpeed / 100)


let animationVars = {

  speed: normalSpeed,

  color: color,

  rotation: 100

}


function animate() {

  particleSystem.rotation.y += animationVars.speed;

  particles.verticesNeedUpdate = true;


  camera.position.z = animationVars.rotation;

  camera.position.y = animationVars.rotation;

  camera.lookAt(scene.position);


  particleSystem.material.color = new THREE.Color(animationVars.color);


  window.requestAnimationFrame(animate);

  renderer.render(scene, camera);

}


animate();


function morphTo(newParticles, color = '#FFFFFF') {


  TweenMax.to(animationVars, 2, {

    ease: Linear.easeNone,

    color: color

  });


  particleSystem.material.color.setHex(color);


  for (let i = 0; i < particles.vertices.length; i++) {

    TweenMax.to(particles.vertices[i], 2, {

      ease: Elastic.easeOut.config(0.1, .3),

      x: newParticles.vertices[i].x,

      y: newParticles.vertices[i].y,

      z: newParticles.vertices[i].z

    })

  }

}

body {

  font-family: 'Titillium Web', sans-serif;

  margin: 0;

  overflow: hidden;

}


.triggers {

  bottom: 20px;

  color: white;

  left: 50%;

  position: absolute;

  text-align: center;

  transform: translateX(-50%);

  width: 100%;

  z-index: 10;

}


.triggers span {

  cursor: pointer;

  display: inline-block;

  font-size: 14px;

  margin: 0 20px;

  padding: 2px 4px;

  transition: opacity 0.5s, color 0.5s;

}


.triggers span[data-disabled="true"] {

  opacity: 0.3;

  pointer-events: none;

}


.triggers span:hover {

  color: red;

}

<div class="triggers">

  <span data-disabled="true" data-color="#3D8CD0">CLICK</span>

  <span data-disabled="true" data-color="#D32A7B">TO</span>

  <span data-disabled="true" data-color="#2AD37A">SWITCH</span>

</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/109/three.js" type="text/javascript"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js" type="text/javascript"></script>

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/605067/GeometryUtils.js" type="text/javascript"></script>

注意這篇文章只有一個不渲染的粒子的解決方案。我將接受回答我應該如何用數字替換粒子的帖子。



查看完整回答
反對 回復 2022-09-29
  • 1 回答
  • 0 關注
  • 63 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號