Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

add simple material option to models. Trigger volumes can now be scaled #6424

Merged
merged 3 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/client-core/i18n/en/editor.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"error-url": "Error Loading From URL",
"lbl-loopAnimation": "Loop Animation",
"lbl-isAvatar": "Is Avatar",
"lbl-useBasicMaterials": "Use Basic Materials",
"lbl-isGPUInstancing": "Is Using GPU Instancing",
"lbl-isDynamic": "Is Dynamic",
"lbl-castShadow": "Cast Shadow",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export const ModelNodeEditor: EditorComponentType = (props) => {
onChange={updateProperty(ModelComponent, 'matrixAutoUpdate')}
/>
</InputGroup>
<InputGroup name="Use Basic Materials" label={t('editor:properties.model.lbl-useBasicMaterials')}>
<BooleanInput
value={modelComponent.useBasicMaterial}
onChange={updateProperty(ModelComponent, 'useBasicMaterial')}
/>
</InputGroup>
<InputGroup name="Is Using GPU Instancing" label={t('editor:properties.model.lbl-isGPUInstancing')}>
<BooleanInput
value={modelComponent.isUsingGPUInstancing}
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/scene/components/ModelComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ModelComponentType = {
textureOverride: string
materialOverrides: MaterialOverrideComponentType[]
matrixAutoUpdate: boolean
useBasicMaterial: boolean
isUsingGPUInstancing: boolean
isDynamicObject: boolean
curScr?: string
Expand Down
14 changes: 13 additions & 1 deletion packages/engine/src/scene/functions/loaders/ModelFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Texture } from 'three'
import { Mesh, Texture } from 'three'

import { ComponentJson } from '@xrengine/common/src/interfaces/SceneInterface'

Expand All @@ -20,13 +20,15 @@ import cloneObject3D from '../cloneObject3D'
import { addError, removeError } from '../ErrorFunctions'
import { overrideTexture, parseGLTFModel } from '../loadGLTFModel'
import { initializeOverride } from './MaterialOverrideFunctions'
import { useSimpleMaterial, useStandardMaterial } from './SimpleMaterialFunctions'

export const SCENE_COMPONENT_MODEL = 'gltf-model'
export const SCENE_COMPONENT_MODEL_DEFAULT_VALUE = {
src: '',
textureOverride: '',
materialOverrides: [] as MaterialOverrideComponentType[],
matrixAutoUpdate: true,
useBasicMaterial: false,
isUsingGPUInstancing: false,
isDynamicObject: false
}
Expand Down Expand Up @@ -66,6 +68,15 @@ export const updateModel: ComponentUpdateFunction = (entity: Entity, properties:
if (typeof properties.textureOverride !== 'undefined') {
overrideTexture(entity)
}

if (properties.useBasicMaterial !== undefined) {
HexaField marked this conversation as resolved.
Show resolved Hide resolved
const obj3d = getComponent(entity, Object3DComponent).value
obj3d.traverseVisible((child: Mesh) => {
if (child.isMesh) {
properties.useBasicMaterial ? useSimpleMaterial(child as any) : useStandardMaterial(child as any)
}
})
}
}

export const serializeModel: ComponentSerializeFunction = (entity) => {
Expand Down Expand Up @@ -104,6 +115,7 @@ const parseModelProperties = (props): ModelComponentType => {
textureOverride: props.textureOverride ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.textureOverride,
materialOverrides: props.materialOverrides ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.materialOverrides,
matrixAutoUpdate: props.matrixAutoUpdate ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.matrixAutoUpdate,
useBasicMaterial: props.useBasicMaterial ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.useBasicMaterial,
isUsingGPUInstancing: props.isUsingGPUInstancing ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.isUsingGPUInstancing,
isDynamicObject: props.isDynamicObject ?? SCENE_COMPONENT_MODEL_DEFAULT_VALUE.isDynamicObject
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const deserializeTriggerVolume: ComponentDeserializeFunction = (
entity: Entity,
json: ComponentJson<TriggerVolumeComponentType>
): void => {
const transform = getComponent(entity, TransformComponent)

const boxMesh = new Mesh(new BoxBufferGeometry(), new MeshBasicMaterial())
boxMesh.material.visible = false
boxMesh.userData = {
Expand All @@ -33,7 +35,7 @@ export const deserializeTriggerVolume: ComponentDeserializeFunction = (
collisionLayer: CollisionGroups.Trigger,
collisionMask: CollisionGroups.Default
}

boxMesh.scale.set(transform.scale.x, transform.scale.y, transform.scale.z)
createCollider(entity, boxMesh)

addComponent(entity, TriggerVolumeComponent, {
Expand Down