private void SetHitInfo(ref HitInfo hitInfo, RaycastHit hit, IParcelScene scene) { hitInfo.point = WorldStateUtils.ConvertUnityToScenePosition(hit.point, scene); hitInfo.distance = hit.distance; hitInfo.normal = hit.normal; hitInfo.collider = hit.collider; }
public DCLBuilderInWorldEntity CreateEmptyEntity(ParcelScene parcelScene, Vector3 entryPoint, Vector3 editionGOPosition, bool notifyEntityList = true) { IDCLEntity newEntity = parcelScene.CreateEntity(Guid.NewGuid().ToString()); DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entryPoint, parcelScene); Vector3 pointToLookAt = Camera.main.transform.position; pointToLookAt.y = editionGOPosition.y; Quaternion lookOnLook = Quaternion.LookRotation(editionGOPosition - pointToLookAt); DCLTransform.model.rotation = lookOnLook; DCLTransform.model.scale = newEntity.gameObject.transform.lossyScale; parcelScene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model); DCLBuilderInWorldEntity convertedEntity = SetupEntityToEdit(newEntity, true); hudController?.UpdateSceneLimitInfo(); if (notifyEntityList) { EntityListChanged(); } return(convertedEntity); }
public void CreateFloor(CatalogItem floorSceneObject) { Vector3 initialPosition = new Vector3(ParcelSettings.PARCEL_SIZE / 2, 0, ParcelSettings.PARCEL_SIZE / 2); Vector2Int[] parcelsPoints = sceneToEdit.sceneData.parcels; numberOfParcelsLoaded = 0; loadedFloorEntities.Clear(); foreach (Vector2Int parcel in parcelsPoints) { BIWEntity decentralandEntity = creatorController.CreateCatalogItem( floorSceneObject, WorldStateUtils.ConvertPointInSceneToUnityPosition(initialPosition, parcel), false, true, OnFloorLoaded); // It may happen that when you get here, the floor entity is already loaded and it wouldn't be necessary to show its loading indicator. if (!loadedFloorEntities.Contains(decentralandEntity.rootEntity.entityId)) { GameObject floorPlaceHolder = GameObject.Instantiate(floorPrefab, decentralandEntity.rootEntity.gameObject.transform.position, Quaternion.identity); floorPlaceHolder.GetComponentInChildren <BIWFloorLoading>().Initialize(mainCamera); floorPlaceHolderDict.Add(decentralandEntity.rootEntity.entityId, floorPlaceHolder); decentralandEntity.OnShapeFinishLoading += RemovePlaceHolder; } } entityHandler.DeselectEntities(); lastFloorCalalogItemUsed = floorSceneObject; }
public static string ConvertEntityToJSON(DecentralandEntity entity) { EntityData builderInWorldEntityData = new EntityData(); builderInWorldEntityData.entityId = entity.entityId; foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> keyValuePair in entity.components) { if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM) { EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent(); entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, entity.scene); entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles; entityComponentModel.scale = entity.gameObject.transform.localScale; builderInWorldEntityData.transformComponent = entityComponentModel; } else { ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); entityComponentModel.componentId = (int)keyValuePair.Key; entityComponentModel.data = keyValuePair.Value.GetModel(); builderInWorldEntityData.components.Add(entityComponentModel); } } foreach (KeyValuePair <Type, BaseDisposable> keyValuePair in entity.GetSharedComponents()) { if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE) { EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent(); NFTShape.Model model = (NFTShape.Model)keyValuePair.Value.GetModel(); nFTComponent.id = keyValuePair.Value.id; nFTComponent.color = new ColorRepresentation(model.color); nFTComponent.assetId = model.assetId; nFTComponent.src = model.src; nFTComponent.style = model.style; builderInWorldEntityData.nftComponent = nFTComponent; } else { ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent(); entityComponentModel.componentId = keyValuePair.Value.GetClassId(); entityComponentModel.data = keyValuePair.Value.GetModel(); entityComponentModel.classId = keyValuePair.Value.id; builderInWorldEntityData.sharedComponents.Add(entityComponentModel); } } return(JsonConvert.SerializeObject(builderInWorldEntityData)); }
public void AddEntityOnKernel(IDCLEntity entity, ParcelScene scene) { List <ComponentPayload> list = new List <ComponentPayload>(); foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> keyValuePair in entity.components) { ComponentPayload componentPayLoad = new ComponentPayload(); componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key); if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM) { TransformComponent entityComponentModel = new TransformComponent(); entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, scene); entityComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation); entityComponentModel.scale = entity.gameObject.transform.localScale; componentPayLoad.data = entityComponentModel; } else { componentPayLoad.data = keyValuePair.Value.GetModel(); } list.Add(componentPayLoad); } foreach (KeyValuePair <Type, ISharedComponent> keyValuePairBaseDisposable in entity.sharedComponents) { ComponentPayload componentPayLoad = new ComponentPayload(); componentPayLoad.componentId = keyValuePairBaseDisposable.Value.GetClassId(); if (keyValuePairBaseDisposable.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE) { NFTComponent nftComponent = new NFTComponent(); NFTShape.Model model = (NFTShape.Model)keyValuePairBaseDisposable.Value.GetModel(); nftComponent.color = new ColorRepresentation(model.color); nftComponent.assetId = model.assetId; nftComponent.src = model.src; nftComponent.style = model.style; componentPayLoad.data = nftComponent; } else { componentPayLoad.data = keyValuePairBaseDisposable.Value.GetModel(); } list.Add(componentPayLoad); } SendNewEntityToKernel(scene.sceneData.id, entity.entityId, list.ToArray()); }
public void UpdateSelectionPosition(Vector3 newPosition) { if (selectedEntities.Count != 1) { return; } editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit); UpdateGizmosToSelectedEntities(); }
public DecentralandEntity DuplicateEntity(DecentralandEntity entity) { if (!entities.ContainsKey(entity.entityId)) { return(null); } DecentralandEntity newEntity = CreateEntity(System.Guid.NewGuid().ToString()); if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { DecentralandEntity childDuplicate = DuplicateEntity(iterator.Current.Value); childDuplicate.SetParent(newEntity); } } } if (entity.parent != null) { SetEntityParent(newEntity.entityId, entity.parent.entityId); } DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); DCLTransform.model.rotation = entity.gameObject.transform.rotation; DCLTransform.model.scale = entity.gameObject.transform.lossyScale; foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> component in entity.components) { EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, component.Key, DCLTransform.model); } foreach (KeyValuePair <System.Type, BaseDisposable> component in entity.GetSharedComponents()) { BaseDisposable baseDisposable = SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId()); string jsonModel = Newtonsoft.Json.JsonConvert.SerializeObject(component.Value.GetModel()); baseDisposable.UpdateFromJSON(jsonModel); SharedComponentAttach(newEntity.entityId, baseDisposable.id); } //NOTE: (Adrian) Evaluate if all created components should be handle as equals instead of different foreach (KeyValuePair <string, UUIDComponent> component in entity.uuidComponents) { EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.UUID_CALLBACK, component.Value.model); } return(newEntity); }
Vector3 CalculatePointToLookAt(ParcelScene parcelScene) { Vector3 position; float totalX = 0f; float totalY = 0f; float totalZ = 0f; int minX = int.MaxValue; int minY = int.MaxValue; int maxX = int.MinValue; int maxY = int.MinValue; foreach (Vector2Int vector in parcelScene.sceneData.parcels) { totalX += vector.x; totalZ += vector.y; if (vector.x < minX) { minX = vector.x; } if (vector.y < minY) { minY = vector.y; } if (vector.x > maxX) { maxX = vector.x; } if (vector.y > maxY) { maxY = vector.y; } } float centerX = totalX / parcelScene.sceneData.parcels.Length; float centerZ = totalZ / parcelScene.sceneData.parcels.Length; position.x = centerX; position.y = totalY; position.z = centerZ; position = WorldStateUtils.ConvertScenePositionToUnityPosition(parcelScene); position.x += ParcelSettings.PARCEL_SIZE / 2; position.z += ParcelSettings.PARCEL_SIZE / 2; return(position); }
public void UpdateInfo(BIWEntity entity) { if (entity != null && entity.rootEntity.gameObject != null) { Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.rootEntity.gameObject.transform.position, parcelScene); Vector3 currentRotation = entity.rootEntity.gameObject.transform.rotation.eulerAngles; Vector3 currentScale = entity.rootEntity.gameObject.transform.lossyScale; currentRotation = entity.GetEulerRotation(); entityInformationView.SetPositionAttribute(positionConverted); entityInformationView.SetRotationAttribute(currentRotation); entityInformationView.SetScaleAttribute(currentScale); } }
public void UpdateSelectionPosition(Vector3 newPosition) { if (selectedEntities.Count != 1) { return; } TransformActionStarted(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME); editionGO.transform.position = WorldStateUtils.ConvertSceneToUnityPosition(newPosition, sceneToEdit); UpdateGizmosToSelectedEntities(); TransformActionEnd(selectedEntities[0].rootEntity, BIWSettings.TRANSLATE_GIZMO_NAME); ActionFinish(BIWCompleteAction.ActionType.MOVE); entityHandler.ReportTransform(true); saveController.TryToSave(); }
public void FindSceneToEdit() { foreach (IParcelScene scene in Environment.i.world.state.scenesSortedByDistance) { if (WorldStateUtils.IsCharacterInsideScene(scene)) { ParcelScene parcelScene = (ParcelScene)scene; if (sceneToEdit != null && sceneToEdit != parcelScene) { actionController.Clear(); } sceneToEdit = parcelScene; break; } } }
public static IDCLEntity DuplicateEntity(ParcelScene scene, IDCLEntity entity) { if (!scene.entities.ContainsKey(entity.entityId)) { return(null); } IDCLEntity newEntity = scene.CreateEntity(System.Guid.NewGuid().ToString()); if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value); childDuplicate.SetParent(newEntity); } } } if (entity.parent != null) { scene.SetEntityParent(newEntity.entityId, entity.parent.entityId); } DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); DCLTransform.model.rotation = entity.gameObject.transform.rotation; DCLTransform.model.scale = entity.gameObject.transform.lossyScale; foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> component in entity.components) { scene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, component.Key, component.Value.GetModel()); } foreach (KeyValuePair <System.Type, ISharedComponent> component in entity.sharedComponents) { ISharedComponent sharedComponent = scene.SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId()); sharedComponent.UpdateFromModel(component.Value.GetModel()); scene.SharedComponentAttach(newEntity.entityId, sharedComponent.id); } return(newEntity); }
public void UpdateInfo(DCLBuilderInWorldEntity entity) { if (entity != null && entity.gameObject != null) { Vector3 positionConverted = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, parcelScene); Vector3 currentRotation = entity.gameObject.transform.rotation.eulerAngles; Vector3 currentScale = entity.gameObject.transform.localScale; var newEuler = currentRotation; newEuler.x = RepeatWorking(newEuler.x - currentRotation.x + 180.0F, 360.0F) + currentRotation.x - 180.0F; newEuler.y = RepeatWorking(newEuler.y - currentRotation.y + 180.0F, 360.0F) + currentRotation.y - 180.0F; newEuler.z = RepeatWorking(newEuler.z - currentRotation.z + 180.0F, 360.0F) + currentRotation.z - 180.0F; currentRotation = newEuler; entityInformationView.SetPositionAttribute(positionConverted); entityInformationView.SetRotationAttribute(currentRotation); entityInformationView.SetScaleAttribute(currentScale); } }
public void CreateFloor(CatalogItem floorSceneObject) { Vector3 initialPosition = new Vector3(ParcelSettings.PARCEL_SIZE / 2, 0, ParcelSettings.PARCEL_SIZE / 2); Vector2Int[] parcelsPoints = sceneToEdit.sceneData.parcels; foreach (Vector2Int parcel in parcelsPoints) { DCLBuilderInWorldEntity decentralandEntity = biwCreatorController.CreateSceneObject(floorSceneObject, false, true); decentralandEntity.rootEntity.OnShapeUpdated += OnFloorLoaded; decentralandEntity.transform.position = WorldStateUtils.ConvertPointInSceneToUnityPosition(initialPosition, parcel); dclBuilderMeshLoadIndicatorController.ShowIndicator(decentralandEntity.rootEntity.gameObject.transform.position, decentralandEntity.rootEntity.entityId); GameObject floorPlaceHolder = GameObject.Instantiate(floorPrefab, decentralandEntity.rootEntity.gameObject.transform.position, Quaternion.identity); floorPlaceHolderDict.Add(decentralandEntity.rootEntity.entityId, floorPlaceHolder); builderInWorldBridge?.EntityTransformReport(decentralandEntity.rootEntity, sceneToEdit); } builderInWorldEntityHandler.DeselectEntities(); lastFloorCalalogItemUsed = floorSceneObject; }
private void SetRaycastInfoData(ref RaycastHitInfo hitInfo, IParcelScene scene) { if (hitInfo.hit.collider == null) { return; } if (!CollidersManager.i.GetColliderInfo(hitInfo.hit.collider, out ColliderInfo info)) { return; } if (scene != null) { hitInfo.isValid = (info.scene == scene) || (scene is GlobalScene globalScene && globalScene.isPortableExperience); } else if (scene == null && WorldStateUtils.IsCharacterInsideScene(info.scene)) { hitInfo.isValid = true; } }
public void EntityTransformReport(IDCLEntity entity, ParcelScene scene) { entitySingleComponentPayload.entityId = entity.entityId; entitySingleComponentPayload.componentId = (int)CLASS_ID_COMPONENT.TRANSFORM; entityTransformComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, scene); entityTransformComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation); entityTransformComponentModel.scale = entity.gameObject.transform.localScale; entitySingleComponentPayload.data = entityTransformComponentModel; modifyEntityComponentEvent.payload = entitySingleComponentPayload; WebInterface.SceneEvent <ModifyEntityComponentEvent> sceneEvent = new WebInterface.SceneEvent <ModifyEntityComponentEvent>(); sceneEvent.sceneId = scene.sceneData.id; sceneEvent.eventType = BuilderInWorldSettings.STATE_EVENT_NAME; sceneEvent.payload = modifyEntityComponentEvent; //Note (Adrian): We use Newtonsoft instead of JsonUtility because we need to deal with super classes, JsonUtility doesn't encode them string message = JsonConvert.SerializeObject(sceneEvent); WebInterface.BuilderInWorldMessage(BuilderInWorldSettings.SCENE_EVENT_NAME, message); }