Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo create/remove entity, add/remove component #789

Merged
merged 52 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7801121
add EntityAddComponentCommand and EntityRemoveComponentCommand
vincentfretin Aug 26, 2024
d9cf7f1
add EntityCreateCommand and modify createLayerFunctions to use it
vincentfretin Aug 26, 2024
6835588
use correct componentadd or entityupdate commands when changing stree…
vincentfretin Aug 26, 2024
6127e84
update createStreetmixStreet to use command
vincentfretin Aug 26, 2024
85eda94
remove unused entitycreate, replace it by updatescenegraph, remove un…
vincentfretin Aug 26, 2024
cfcffc0
modify createEntity and createEntityOnPosition to use EntityCreateCom…
vincentfretin Aug 26, 2024
a289282
emit entityremoved event when removing entity to update scene graph
vincentfretin Aug 26, 2024
cff2b7c
add EntityRemoveCommand
vincentfretin Aug 26, 2024
5dd1ae8
add new createUniqueId function
vincentfretin Aug 26, 2024
15e361d
don't show the random entity id in scene graph, use getEntityDisplayN…
vincentfretin Aug 26, 2024
50348c9
get again the entity from id for undo to properly work after undoing …
vincentfretin Aug 26, 2024
0384ac9
always set an id for created entity
vincentfretin Aug 26, 2024
f39339f
Remove unused m shortcut that was used in the removed motion capture …
vincentfretin Aug 27, 2024
c6786b1
rename EntityAddComponentCommand to ComponentAddCommand, and EntityRe…
vincentfretin Aug 27, 2024
20ae117
use a single payload param for ComponentAddCommand/ComponentRemoveCom…
vincentfretin Aug 27, 2024
5667cc7
free reference to removed entity
vincentfretin Aug 27, 2024
9a1ff8b
simplify command execution
vincentfretin Aug 27, 2024
24f2483
return in execute so we get the created entity for entitycreate command
vincentfretin Aug 27, 2024
4927b8b
recreate createEntity and use it in the entitycreate command
vincentfretin Aug 27, 2024
46724a0
simplify updateEntity function used in PropertyRow component and move…
vincentfretin Aug 27, 2024
4172a79
move emit entityupdate in updateEntity
vincentfretin Aug 27, 2024
e3bb79e
Remove redundant removeObject call, this is already called on child-d…
vincentfretin Aug 27, 2024
ce177fe
Remove unneeded iife in addHelper
vincentfretin Aug 27, 2024
6e654f9
Use const to be consistent in this file
vincentfretin Aug 27, 2024
9b445b5
Merge branch 'main' into undo-plus
kfarr Aug 27, 2024
fb646cf
Merge branch 'main' into undo-plus
vincentfretin Aug 28, 2024
5e35c74
use geoLayer variable instead of getting again the entity
vincentfretin Aug 28, 2024
1478142
use entityupdate or componentadd command when updating geo coordinates
vincentfretin Aug 28, 2024
0ca98b3
fix entityupdate on multi-prop component with property '' and value a…
vincentfretin Aug 28, 2024
8f41a6f
revert back to this.type instead of static type
vincentfretin Aug 28, 2024
e4c610b
always get back the entity from id, with undo remove the entity was t…
vincentfretin Aug 28, 2024
303463d
remove non working line
vincentfretin Aug 28, 2024
6990401
show default google 3d tiles in scene graph after setting location (f…
vincentfretin Aug 28, 2024
b036d0f
recreate with the same id when redo entiycreate command
vincentfretin Aug 28, 2024
b3da692
update jsdoc for updateEntity function
vincentfretin Aug 28, 2024
5ac90b7
remove exposed off/on/emit on inspector, remove entityclone, entitycr…
vincentfretin Aug 28, 2024
229bd8c
put back the entitycreated,entityclone,entityremoved events even if w…
vincentfretin Aug 29, 2024
94d64c2
add entityclone command
vincentfretin Aug 29, 2024
9612ac5
use getDOMAttribute instead of getAttribute to store the old value to…
vincentfretin Aug 29, 2024
629fb2d
make a copy of the object returned by getDOMAttribute otherwise the o…
vincentfretin Aug 29, 2024
6bf2daa
really remove exposed off/on/emit on inspector
vincentfretin Aug 30, 2024
1519c50
add config file to set defaultParent config
vincentfretin Aug 30, 2024
1f07920
move debugUndoRedo to config
vincentfretin Aug 30, 2024
3e512c4
simplify condition
vincentfretin Aug 30, 2024
39e7a28
avoid importing from .component.jsx files
vincentfretin Aug 28, 2024
999d566
simplify condition
vincentfretin Aug 30, 2024
10486aa
remove comment, we put back createEntity with doc in entity.js
vincentfretin Aug 30, 2024
0abebfc
add empty line
vincentfretin Aug 30, 2024
38b5175
add comment
vincentfretin Aug 30, 2024
798c226
remove dead code
vincentfretin Aug 30, 2024
e38cfd4
remove console.log
vincentfretin Aug 30, 2024
2a044d8
Merge branch 'main' into undo-plus
kfarr Aug 30, 2024
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
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"firebase-admin": "^12.1.1",
"firebase-functions": "^5.0.1",
"lodash-es": "^4.17.21",
"nanoid": "^5.0.7",
"posthog-js": "^1.138.3",
"prop-types": "^15.8.1",
"react": "^18.2.0",
Expand Down
17 changes: 13 additions & 4 deletions src/components/street-geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ AFRAME.registerComponent('street-geo', {
});
google3dElement.classList.add('autocreated');

if (AFRAME.INSPECTOR && AFRAME.INSPECTOR.opened) {
// emit play event to start loading tiles in Editor mode
if (AFRAME.INSPECTOR?.opened) {
google3dElement.addEventListener(
'loaded',
() => {
// emit play event to start loading tiles in Editor mode
google3dElement.play();
},
{ once: true }
Expand Down Expand Up @@ -212,12 +212,21 @@ AFRAME.registerComponent('street-geo', {
osm3dBuildingElement.classList.add('autocreated');
osm3dBuildingElement.setAttribute('data-ignore-raycaster', '');

if (AFRAME.INSPECTOR && AFRAME.INSPECTOR.opened) {
// emit play event to start loading tiles in Editor mode
if (AFRAME.INSPECTOR?.opened) {
osm3dElement.addEventListener(
'loaded',
() => {
// emit play event to start loading tiles in Editor mode
osm3dElement.play();
},
{ once: true }
);
}
if (AFRAME.INSPECTOR?.opened) {
osm3dBuildingElement.addEventListener(
'loaded',
() => {
// emit play event to start loading tiles in Editor mode
osm3dBuildingElement.play();
},
{ once: true }
Expand Down
9 changes: 6 additions & 3 deletions src/editor/components/components/AddComponent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import Events from '../../lib/Events';
import Select from 'react-select';
import { sendMetric } from '../../services/ga';

Expand All @@ -25,8 +24,12 @@ export default class AddComponent extends React.Component {
componentName = id ? `${componentName}__${id}` : componentName;
}

entity.setAttribute(componentName, '');
Events.emit('componentadd', { entity: entity, component: componentName });
AFRAME.INSPECTOR.execute('componentadd', {
entity,
component: componentName,
value: ''
});

sendMetric('Components', 'addComponent', componentName);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,23 @@ const createEntityOnPosition = (mixinId, position) => {
if (previewEntity) {
previewEntity.remove();
}
const newEntity = document.createElement('a-entity');
newEntity.setAttribute('mixin', mixinId);
newEntity.addEventListener(
'loaded',
() => {
Events.emit('entitycreated', newEntity);
AFRAME.INSPECTOR.selectEntity(newEntity);
},
{ once: true }
);
newEntity.setAttribute('position', position);
const streetContainer = document.querySelector('#street-container');
// apppend element as a child of street-container
if (streetContainer) {
streetContainer.appendChild(newEntity);
} else {
AFRAME.scenes[0].appendChild(newEntity);
}
AFRAME.INSPECTOR.execute('entitycreate', {
mixin: mixinId,
components: {
position: position
}
});
};

const createEntity = (mixinId) => {
const previewEntity = document.getElementById('previewEntity');
if (previewEntity) {
previewEntity.remove();
}
const newEntity = document.createElement('a-entity');
newEntity.setAttribute('mixin', mixinId);
newEntity.addEventListener(
'loaded',
() => {
Events.emit('entitycreated', newEntity);
AFRAME.INSPECTOR.selectEntity(newEntity);
},
{ once: true }
);
const newEntityObject = {
mixin: mixinId,
components: {}
};

const selectedElement = AFRAME.INSPECTOR.selectedEntity;
const [ancestorEl, inSegment] = selectedElement
Expand All @@ -176,43 +158,50 @@ const createEntity = (mixinId) => {
if (selectedElement && !ancestorEl.parentEl.isScene) {
// append element as a child of the entity with .custom-group class.
let customGroupEl = ancestorEl.querySelector('.custom-group');
let entityToMove;
let customGroupCreated = false;
if (!customGroupEl) {
customGroupEl = document.createElement('a-entity');
// .custom-group entity is a child of segment or .street-parent/.buildings-parent elements
ancestorEl.appendChild(customGroupEl);
customGroupEl.classList.add('custom-group');
entityToMove = customGroupEl;
} else {
entityToMove = newEntity;
customGroupCreated = true;
}
customGroupEl.appendChild(newEntity);
newEntityObject.parentEl = customGroupEl;

if (inSegment) {
// get elevation position Y from attribute of segment element
const segmentElevationPosY = getSegmentElevationPosY(ancestorEl);
// set position y by elevation level of segment
entityToMove.setAttribute('position', { y: segmentElevationPosY });
if (customGroupCreated) {
customGroupEl.setAttribute('position', { y: segmentElevationPosY });
newEntityObject.components.position = { x: 0, y: 0, z: 0 };
} else {
newEntityObject.components.position = {
x: 0,
y: segmentElevationPosY,
z: 0
};
}
} else {
// if we are creating element not inside segment-parent
selectedElement.object3D.getWorldPosition(entityToMove.object3D.position);
entityToMove.object3D.parent.worldToLocal(entityToMove.object3D.position);
const pos = new THREE.Vector3();
selectedElement.object3D.getWorldPosition(pos);
if (customGroupCreated) {
customGroupEl.object3D.parent.worldToLocal(pos);
} else {
customGroupEl.object3D.worldToLocal(pos);
}
newEntityObject.components.position = { x: pos.x, y: pos.y, z: pos.z };
}
} else {
const position = pickPointOnGroundPlane({
normalizedX: 0,
normalizedY: -0.1,
camera: AFRAME.INSPECTOR.camera
});
newEntity.setAttribute('position', position);
const streetContainer = document.querySelector('#street-container');
// apppend element as a child of street-container
if (streetContainer) {
streetContainer.appendChild(newEntity);
} else {
AFRAME.scenes[0].appendChild(newEntity);
}
newEntityObject.components.position = position;
}
AFRAME.INSPECTOR.execute('entitycreate', newEntityObject);
};

const cardMouseEnter = (mixinId) => {
Expand All @@ -222,15 +211,16 @@ const cardMouseEnter = (mixinId) => {
previewEntity.setAttribute('id', 'previewEntity');
AFRAME.scenes[0].appendChild(previewEntity);
const dropCursorEntity = document.createElement('a-entity');
dropCursorEntity.classList.add('hideFromSceneGraph');
dropCursorEntity.innerHTML = `
<a-ring id="drop-cursor" rotation="-90 0 0" radius-inner="0.2" radius-outer="0.3">
<a-ring color="yellow" radius-inner="0.4" radius-outer="0.5"
<a-ring class="hideFromSceneGraph" id="drop-cursor" rotation="-90 0 0" radius-inner="0.2" radius-outer="0.3">
<a-ring class="hideFromSceneGraph" color="yellow" radius-inner="0.4" radius-outer="0.5"
animation="property: scale; from: 1 1 1; to: 2 2 2; loop: true; dir: alternate"></a-ring>
<a-ring color="yellow" radius-inner="0.6" radius-outer="0.7"
<a-ring class="hideFromSceneGraph" color="yellow" radius-inner="0.6" radius-outer="0.7"
animation="property: scale; from: 1 1 1; to: 3 3 3; loop: true; dir: alternate"></a-ring>
<a-entity class="drop-cursor-arrow" rotation="90 0 0">
<a-cylinder color="yellow" position="0 5.25 0" radius="0.05" height="2.5"></a-cylinder>
<a-cone color="yellow" position="0 4 0" radius-top="0.5" radius-bottom="0" height="1"></a-cone>
<a-entity class="hideFromSceneGraph" rotation="90 0 0">
<a-cylinder class="hideFromSceneGraph" color="yellow" position="0 5.25 0" radius="0.05" height="2.5"></a-cylinder>
<a-cone class="hideFromSceneGraph" color="yellow" position="0 4 0" radius-top="0.5" radius-bottom="0" height="1"></a-cone>
</a-ring>`;
previewEntity.appendChild(dropCursorEntity);
}
Expand Down
Loading