mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
shadow test
This commit is contained in:
parent
355576b8ae
commit
946c83388b
@ -1,9 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<Renderer ref="renderer">
|
<Renderer ref="renderer">
|
||||||
<Camera :position="{ z: 100 }"></Camera>
|
<Camera :position="{ z: 100 }"></Camera>
|
||||||
|
|
||||||
<LambertMaterial id="material" color="#0000ff"></LambertMaterial>
|
<LambertMaterial id="material" color="#0000ff"></LambertMaterial>
|
||||||
|
|
||||||
<Scene>
|
<Scene>
|
||||||
<PointLight :position="{ x: 0, y: 50, z: 50 }"></PointLight>
|
<PointLight :position="{ x: 0, y: 50, z: 50 }"></PointLight>
|
||||||
<Box ref="box" :size="10" :rotation="{ y: Math.PI / 4, z: Math.PI / 4 }" material="material"></Box>
|
<Box ref="box" :size="10" :rotation="{ y: Math.PI / 4, z: Math.PI / 4 }" material="material"></Box>
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<Renderer ref="renderer" :orbit-ctrl="{ enableDamping: true, dampingFactor: 0.05 }">
|
<Renderer ref="renderer" :shadow="true" :orbit-ctrl="{ enableDamping: true, dampingFactor: 0.05 }">
|
||||||
<Camera :position="{ z: 100 }"></Camera>
|
<Camera :position="{ z: 100 }"></Camera>
|
||||||
|
|
||||||
<PhongMaterial id="material" color="#ff0000"></PhongMaterial>
|
<PhongMaterial id="material" color="#ff0000"></PhongMaterial>
|
||||||
|
|
||||||
<Scene id="scene1">
|
<Scene id="scene1">
|
||||||
<PointLight :position="{ x: 0, y: 50, z: 50 }"></PointLight>
|
<PointLight :position="{ x: 0, y: 150, z: 150 }" :castShadow="true"></PointLight>
|
||||||
<InstancedMesh ref="imesh" material="material" :count="1000">
|
<InstancedMesh ref="imesh" material="material" :count="1000" :castShadow="true" :receiveShadow="true">
|
||||||
<BoxGeometry :size="2"></BoxGeometry>
|
<BoxGeometry :size="5"></BoxGeometry>
|
||||||
</InstancedMesh>
|
</InstancedMesh>
|
||||||
</Scene>
|
</Scene>
|
||||||
</Renderer>
|
</Renderer>
|
||||||
@ -39,8 +39,8 @@ export default {
|
|||||||
for (let i = 0; i < 1000; i++) {
|
for (let i = 0; i < 1000; i++) {
|
||||||
dummy.position.set(rndFS(100), rndFS(100), rndFS(100));
|
dummy.position.set(rndFS(100), rndFS(100), rndFS(100));
|
||||||
dummy.rotation.set(rndFS(1), rndFS(1), rndFS(1));
|
dummy.rotation.set(rndFS(1), rndFS(1), rndFS(1));
|
||||||
// const scale = rnd(0.2, 1);
|
const scale = rnd(0.2, 1);
|
||||||
// dummy.scale.set(scale, scale, scale);
|
dummy.scale.set(scale, scale, scale);
|
||||||
dummy.updateMatrix();
|
dummy.updateMatrix();
|
||||||
imesh.setMatrixAt(i, dummy.matrix);
|
imesh.setMatrixAt(i, dummy.matrix);
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<Renderer ref="renderer" :orbit-ctrl="{ enableDamping: true, dampingFactor: 0.05 }">
|
<Renderer ref="renderer" :orbit-ctrl="{ enableDamping: true, dampingFactor: 0.05 }">
|
||||||
<Camera :position="{ z: 100 }"></Camera>
|
<Camera :position="{ z: 100 }"></Camera>
|
||||||
|
|
||||||
<PhongMaterial id="material" color="#ffffff"></PhongMaterial>
|
<PhongMaterial id="material" color="#ffffff"></PhongMaterial>
|
||||||
|
|
||||||
<Scene id="scene1">
|
<Scene id="scene1">
|
||||||
<!-- <SpotLight color="#ffffff" :intensity="0.5" :position="{ y: 20, z: 50 }"></SpotLight> -->
|
<!-- <SpotLight color="#ffffff" :intensity="0.5" :position="{ y: 20, z: 50 }"></SpotLight> -->
|
||||||
<!-- <SpotLight color="#ff0000" :intensity="0.5" :position="{ y: -20, z: 50 }"></SpotLight> -->
|
<!-- <SpotLight color="#ff0000" :intensity="0.5" :position="{ y: -20, z: 50 }"></SpotLight> -->
|
||||||
|
|
||||||
<PointLight color="#ffffff" :intensity="0.5" :position="{ y: 50, z: 50 }"></PointLight>
|
<PointLight color="#ffffff" :intensity="0.5" :position="{ y: 50, z: 50 }"></PointLight>
|
||||||
<PointLight color="#ff0000" :intensity="0.5" :position="{ y: -50, z: 50 }"></PointLight>
|
<PointLight color="#ff0000" :intensity="0.5" :position="{ y: -50, z: 50 }"></PointLight>
|
||||||
|
|
||||||
<InstancedMesh ref="imesh" material="material" :count="1000">
|
<InstancedMesh ref="imesh" material="material" :count="1000">
|
||||||
<SphereGeometry :radius="2"></SphereGeometry>
|
<SphereGeometry :radius="2"></SphereGeometry>
|
||||||
</InstancedMesh>
|
</InstancedMesh>
|
||||||
|
@ -17,6 +17,10 @@ export default {
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
shadow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
orbitCtrl: {
|
orbitCtrl: {
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@ -42,6 +46,7 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.three.init(params)) {
|
if (this.three.init(params)) {
|
||||||
|
this.three.renderer.shadowMap.enabled = this.shadow;
|
||||||
this.animate();
|
this.animate();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,14 @@ export default {
|
|||||||
props: {
|
props: {
|
||||||
material: String,
|
material: String,
|
||||||
count: Number,
|
count: Number,
|
||||||
|
castShadow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
receiveShadow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
@ -23,6 +31,8 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.mesh = new InstancedMesh(this.conf.geometry, this.three.materials[this.material], this.count);
|
this.mesh = new InstancedMesh(this.conf.geometry, this.three.materials[this.material], this.count);
|
||||||
|
this.mesh.castShadow = this.castShadow;
|
||||||
|
this.mesh.receiveShadow = this.receiveShadow;
|
||||||
this.scene.add(this.mesh);
|
this.scene.add(this.mesh);
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
@ -8,12 +8,22 @@ export default {
|
|||||||
position: Object,
|
position: Object,
|
||||||
rotation: Object,
|
rotation: Object,
|
||||||
scale: Object,
|
scale: Object,
|
||||||
|
castShadow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
receiveShadow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.mesh = new Mesh(this.geometry, this.three.materials[this.material]);
|
this.mesh = new Mesh(this.geometry, this.three.materials[this.material]);
|
||||||
setFromProp(this.mesh.position, this.position);
|
setFromProp(this.mesh.position, this.position);
|
||||||
setFromProp(this.mesh.rotation, this.rotation);
|
setFromProp(this.mesh.rotation, this.rotation);
|
||||||
setFromProp(this.mesh.scale, this.scale);
|
setFromProp(this.mesh.scale, this.scale);
|
||||||
|
this.mesh.castShadow = this.castShadow;
|
||||||
|
this.mesh.receiveShadow = this.receiveShadow;
|
||||||
this.scene.add(this.mesh);
|
this.scene.add(this.mesh);
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
|
Loading…
Reference in New Issue
Block a user