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

Commit

Permalink
Int (#10884)
Browse files Browse the repository at this point in the history
* Revert "Physics reactivity for collider component updates and order dependenc…" (#10876)

This reverts commit 33afb3b.

* fix collider reactivity (#10877)

* fix collider reactivity

* fix tests

* optimize

* fix duplicate new scene (#10880)

* rigidbody initialization quick fix (#10883)

* Upload drag drop files MT fix (#10881)

* Upload drag drop files MT fix

* Array length check

* LerpTransform from rigid body uses rigid body instead of scene entity (#10882)

---------

Co-authored-by: Michael Estes <[email protected]>
Co-authored-by: Daniel Belmes <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2024
1 parent ff78b0d commit dbec670
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 42 deletions.
2 changes: 0 additions & 2 deletions packages/editor/src/components/toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ const onClickNewScene = async () => {
if (!confirm) return
}

onNewScene()

const newSceneUIAddons = getState(EditorState).uiAddons.newScene
if (Object.keys(newSceneUIAddons).length > 0) {
PopoverState.showPopupover(<CreateSceneDialog />)
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/functions/assetFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { modelResourcesPath } from '@etherealengine/engine/src/assets/functions/

import { pathJoin } from '@etherealengine/common/src/utils/miscUtils'

const handleUploadFiles = (projectName: string, directoryPath: string, files: FileList) => {
export const handleUploadFiles = (projectName: string, directoryPath: string, files: FileList | File[]) => {
return Promise.all(
Array.from(files).map((file) => {
const fileDirectory = file.webkitRelativePath || file.name
Expand Down
4 changes: 2 additions & 2 deletions packages/spatial/src/physics/components/ColliderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const ColliderComponent = defineComponent({
const hasCollider = useState(false)

useLayoutEffect(() => {
if (!rigidbodyComponent || !physicsWorld) return
if (!rigidbodyComponent?.initialized?.value || !physicsWorld) return

const colliderDesc = Physics.createColliderDesc(physicsWorld, entity, rigidbodyEntity)

Expand All @@ -102,7 +102,7 @@ export const ColliderComponent = defineComponent({
Physics.removeCollider(physicsWorld, entity)
hasCollider.set(false)
}
}, [physicsWorld, component.shape, rigidbodyEntity, !!rigidbodyComponent, transform.scale])
}, [physicsWorld, component.shape, !!rigidbodyComponent?.initialized?.value, transform.scale])

useLayoutEffect(() => {
if (!physicsWorld) return
Expand Down
4 changes: 4 additions & 0 deletions packages/spatial/src/physics/components/RigidBodyComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const RigidBodyComponent = defineComponent({
canSleep: true,
gravityScale: 1,
// internal
/** @deprecated @todo make the physics api properly reactive to remove this property */
initialized: false,
previousPosition: proxifyVector3(this.previousPosition, entity),
previousRotation: proxifyQuaternion(this.previousRotation, entity),
position: proxifyVector3(this.position, entity),
Expand Down Expand Up @@ -118,8 +120,10 @@ export const RigidBodyComponent = defineComponent({
useEffect(() => {
if (!physicsWorld) return
Physics.createRigidBody(physicsWorld, entity)
component.initialized.set(true)
return () => {
Physics.removeRigidbody(physicsWorld, entity)
component.initialized.set(false)
}
}, [physicsWorld])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { ECSState } from '@etherealengine/ecs/src/ECSState'
import { getState } from '@etherealengine/hyperflux'

import { Vector3_One, Vector3_Zero } from '../../common/constants/MathConstants'
import { SceneComponent } from '../../renderer/components/SceneComponents'
import { EntityTreeComponent, getAncestorWithComponent, iterateEntityNode } from '../../transform/components/EntityTree'
import { TransformComponent } from '../../transform/components/TransformComponent'
import { computeTransformMatrix, isDirty, TransformDirtyUpdateSystem } from '../../transform/systems/TransformSystem'
Expand Down Expand Up @@ -79,13 +78,13 @@ export const lerpTransformFromRigidbody = (entity: Entity, alpha: number) => {

const transform = getComponent(entity, TransformComponent)

const sceneEntity = getAncestorWithComponent(entity, SceneComponent)
const sceneTransform = getComponent(sceneEntity, TransformComponent)
parentMatrixInverse.copy(sceneTransform.matrixWorld).invert()
const rigidBodyEntity = getAncestorWithComponent(entity, RigidBodyComponent)
const rigidBodyTransform = getComponent(rigidBodyEntity, TransformComponent)
parentMatrixInverse.copy(rigidBodyTransform.matrixWorld).invert()
localMatrix.compose(position, rotation, Vector3_One).premultiply(parentMatrixInverse)
localMatrix.decompose(position, rotation, scale)
transform.matrix.compose(position, rotation, transform.scale)
transform.matrixWorld.multiplyMatrices(sceneTransform.matrixWorld, transform.matrix)
transform.matrixWorld.multiplyMatrices(rigidBodyTransform.matrixWorld, transform.matrix)

/** set all children dirty deeply, but set this entity to clean */
iterateEntityNode(entity, setDirty)
Expand Down
48 changes: 16 additions & 32 deletions packages/ui/src/components/editor/panels/Files/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,17 @@ Ethereal Engine. All Rights Reserved.
import { FileThumbnailJobState } from '@etherealengine/client-core/src/common/services/FileThumbnailJobState'
import { NotificationService } from '@etherealengine/client-core/src/common/services/NotificationService'
import { PopoverState } from '@etherealengine/client-core/src/common/services/PopoverState'
import { uploadToFeathersService } from '@etherealengine/client-core/src/util/upload'
import config from '@etherealengine/common/src/config'
import {
FileBrowserContentType,
StaticResourceType,
UserID,
archiverPath,
fileBrowserPath,
fileBrowserUploadPath,
projectPath,
staticResourcePath
} from '@etherealengine/common/src/schema.type.module'
import { CommonKnownContentTypes } from '@etherealengine/common/src/utils/CommonKnownContentTypes'
import { processFileName } from '@etherealengine/common/src/utils/processFileName'
import { Engine } from '@etherealengine/ecs'
import { AssetSelectionChangePropsType } from '@etherealengine/editor/src/components/assets/AssetsPreviewPanel'
import {
Expand All @@ -51,7 +48,11 @@ import ImageCompressionPanel from '@etherealengine/editor/src/components/assets/
import ModelCompressionPanel from '@etherealengine/editor/src/components/assets/ModelCompressionPanel'
import { DndWrapper } from '@etherealengine/editor/src/components/dnd/DndWrapper'
import { SupportedFileTypes } from '@etherealengine/editor/src/constants/AssetTypes'
import { downloadBlobAsZip, inputFileWithAddToScene } from '@etherealengine/editor/src/functions/assetFunctions'
import {
downloadBlobAsZip,
handleUploadFiles,
inputFileWithAddToScene
} from '@etherealengine/editor/src/functions/assetFunctions'
import { bytesToSize, unique } from '@etherealengine/editor/src/functions/utils'
import { EditorState } from '@etherealengine/editor/src/services/EditorServices'
import { ClickPlacementState } from '@etherealengine/editor/src/systems/ClickPlacementSystem'
Expand Down Expand Up @@ -346,10 +347,8 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
await moveContent(data.fullName, newName, data.path, destinationPath, false)
}
} else {
const destinationPathCleaned = removeLeadingTrailingSlash(destinationPath)
const folder = destinationPathCleaned //destinationPathCleaned.substring(0, destinationPathCleaned.lastIndexOf('/') + 1)
const projectName = folder.split('/')[1]
const relativePath = folder.replace('projects/' + projectName + '/', '')
const path = selectedDirectory.get(NO_PROXY).slice(1)
const toUpload = [] as File[]

await Promise.all(
data.files.map(async (file) => {
Expand All @@ -358,38 +357,23 @@ const FileBrowserContentPanel: React.FC<FileBrowserContentPanelProps> = (props)
// creating directory
await fileService.create(`${destinationPath}${file.name}`)
} else {
try {
const name = processFileName(file.name)
await uploadToFeathersService(fileBrowserUploadPath, [file], {
args: [
{
project: projectName,
path: relativePath + '/' + name,
contentType: file.type
}
]
}).promise
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
toUpload.push(file)
}
})
)

if (toUpload.length) {
try {
await handleUploadFiles(projectName, path, toUpload)
} catch (err) {
NotificationService.dispatchNotify(err.message, { variant: 'error' })
}
}
}

await refreshDirectory()
}

function removeLeadingTrailingSlash(str) {
if (str.startsWith('/')) {
str = str.substring(1)
}
if (str.endsWith('/')) {
str = str.substring(0, str.length - 1)
}
return str
}

const onBackDirectory = () => {
const pattern = /([^/]+)/g
const result = selectedDirectory.value.match(pattern)
Expand Down

0 comments on commit dbec670

Please sign in to comment.