mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-12 22:00:56 -05:00
Improve WebGL Raycaster example (#478)
Signed-off-by: Ryan Russell <ryanrussell@users.noreply.github.com>
This commit is contained in:
@@ -68,15 +68,15 @@ setcolor = "#000000"
|
||||
scene.background = THREE.Color.new(setcolor)
|
||||
scene.fog = THREE.Fog.new(setcolor, 2.5, 3.5);
|
||||
|
||||
sceneGruop = THREE.Object3D.new();
|
||||
particularGruop = THREE.Object3D.new();
|
||||
sceneGroup = THREE.Object3D.new();
|
||||
particularGroup = THREE.Object3D.new();
|
||||
|
||||
def mathRandom(num = 1):
|
||||
setNumber = - Math.random() * num + Math.random() * num
|
||||
return setNumber
|
||||
|
||||
particularGruop = THREE.Object3D.new();
|
||||
modularGruop = THREE.Object3D.new();
|
||||
particularGroup = THREE.Object3D.new();
|
||||
modularGroup = THREE.Object3D.new();
|
||||
|
||||
perms = {"flatShading":True, "color":"#111111", "transparent":False, "opacity":1, "wireframe":False}
|
||||
perms = Object.fromEntries(to_js(perms))
|
||||
@@ -84,7 +84,7 @@ perms = Object.fromEntries(to_js(perms))
|
||||
particle_perms = {"color":"#FFFFFF", "side":THREE.DoubleSide}
|
||||
particle_perms = Object.fromEntries(to_js(particle_perms))
|
||||
|
||||
def create_cubes(mathRandom, modularGruop):
|
||||
def create_cubes(mathRandom, modularGroup):
|
||||
i = 0
|
||||
while i < 30:
|
||||
geometry = THREE.IcosahedronGeometry.new();
|
||||
@@ -102,13 +102,13 @@ def create_cubes(mathRandom, modularGruop):
|
||||
cube.rotation.y = mathRandom(180 * Math.PI / 180);
|
||||
cube.rotation.z = mathRandom(180 * Math.PI / 180);
|
||||
cube.position.set(cube.positionX, cube.positionY, cube.positionZ);
|
||||
modularGruop.add(cube);
|
||||
modularGroup.add(cube);
|
||||
i += 1
|
||||
|
||||
create_cubes(mathRandom, modularGruop)
|
||||
create_cubes(mathRandom, modularGroup)
|
||||
|
||||
|
||||
def generateParticle(mathRandom, particularGruop, num, amp = 2):
|
||||
def generateParticle(mathRandom, particularGroup, num, amp = 2):
|
||||
gmaterial = THREE.MeshPhysicalMaterial.new(particle_perms);
|
||||
gparticular = THREE.CircleGeometry.new(0.2,5);
|
||||
i = 0
|
||||
@@ -119,14 +119,14 @@ def generateParticle(mathRandom, particularGruop, num, amp = 2):
|
||||
particular.rotation.set(mathRandom(),mathRandom(),mathRandom());
|
||||
particular.scale.set(pscale,pscale,pscale);
|
||||
particular.speedValue = mathRandom(1);
|
||||
particularGruop.add(particular);
|
||||
particularGroup.add(particular);
|
||||
i += 1
|
||||
|
||||
generateParticle(mathRandom, particularGruop, 200, 2)
|
||||
generateParticle(mathRandom, particularGroup, 200, 2)
|
||||
|
||||
sceneGruop.add(particularGruop);
|
||||
scene.add(modularGruop);
|
||||
scene.add(sceneGruop);
|
||||
sceneGroup.add(particularGroup);
|
||||
scene.add(modularGroup);
|
||||
scene.add(sceneGroup);
|
||||
|
||||
camera.position.set(0, 0, cameraRange);
|
||||
cameraValue = False;
|
||||
@@ -143,7 +143,7 @@ light.penumbra = 0.5;
|
||||
lightBack = THREE.PointLight.new(0x0FFFFF, 1);
|
||||
lightBack.position.set(0, -3, -1);
|
||||
|
||||
scene.add(sceneGruop);
|
||||
scene.add(sceneGroup);
|
||||
scene.add(light);
|
||||
scene.add(lightBack);
|
||||
|
||||
@@ -164,16 +164,16 @@ camera.lookAt(scene.position)
|
||||
while True:
|
||||
time = performance.now() * 0.0003;
|
||||
i = 0
|
||||
while i < particularGruop.children.length:
|
||||
newObject = particularGruop.children[i];
|
||||
while i < particularGroup.children.length:
|
||||
newObject = particularGroup.children[i];
|
||||
newObject.rotation.x += newObject.speedValue/10;
|
||||
newObject.rotation.y += newObject.speedValue/10;
|
||||
newObject.rotation.z += newObject.speedValue/10;
|
||||
i += 1
|
||||
|
||||
i = 0
|
||||
while i < modularGruop.children.length:
|
||||
newCubes = modularGruop.children[i];
|
||||
while i < modularGroup.children.length:
|
||||
newCubes = modularGroup.children[i];
|
||||
newCubes.rotation.x += 0.008;
|
||||
newCubes.rotation.y += 0.005;
|
||||
newCubes.rotation.z += 0.003;
|
||||
@@ -183,10 +183,10 @@ while True:
|
||||
newCubes.position.z = Math.sin(time * newCubes.positionY) * newCubes.positionX;
|
||||
i += 1
|
||||
|
||||
particularGruop.rotation.y += 0.005;
|
||||
particularGroup.rotation.y += 0.005;
|
||||
|
||||
modularGruop.rotation.y -= ((mouse.x * 4) + modularGruop.rotation.y) * uSpeed;
|
||||
modularGruop.rotation.x -= ((-mouse.y * 4) + modularGruop.rotation.x) * uSpeed;
|
||||
modularGroup.rotation.y -= ((mouse.x * 4) + modularGroup.rotation.y) * uSpeed;
|
||||
modularGroup.rotation.x -= ((-mouse.y * 4) + modularGroup.rotation.x) * uSpeed;
|
||||
|
||||
renderer.render( scene, camera )
|
||||
await asyncio.sleep(0.02)
|
||||
|
||||
Reference in New Issue
Block a user