From a1d786297ceca32db23359bb39ce97c1a284c7fd Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sun, 4 Apr 2021 20:42:35 +0200 Subject: [PATCH] defineComponent for materials (#10) --- src/materials/BasicMaterial.js | 5 +++-- src/materials/CubeTexture.js | 6 +++--- src/materials/LambertMaterial.js | 5 +++-- src/materials/Map.js | 5 +++-- src/materials/MatcapMaterial.js | 6 +++--- src/materials/Material.js | 6 +++--- src/materials/PhongMaterial.js | 6 +++--- src/materials/PhysicalMaterial.js | 5 +++-- src/materials/ShaderMaterial.js | 6 +++--- src/materials/StandardMaterial.js | 6 +++--- src/materials/SubSurfaceMaterial.js | 5 +++-- src/materials/Texture.js | 6 +++--- src/materials/ToonMaterial.js | 5 +++-- 13 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/materials/BasicMaterial.js b/src/materials/BasicMaterial.js index d0183a2..798f376 100644 --- a/src/materials/BasicMaterial.js +++ b/src/materials/BasicMaterial.js @@ -1,8 +1,9 @@ +import { defineComponent } from 'vue'; import { MeshBasicMaterial } from 'three'; import { bindProps, propsValues } from '../tools'; import Material, { wireframeProps } from './Material'; -export default { +export default defineComponent({ extends: Material, props: { ...wireframeProps, @@ -16,4 +17,4 @@ export default { }, }, __hmrId: 'BasicMaterial', -}; +}); diff --git a/src/materials/CubeTexture.js b/src/materials/CubeTexture.js index 31ddd0e..058b7c8 100644 --- a/src/materials/CubeTexture.js +++ b/src/materials/CubeTexture.js @@ -1,7 +1,7 @@ +import { defineComponent, watch } from 'vue'; import { CubeTextureLoader, CubeRefractionMapping } from 'three'; -import { watch } from 'vue'; -export default { +export default defineComponent({ inject: ['material'], emits: ['loaded'], props: { @@ -49,4 +49,4 @@ export default { render() { return []; }, -}; +}); diff --git a/src/materials/LambertMaterial.js b/src/materials/LambertMaterial.js index b29c605..2637e49 100644 --- a/src/materials/LambertMaterial.js +++ b/src/materials/LambertMaterial.js @@ -1,8 +1,9 @@ +import { defineComponent } from 'vue'; import { MeshLambertMaterial } from 'three'; import { bindProps, propsValues } from '../tools'; import Material, { wireframeProps } from './Material'; -export default { +export default defineComponent({ extends: Material, props: { ...wireframeProps, @@ -16,4 +17,4 @@ export default { }, }, __hmrId: 'LambertMaterial', -}; +}); diff --git a/src/materials/Map.js b/src/materials/Map.js index b176226..a29d0db 100644 --- a/src/materials/Map.js +++ b/src/materials/Map.js @@ -1,6 +1,7 @@ +import { defineComponent } from 'vue'; import Texture from './Texture.js'; -export default { +export default defineComponent({ extends: Texture, inject: ['material'], created() { @@ -16,4 +17,4 @@ export default { }, }, __hmrId: 'Map', -}; +}); diff --git a/src/materials/MatcapMaterial.js b/src/materials/MatcapMaterial.js index 0f4349a..4e5161f 100644 --- a/src/materials/MatcapMaterial.js +++ b/src/materials/MatcapMaterial.js @@ -1,9 +1,9 @@ +import { defineComponent } from 'vue'; import { MeshMatcapMaterial, TextureLoader } from 'three'; -// import { watch } from 'vue'; import { propsValues, getMatcapUrl } from '../tools'; import Material from './Material'; -export default { +export default defineComponent({ extends: Material, props: { src: String, @@ -22,4 +22,4 @@ export default { }, }, __hmrId: 'MatcapMaterial', -}; +}); diff --git a/src/materials/Material.js b/src/materials/Material.js index 90c64df..c2fbc77 100644 --- a/src/materials/Material.js +++ b/src/materials/Material.js @@ -1,7 +1,7 @@ -import { watch } from 'vue'; +import { defineComponent, watch } from 'vue'; import { FrontSide } from 'three'; -export default { +export default defineComponent({ inject: ['three', 'mesh'], props: { color: { type: [String, Number], default: '#ffffff' }, @@ -52,7 +52,7 @@ export default { return this.$slots.default ? this.$slots.default() : []; }, __hmrId: 'Material', -}; +}); export const wireframeProps = { wireframe: { type: Boolean, default: false }, diff --git a/src/materials/PhongMaterial.js b/src/materials/PhongMaterial.js index 9585a96..1e70b4f 100644 --- a/src/materials/PhongMaterial.js +++ b/src/materials/PhongMaterial.js @@ -1,9 +1,9 @@ +import { defineComponent, watch } from 'vue'; import { MeshPhongMaterial } from 'three'; -import { watch } from 'vue'; import { bindProps, propsValues } from '../tools'; import Material, { wireframeProps } from './Material'; -export default { +export default defineComponent({ extends: Material, props: { emissive: { type: [Number, String], default: 0 }, @@ -33,4 +33,4 @@ export default { }, }, __hmrId: 'PhongMaterial', -}; +}); diff --git a/src/materials/PhysicalMaterial.js b/src/materials/PhysicalMaterial.js index 84edc6a..24a4bff 100644 --- a/src/materials/PhysicalMaterial.js +++ b/src/materials/PhysicalMaterial.js @@ -1,8 +1,9 @@ +import { defineComponent } from 'vue'; import { MeshPhysicalMaterial } from 'three'; import { propsValues } from '../tools'; import StandardMaterial from './StandardMaterial'; -export default { +export default defineComponent({ extends: StandardMaterial, props: { flatShading: Boolean, @@ -16,4 +17,4 @@ export default { }, }, __hmrId: 'PhysicalMaterial', -}; +}); diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index d9d14af..b384282 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -1,8 +1,8 @@ +import { defineComponent, watch } from 'vue'; import { ShaderMaterial } from 'three'; -import { watch } from 'vue'; import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tools'; -export default { +export default defineComponent({ inject: ['three', 'mesh'], props: { uniforms: { type: Object, default: () => { return {}; } }, @@ -37,4 +37,4 @@ export default { return this.$slots.default ? this.$slots.default() : []; }, __hmrId: 'ShaderMaterial', -}; +}); diff --git a/src/materials/StandardMaterial.js b/src/materials/StandardMaterial.js index 3e18406..99b5296 100644 --- a/src/materials/StandardMaterial.js +++ b/src/materials/StandardMaterial.js @@ -1,5 +1,5 @@ +import { defineComponent, watch } from 'vue'; import { MeshStandardMaterial } from 'three'; -import { watch } from 'vue'; import { bindProp, bindProps, propsValues } from '../tools'; import Material, { wireframeProps } from './Material'; @@ -19,7 +19,7 @@ const props = { flatShading: Boolean, }; -export default { +export default defineComponent({ extends: Material, props: { ...props, @@ -46,4 +46,4 @@ export default { }, }, __hmrId: 'StandardMaterial', -}; +}); diff --git a/src/materials/SubSurfaceMaterial.js b/src/materials/SubSurfaceMaterial.js index f6cebbe..1fc08c6 100644 --- a/src/materials/SubSurfaceMaterial.js +++ b/src/materials/SubSurfaceMaterial.js @@ -1,7 +1,8 @@ +import { defineComponent } from 'vue'; import { Color, ShaderMaterial as TShaderMaterial, UniformsUtils } from 'three'; import SubsurfaceScatteringShader from './SubsurfaceScatteringShader.js'; -export default { +export default defineComponent({ inject: ['three', 'mesh'], props: { color: { type: String, default: '#ffffff' }, @@ -51,4 +52,4 @@ export default { return []; }, __hmrId: 'SubSurfaceMaterial', -}; +}); diff --git a/src/materials/Texture.js b/src/materials/Texture.js index c7c3033..90df384 100644 --- a/src/materials/Texture.js +++ b/src/materials/Texture.js @@ -1,8 +1,8 @@ +import { defineComponent, watch } from 'vue'; import { ClampToEdgeWrapping, LinearFilter, LinearMipmapLinearFilter, TextureLoader, UVMapping } from 'three'; -import { watch } from 'vue'; import { bindProp } from '../tools'; -export default { +export default defineComponent({ inject: ['material'], emits: ['loaded'], props: { @@ -57,4 +57,4 @@ export default { }, }, render() { return []; }, -}; +}); diff --git a/src/materials/ToonMaterial.js b/src/materials/ToonMaterial.js index b87d4a1..719e20b 100644 --- a/src/materials/ToonMaterial.js +++ b/src/materials/ToonMaterial.js @@ -1,8 +1,9 @@ +import { defineComponent } from 'vue'; import { MeshToonMaterial } from 'three'; import { bindProps, propsValues } from '../tools'; import Material, { wireframeProps } from './Material'; -export default { +export default defineComponent({ extends: Material, props: { ...wireframeProps, @@ -16,4 +17,4 @@ export default { }, }, __hmrId: 'ToonMaterial', -}; +});