其他
2023二月随记 - chatGPT初体验
一、chatGPT初体验
// Create a sphere geometry
var sphereGeometry =newTHREE.SphereGeometry(50,32,32);
var sphereMaterial =newTHREE.MeshBasicMaterial({ color:0xffffff, wireframe:true});
var sphere =newTHREE.Mesh(sphereGeometry, sphereMaterial);
// Create a cloth geometry
var clothGeometry =newTHREE.PlaneGeometry(200,200,20,20);
var clothMaterial =newTHREE.MeshBasicMaterial({ color:0xffffff, side:THREE.DoubleSide, wireframe:true});
var cloth =newTHREE.Mesh(clothGeometry, clothMaterial);
// Set the position of the cloth above the sphere
cloth.position.set(0,100,0);
// Create a render loop using Three.js's animation function
functionrender(){
requestAnimationFrame(render);
// Apply gravity to the cloth vertices
for(var i =0; i < cloth.geometry.vertices.length; i++){
cloth.geometry.vertices[i].y -=0.1;
// Check if a vertex has collided with the sphere
var distance = cloth.geometry.vertices[i].distanceTo(sphere.position);
if(distance <50){
cloth.geometry.vertices[i].y =50-(50- cloth.geometry.vertices[i].y)*0.8;
}
}
// Update the cloth geometry
cloth.geometry.verticesNeedUpdate =true;
// Render the scene
renderer.render(scene, camera);
}