Fix softbody/cloth and softbody/cloth2 examples

Former-commit-id: 059c624bcc0232333e8c9456588b47086256d5b0
This commit is contained in:
Alexander Buzin 2017-01-21 22:39:38 +02:00
parent b726299540
commit 08d1196ca8
4 changed files with 141 additions and 120 deletions

View File

@ -26,7 +26,6 @@ const world = new WHS.App([
new WHS.app.AutoresizeModule()
]);
// TODO: Make cloth position start from specific position. [Softbodies issue]
const cloth = new WHS.Plane({ // Softbody (blue).
geometry: {
width: 60,

View File

@ -1,21 +1,59 @@
import * as UTILS from '../../globals';
const world = new (PHYSICS.$world(WHS.World))({
...UTILS.$world,
const world = new WHS.App([
new WHS.app.ElementModule(),
new WHS.app.SceneModule(),
new WHS.app.CameraModule({
position: new THREE.Vector3(0, 60, 120),
far: 10000
}),
new WHS.app.RenderingModule({
bgColor: 0x162129,
physics: {
ammo: process.ammoPath
renderer: {
antialias: true,
shadowmap: {
type: THREE.PCFSoftShadowMap
}
}
}),
new PHYSICS.WorldModule({
ammo: process.ammoPath,
gravity: new THREE.Vector3(0, -9.8, 0),
softbody: true
}),
new WHS.OrbitControlsModule(),
new WHS.app.AutoresizeModule()
]);
const cloth = new WHS.Plane({ // Softbody (blue).
geometry: {
width: 80,
height: 40,
wSegments: 20,
hSegments: 15
},
softbody: true,
modules: [
new PHYSICS.ClothModule({
mass: 4,
margin: 1,
damping: 0.01,
piterations: 12
})
],
gravity: {
y: -9.8,
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.softbody,
side: THREE.DoubleSide
}),
position: {
y: 50
},
camera: {
far: 10000,
position: [0, 30, 90]
rotation: {
x: Math.PI / 4
}
});
@ -26,71 +64,44 @@ const arm = new WHS.Box({ // Rigidbody (green).
depth: 6
},
mass: 0,
modules: [
new PHYSICS.BoxModule({
mass: 0
})
],
material: {
color: UTILS.$colors.mesh,
kind: 'phong'
},
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.mesh
}),
position: {
y: 50,
z: 10
y: 67,
z: 11
}
});
arm.addTo(world);
const cloth = new WHS.Plane({ // Softbody (blue).
geometry: {
width: 80,
height: 40,
wSegments: 20,
hSegments: 15
},
mass: 10,
softbody: true,
material: {
color: UTILS.$colors.softbody,
kind: 'phong',
side: THREE.DoubleSide
},
physics: {
margin: 1,
// damping: 0.03,
piterations: 12
},
position: {
y: 30
},
rotation: {
x: Math.PI / 4
}
cloth.addTo(world).then(() => {
cloth.appendAnchor(arm, 0, 1, false);
cloth.appendAnchor(arm, 20, 1, false);
});
cloth.addTo(world);
cloth.appendAnchor(world, arm, 0, 1, false);
cloth.appendAnchor(world, arm, 20, 1, false);
new WHS.Box({ // Rigidbody (green).
geometry: {
width: 10,
height: 10,
depth: 10
width: 30,
height: 30,
depth: 30
},
mass: 10,
modules: [
new PHYSICS.BoxModule({
mass: 10
})
],
material: {
color: UTILS.$colors.mesh,
kind: 'phong'
},
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.mesh
}),
position: {
y: 18
@ -98,7 +109,6 @@ new WHS.Box({ // Rigidbody (green).
}).addTo(world);
UTILS.addBoxPlane(world, 250);
UTILS.addBasicLights(world);
UTILS.addBasicLights(world, 0.5, [60, 60, 20], 400);
world.setControls(new WHS.OrbitControls());
world.start();

View File

@ -1,26 +1,57 @@
import * as UTILS from '../../globals';
const world = new (PHYSICS.$world(WHS.World))({
...UTILS.$world,
const world = new WHS.App([
new WHS.app.ElementModule(),
new WHS.app.SceneModule(),
new WHS.app.CameraModule({
position: new THREE.Vector3(0, 60, 120),
far: 10000
}),
new WHS.app.RenderingModule({
bgColor: 0x162129,
physics: {
ammo: process.ammoPath
renderer: {
antialias: true,
shadowmap: {
type: THREE.PCFSoftShadowMap
}
}
}),
new PHYSICS.WorldModule({
ammo: process.ammoPath,
gravity: new THREE.Vector3(0, -9.8, 0),
softbody: true
}),
new WHS.OrbitControlsModule(),
new WHS.app.AutoresizeModule()
]);
const cloth = new WHS.Tube({ // Softbody (blue).
geometry: {
path: new THREE.LineCurve3(new THREE.Vector3(0, 40, 0), new THREE.Vector3(0, 10, 0)),
segments: 20,
radius: 16,
radiusSegments: 16,
closed: false
},
softbody: true,
modules: [
new PHYSICS.SoftbodyModule({
mass: 1,
margin: 3,
damping: 0.03,
piterations: 12,
viterations: 12,
pressure: 300
})
],
gravity: {
y: -9.8,
},
camera: {
far: 10000,
position: [0, 30, 90]
}
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.softbody,
side: THREE.DoubleSide
})
});
const mouse = new WHS.VirtualMouse(world);
const arm = new WHS.Box({ // Rigidbody (green).
geometry: {
width: 80,
@ -28,12 +59,15 @@ const arm = new WHS.Box({ // Rigidbody (green).
depth: 6
},
mass: 0,
modules: [
new PHYSICS.BoxModule({
mass: 0
})
],
material: {
color: UTILS.$colors.mesh,
kind: 'phong'
},
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.mesh
}),
position: {
y: 50,
@ -42,36 +76,12 @@ const arm = new WHS.Box({ // Rigidbody (green).
});
arm.addTo(world);
const cloth = new WHS.Tube({ // Softbody (blue).
geometry: {
path: new THREE.LineCurve3(new THREE.Vector3(0, 30, 0), new THREE.Vector3(0, 10, 0)),
segments: 20,
radius: 12,
radiusSegments: 16,
closed: false
},
mass: 1,
softbody: true,
physics: {
margin: 1,
damping: 0.03,
piterations: 12
},
material: {
color: UTILS.$colors.softbody,
kind: 'phong',
side: THREE.DoubleSide
}
cloth.addTo(world).then(() => {
cloth.appendAnchor(arm, 0, 1, false);
cloth.appendAnchor(arm, 40, 1, false);
});
cloth.addTo(world);
cloth.appendAnchor(world, arm, 0, 1, false);
cloth.appendAnchor(world, arm, 40, 1, false);
const mouse = new WHS.VirtualMouse(world);
new WHS.Box({ // Rigidbody (green).
geometry: {
@ -80,12 +90,15 @@ new WHS.Box({ // Rigidbody (green).
depth: 10
},
mass: 10,
modules: [
new PHYSICS.BoxModule({
mass: 10
})
],
material: {
color: UTILS.$colors.mesh,
kind: 'phong'
},
material: new THREE.MeshPhongMaterial({
color: UTILS.$colors.mesh
}),
position: {
y: 18
@ -97,7 +110,6 @@ new WHS.Box({ // Rigidbody (green).
});
UTILS.addBoxPlane(world, 250);
UTILS.addBasicLights(world);
UTILS.addBasicLights(world, 0.5, [60, 60, 20], 400);
world.setControls(new WHS.OrbitControls());
world.start();

View File

@ -18,7 +18,7 @@ export class VirtualMouse extends Events {
super();
world.mouse = this;
this.manager = world;
this.manager = world.manager;
if (this.manager.get('renderer')) this.canvas = this.manager.get('renderer').domElement;