mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
update noisy components
This commit is contained in:
parent
057d245f65
commit
3641f02011
@ -27,7 +27,7 @@ export default {
|
|||||||
uTime, uNoiseCoef, uZCoef, uDispCoef,
|
uTime, uNoiseCoef, uZCoef, uDispCoef,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
this.three.onBeforeRender(() => {
|
this.three.onBeforeRender(() => {
|
||||||
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { MeshLambertMaterial } from 'three';
|
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
import Plane from '../../meshes/Plane.js';
|
import Plane from '../../meshes/Plane.js';
|
||||||
import snoise3 from '../../glsl/snoise3.glsl.js';
|
import snoise3 from '../../glsl/snoise3.glsl.js';
|
||||||
@ -22,16 +21,15 @@ export default {
|
|||||||
uTime, uNoiseCoef, uZCoef,
|
uTime, uNoiseCoef, uZCoef,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
this.createMaterial();
|
this.updateMaterial();
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
this.three.onBeforeRender(() => {
|
this.three.onBeforeRender(() => {
|
||||||
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createMaterial() {
|
updateMaterial() {
|
||||||
this.material = new MeshLambertMaterial({});
|
|
||||||
this.material.onBeforeCompile = (shader) => {
|
this.material.onBeforeCompile = (shader) => {
|
||||||
shader.uniforms.uTime = this.uTime;
|
shader.uniforms.uTime = this.uTime;
|
||||||
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
||||||
@ -53,9 +51,9 @@ export default {
|
|||||||
transformed.z += vNoise * uZCoef;
|
transformed.z += vNoise * uZCoef;
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materialShader = shader;
|
this.materialShader = shader;
|
||||||
};
|
};
|
||||||
|
this.material.needsupdate = true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'NoisyPlane',
|
__hmrId: 'NoisyPlane',
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { MeshPhysicalMaterial } from 'three';
|
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
import Sphere from '../../meshes/Sphere.js';
|
import Sphere from '../../meshes/Sphere.js';
|
||||||
import snoise4 from '../../glsl/snoise4.glsl.js';
|
import snoise4 from '../../glsl/snoise4.glsl.js';
|
||||||
@ -24,9 +23,8 @@ export default {
|
|||||||
uTime, uNoiseCoef, uDispCoef,
|
uTime, uNoiseCoef, uDispCoef,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
this.createGeometry();
|
this.updateMaterial();
|
||||||
this.createMaterial();
|
|
||||||
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
this.three.onBeforeRender(() => {
|
this.three.onBeforeRender(() => {
|
||||||
@ -34,8 +32,7 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createMaterial() {
|
updateMaterial() {
|
||||||
this.material = new MeshPhysicalMaterial();
|
|
||||||
this.material.onBeforeCompile = (shader) => {
|
this.material.onBeforeCompile = (shader) => {
|
||||||
shader.uniforms.uTime = this.uTime;
|
shader.uniforms.uTime = this.uTime;
|
||||||
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
||||||
@ -57,9 +54,9 @@ export default {
|
|||||||
transformed += normalize(position) * vNoise * uDispCoef;
|
transformed += normalize(position) * vNoise * uDispCoef;
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materialShader = shader;
|
this.materialShader = shader;
|
||||||
};
|
};
|
||||||
|
this.material.needsupdate = true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'NoisySphere',
|
__hmrId: 'NoisySphere',
|
||||||
|
@ -1,54 +1,37 @@
|
|||||||
import { FontLoader, MeshPhongMaterial, MeshStandardMaterial, TextBufferGeometry } from 'three';
|
|
||||||
import { watch } from 'vue';
|
import { watch } from 'vue';
|
||||||
import Mesh from '../../meshes/Mesh.js';
|
import Text from '../../meshes/Text.js';
|
||||||
import TextProps from '../../meshes/TextProps.js';
|
|
||||||
import snoise2 from '../../glsl/snoise2.glsl.js';
|
import snoise2 from '../../glsl/snoise2.glsl.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
extends: Mesh,
|
extends: Text,
|
||||||
props: {
|
props: {
|
||||||
...TextProps,
|
|
||||||
color: { type: [String, Number], default: 0xffffff },
|
|
||||||
timeCoef: { type: Number, default: 0.001 },
|
timeCoef: { type: Number, default: 0.001 },
|
||||||
noiseCoef: { type: Number, default: 0.015 },
|
noiseCoef: { type: Number, default: 0.015 },
|
||||||
zCoef: { type: Number, default: 10 },
|
zCoef: { type: Number, default: 10 },
|
||||||
},
|
},
|
||||||
created() {
|
setup(props) {
|
||||||
// add watchers
|
|
||||||
const watchProps = [
|
|
||||||
'text', 'size', 'height', 'curveSegments',
|
|
||||||
'bevelEnabled', 'bevelThickness', 'bevelSize', 'bevelOffset', 'bevelSegments',
|
|
||||||
'align',
|
|
||||||
];
|
|
||||||
watchProps.forEach(p => {
|
|
||||||
watch(() => this[p], () => {
|
|
||||||
if (this.font) this.refreshGeometry();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// uniforms
|
// uniforms
|
||||||
this.uTime = { value: 0 };
|
const uTime = { value: 0 };
|
||||||
this.uNoiseCoef = { value: this.noiseCoef };
|
const uNoiseCoef = { value: props.noiseCoef };
|
||||||
watch(() => this.noiseCoef, (value) => { this.uNoiseCoef.value = value; });
|
watch(() => props.noiseCoef, (value) => { uNoiseCoef.value = value; });
|
||||||
this.uZCoef = { value: this.zCoef };
|
const uZCoef = { value: props.zCoef };
|
||||||
watch(() => this.zCoef, (value) => { this.uZCoef.value = value; });
|
watch(() => props.zCoef, (value) => { uZCoef.value = value; });
|
||||||
|
|
||||||
const loader = new FontLoader();
|
return {
|
||||||
loader.load(this.fontSrc, (font) => {
|
uTime, uNoiseCoef, uZCoef,
|
||||||
this.font = font;
|
};
|
||||||
this.createGeometry();
|
},
|
||||||
this.createMaterial();
|
mounted() {
|
||||||
this.initMesh();
|
this.material = this.three.materials[this.materialId];
|
||||||
|
this.updateMaterial();
|
||||||
|
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
this.three.onBeforeRender(() => {
|
this.three.onBeforeRender(() => {
|
||||||
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
this.uTime.value = (Date.now() - startTime) * this.timeCoef;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
createMaterial() {
|
updateMaterial() {
|
||||||
this.material = new MeshPhongMaterial({ color: this.color });
|
|
||||||
this.material.onBeforeCompile = (shader) => {
|
this.material.onBeforeCompile = (shader) => {
|
||||||
shader.uniforms.uTime = this.uTime;
|
shader.uniforms.uTime = this.uTime;
|
||||||
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
shader.uniforms.uNoiseCoef = this.uNoiseCoef;
|
||||||
@ -72,24 +55,7 @@ export default {
|
|||||||
);
|
);
|
||||||
this.materialShader = shader;
|
this.materialShader = shader;
|
||||||
};
|
};
|
||||||
},
|
this.material.needsupdate = true;
|
||||||
createGeometry() {
|
|
||||||
this.geometry = new TextBufferGeometry(this.text, {
|
|
||||||
font: this.font,
|
|
||||||
size: this.size,
|
|
||||||
height: this.height,
|
|
||||||
depth: this.depth,
|
|
||||||
curveSegments: this.curveSegments,
|
|
||||||
bevelEnabled: this.bevelEnabled,
|
|
||||||
bevelThickness: this.bevelThickness,
|
|
||||||
bevelSize: this.bevelSize,
|
|
||||||
bevelOffset: this.bevelOffset,
|
|
||||||
bevelSegments: this.bevelSegments,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.align === 'center') {
|
|
||||||
this.geometry.center();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
__hmrId: 'NoisyText',
|
__hmrId: 'NoisyText',
|
||||||
|
Loading…
Reference in New Issue
Block a user