Parcourir la source

Add options to remove and assign new materials in object UI config.

master
Palash Bansal il y a 1 an
Parent
révision
c67e0059d4
Aucun compte lié à l'adresse e-mail de l'auteur
5 fichiers modifiés avec 50 ajouts et 5 suppressions
  1. 1
    0
      .idea/threepipe.iml
  2. 1
    1
      package.json
  3. 10
    4
      src/assetmanager/MaterialManager.ts
  4. 1
    0
      src/core/IObject.ts
  5. 37
    0
      src/core/object/IObjectUi.ts

+ 1
- 0
.idea/threepipe.iml Voir le fichier

<excludeFolder url="file://$MODULE_DIR$/plugins/plugin-template-vite" /> <excludeFolder url="file://$MODULE_DIR$/plugins/plugin-template-vite" />
<excludeFolder url="file://$MODULE_DIR$/plugins/svg-renderer/docs" /> <excludeFolder url="file://$MODULE_DIR$/plugins/svg-renderer/docs" />
<excludeFolder url="file://$MODULE_DIR$/plugins/tweakpane-editor/docs" /> <excludeFolder url="file://$MODULE_DIR$/plugins/tweakpane-editor/docs" />
<excludeFolder url="file://$MODULE_DIR$/website/.vitepress/dist" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />

+ 1
- 1
package.json Voir le fichier

{ {
"name": "threepipe", "name": "threepipe",
"version": "0.0.38-dev",
"version": "0.0.38",
"description": "A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.", "description": "A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.mjs", "module": "dist/index.mjs",

+ 10
- 4
src/assetmanager/MaterialManager.ts Voir le fichier

const mat = e.target const mat = e.target
if (!mat || mat.assetType !== 'material') return if (!mat || mat.assetType !== 'material') return
mat.setDirty() mat.setDirty()
this._getMapsForMaterial(mat)
.forEach(map=>
!map.isRenderTargetTexture && map.userData.disposeOnIdle !== false &&
map.dispose && !isInScene(map) && map.dispose())
for (const map of this._getMapsForMaterial(mat)) {
const dispose = !map.isRenderTargetTexture
&& map.userData.disposeOnIdle !== false
&& !isInScene(map) // todo <- is this always required? this will be very slow if doing for every map of every material dispose on scene clear

if (dispose && typeof map.dispose === 'function') {
// console.log('disposing texture', map)
map.dispose()
}
}
// this.unregisterMaterial(mat) // not unregistering on dispose, that has to be done explicitly. todo: make an easy way to do that. // this.unregisterMaterial(mat) // not unregistering on dispose, that has to be done explicitly. todo: make an easy way to do that.
} }



+ 1
- 0
src/core/IObject.ts Voir le fichier

material?: IMaterial | IMaterial[] material?: IMaterial | IMaterial[]
/** /**
* Same as material but always returns an array. * Same as material but always returns an array.
* To set, just set `material` property
*/ */
readonly materials?: IMaterial[] readonly materials?: IMaterial[]
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention

+ 37
- 0
src/core/object/IObjectUi.ts Voir le fichier

import {ICamera} from '../ICamera' import {ICamera} from '../ICamera'
import {Vector3} from 'three' import {Vector3} from 'three'
import {ThreeViewer} from '../../viewer' import {ThreeViewer} from '../../viewer'
import {UnlitMaterial} from '../material/UnlitMaterial'
import {PhysicalMaterial} from '../material/PhysicalMaterial'

// todo move somewhere?
const defaultMaterial = new UnlitMaterial()
defaultMaterial.name = 'Default Unlit Material'
defaultMaterial.uiConfig = undefined as any


export function makeICameraCommonUiConfig(this: ICamera, config: UiObjectConfig): UiObjectConfig[] { export function makeICameraCommonUiConfig(this: ICamera, config: UiObjectConfig): UiObjectConfig[] {
return [ return [
type: 'folder', type: 'folder',
children: (this.material as IUiConfigContainer[]).map((a)=>a?.uiConfig).filter(a=>a), children: (this.material as IUiConfigContainer[]).map((a)=>a?.uiConfig).filter(a=>a),
} : (this.material as IUiConfigContainer)?.uiConfig, } : (this.material as IUiConfigContainer)?.uiConfig,
{
label: 'Remove Material(s)',
type: 'button',
hidden: ()=>!this.materials?.length || this.materials.length === 1 && this.materials[0] === defaultMaterial,
value: ()=>{
const mat = this.materials
this.material = [defaultMaterial]
return ()=> this.material = mat
},
},
{
label: 'New Physical Material',
type: 'button',
hidden: ()=>!(!this.materials?.length || this.materials.length === 1 && this.materials[0] === defaultMaterial),
value: ()=>{
const mat = this.materials
this.material = [new PhysicalMaterial()]
return ()=> this.material = mat
},
},
{
label: 'New Unlit Material',
type: 'button',
hidden: ()=>!(!this.materials?.length || this.materials.length === 1 && this.materials[0] === defaultMaterial),
value: ()=>{
const mat = this.materials
this.material = [new UnlitMaterial()]
return ()=> this.material = mat
},
},
] ]
;(config.children as UiObjectConfig[]).push(...ui) ;(config.children as UiObjectConfig[]).push(...ui)
} }

Chargement…
Annuler
Enregistrer