public static Quaternion GenerateRandomRotationQuaternion(ObjectRotationRandomizationSettings randomizationSettings)
        {
            Quaternion randomRotationQuaternion = Quaternion.identity;

            if (randomizationSettings.RandomizeRotation)
            {
                if (randomizationSettings.XAxisRandomizationSettings.Randomize)
                {
                    randomRotationQuaternion = GenerateRandomRotationQuaternionForAxis(Vector3.right, randomizationSettings.XAxisRandomizationSettings.RandomizationModeSettings) * randomRotationQuaternion;
                }
                if (randomizationSettings.YAxisRandomizationSettings.Randomize)
                {
                    randomRotationQuaternion = GenerateRandomRotationQuaternionForAxis(Vector3.up, randomizationSettings.YAxisRandomizationSettings.RandomizationModeSettings) * randomRotationQuaternion;
                }
                if (randomizationSettings.ZAxisRandomizationSettings.Randomize)
                {
                    randomRotationQuaternion = GenerateRandomRotationQuaternionForAxis(Vector3.forward, randomizationSettings.ZAxisRandomizationSettings.RandomizationModeSettings) * randomRotationQuaternion;
                }
                if (randomizationSettings.CustomAxisRandomizationSettings.Randomize)
                {
                    randomRotationQuaternion = GenerateRandomRotationQuaternionForAxis(randomizationSettings.CustomAxisRandomizationSettings.Axis, randomizationSettings.CustomAxisRandomizationSettings.RandomizationModeSettings) * randomRotationQuaternion;
                }
            }

            return(randomRotationQuaternion);
        }
        public ObjectRotationRandomizationSettingsView(ObjectRotationRandomizationSettings settings)
        {
            _settings = settings;

            ToggleVisibilityBeforeRender = true;
            VisibilityToggleLabel        = "Rotation Randomization Settings";
            IndentContent = true;
        }
 public static void Randomize(GameObject gameObject, ObjectRotationRandomizationSettings randomizationSettings)
 {
     if (randomizationSettings.RandomizeRotation)
     {
         Transform objectTransform = gameObject.transform;
         if (randomizationSettings.XAxisRandomizationSettings.Randomize)
         {
             RandomizeRotationForAxis(objectTransform, randomizationSettings.XAxisRandomizationSettings.Axis, randomizationSettings.XAxisRandomizationSettings.RandomizationModeSettings);
         }
         if (randomizationSettings.YAxisRandomizationSettings.Randomize)
         {
             RandomizeRotationForAxis(objectTransform, randomizationSettings.YAxisRandomizationSettings.Axis, randomizationSettings.YAxisRandomizationSettings.RandomizationModeSettings);
         }
         if (randomizationSettings.ZAxisRandomizationSettings.Randomize)
         {
             RandomizeRotationForAxis(objectTransform, randomizationSettings.ZAxisRandomizationSettings.Axis, randomizationSettings.ZAxisRandomizationSettings.RandomizationModeSettings);
         }
         if (randomizationSettings.CustomAxisRandomizationSettings.Randomize)
         {
             RandomizeRotationForAxis(objectTransform, randomizationSettings.CustomAxisRandomizationSettings.Axis, randomizationSettings.CustomAxisRandomizationSettings.RandomizationModeSettings);
         }
     }
 }
예제 #4
0
        public List <ObjectPlacementData> Calculate()
        {
            if (_block == null || _block.NumberOfSegments == 0 || !ObjectPlacementGuide.ExistsInScene)
            {
                return(new List <ObjectPlacementData>());
            }

            Prefab     placementGuidePrefab        = ObjectPlacementGuide.Instance.SourcePrefab;
            Vector3    placementGuideWorldScale    = ObjectPlacementGuide.Instance.WorldScale;
            Quaternion placementGuideWorldRotation = ObjectPlacementGuide.Instance.WorldRotation;
            float      objectMissChance            = _block.Settings.ManualConstructionSettings.ObjectMissChance;
            ObjectRotationRandomizationSettings blockObjectRotationRandomizationSettings = _block.Settings.ManualConstructionSettings.ObjectRotationRandomizationSettings;
            bool           randomizeRotations = blockObjectRotationRandomizationSettings.RandomizeRotation;
            Vector3        objectOffsetAlongExtensionPlaneNormal = _block.Settings.ManualConstructionSettings.OffsetAlongGrowDirection * _block.ExtensionPlane.normal;
            bool           allowObjectIntersection = ObjectPlacementSettings.Get().ObjectIntersectionSettings.AllowIntersectionForBlockPlacement;
            bool           randomizePrefabs        = _block.Settings.ManualConstructionSettings.RandomizePrefabs;
            PrefabCategory activePrefabCategory    = PrefabCategoryDatabase.Get().ActivePrefabCategory;
            ObjectPlacementBlockProjectionSettings projectionSettings = _block.Settings.BlockProjectionSettings;
            bool canProject = projectionSettings.ProjectOnSurface &&
                              (projectionSettings.CanProjectOnMesh || projectionSettings.CanProjectOnTerrain);

            var objectPlacementDataInstances = new List <ObjectPlacementData>(_block.NumberOfSegments * 10);

            for (int segmentIndex = 0; segmentIndex < _block.NumberOfSegments; ++segmentIndex)
            {
                ObjectPlacementBoxStackSegment segment = _block.GetSegmentByIndex(segmentIndex);
                for (int stackIndex = 0; stackIndex < segment.NumberOfStacks; ++stackIndex)
                {
                    ObjectPlacementBoxStack stack = segment.GetStackByIndex(stackIndex);
                    if (stack.IsOverlappedByAnotherStack || stack.NumberOfBoxes == 0)
                    {
                        continue;
                    }

                    Vector3          projectionOffset     = Vector3.zero;
                    Vector3          projectionDirection  = Vector3.zero;
                    Quaternion       prjAlignRotation     = Quaternion.identity;
                    GameObjectRayHit projectionSurfaceHit = null;

                    if (canProject)
                    {
                        Vector3 rayOrigin = stack.GetBoxByIndex(0).Center;
                        Vector3 rayDir    = Vector3.zero;

                        if (projectionSettings.ProjectionDirection == ObjectBlockProjectionDir.BlockUp)
                        {
                            rayDir = _block.ExtensionPlane.normal;
                        }
                        else
                        {
                            rayDir = -_block.ExtensionPlane.normal;
                        }

                        projectionDirection = rayDir;

                        Ray ray = new Ray(rayOrigin, rayDir);
                        GameObjectRayHit closestMeshHit    = null;
                        GameObjectRayHit closestTerrainHit = null;

                        if (projectionSettings.CanProjectOnMesh)
                        {
                            closestMeshHit = Octave3DScene.Get().RaycastAllMeshClosest(ray);
                        }
                        if (projectionSettings.CanProjectOnTerrain)
                        {
                            closestTerrainHit = Octave3DScene.Get().RaycastAllTerainsClosest(ray);
                        }

                        // Ignore stack if no surface was found and non-projectables must be rejected
                        if (closestMeshHit == null && closestTerrainHit == null)
                        {
                            if (projectionSettings.RejectNonProjectables)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            projectionSurfaceHit = closestMeshHit;
                            if (closestMeshHit == null || (closestTerrainHit != null && closestMeshHit.HitEnter > closestTerrainHit.HitEnter))
                            {
                                projectionSurfaceHit = closestTerrainHit;
                            }
                        }

                        if (projectionSurfaceHit != null)
                        {
                            ObjectPlacementBox projectionBox = stack.GetBoxByIndex(0);
                            projectionOffset = projectionSurfaceHit.HitPoint - stack.GetBoxByIndex(0).Center;

                            if (projectionOffset.sqrMagnitude > (projectionSurfaceHit.HitPoint - stack.GetBoxByIndex(stack.NumberOfBoxes - 1).Center).sqrMagnitude)
                            {
                                projectionBox    = stack.GetBoxByIndex(stack.NumberOfBoxes - 1);
                                projectionOffset = projectionSurfaceHit.HitPoint - projectionBox.Center;
                            }

                            if (!projectionSettings.AlignToSurfaceNormal)
                            {
                                var     oobb      = projectionBox.OrientedBox;
                                Vector3 oldCenter = oobb.Center;
                                GameObjectExtensions.EmbedObjectBoxInSurface(oobb, projectionDirection, projectionSurfaceHit.HitObject);
                                projectionOffset = oobb.Center - oldCenter;
                            }
                        }
                    }

                    for (int stackBoxIndex = 0; stackBoxIndex < stack.NumberOfBoxes; ++stackBoxIndex)
                    {
                        ObjectPlacementBox box = stack.GetBoxByIndex(stackBoxIndex);
                        if (box.IsHidden)
                        {
                            continue;
                        }

                        if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementBlockManualConstructionSettings.MinObjectMissChance,
                                                             ObjectPlacementBlockManualConstructionSettings.MaxObjectMissChance))
                        {
                            continue;
                        }

                        if (!allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(box.OrientedBox, true))
                        {
                            continue;
                        }

                        Quaternion worldRotation = placementGuideWorldRotation;
                        if (randomizeRotations)
                        {
                            worldRotation = ObjectRotationRandomization.GenerateRandomRotationQuaternion(blockObjectRotationRandomizationSettings);
                        }

                        Vector3 worldScale = placementGuideWorldScale;
                        Prefab  prefab     = placementGuidePrefab;
                        if (randomizePrefabs && activePrefabCategory.NumberOfPrefabs != 0)
                        {
                            int    randomPrefabIndex = UnityEngine.Random.Range(0, activePrefabCategory.NumberOfPrefabs);
                            Prefab randomPrefab      = activePrefabCategory.GetPrefabByIndex(randomPrefabIndex);
                            if (randomPrefab != null && randomPrefab.UnityPrefab != null)
                            {
                                prefab     = activePrefabCategory.GetPrefabByIndex(randomPrefabIndex);
                                worldScale = prefab.UnityPrefab.transform.lossyScale;
                            }
                        }

                        Vector3 boxCenter = box.Center + objectOffsetAlongExtensionPlaneNormal + projectionOffset;
                        if (projectionSurfaceHit != null)
                        {
                            if (projectionSettings.AlignToSurfaceNormal)
                            {
                                worldRotation = AxisAlignment.CalculateRotationQuaternionForAxisAlignment(worldRotation, projectionSettings.AlignmentAxis, projectionSurfaceHit.HitNormal);
                                OrientedBox prefabWorldOOBB = prefab.UnityPrefab.GetHierarchyWorldOrientedBox();
                                Vector3     oobbSize        = prefabWorldOOBB.ScaledSize;
                                int         axisIndex       = (int)((int)(projectionSettings.AlignmentAxis) * 0.5f);
                                boxCenter = projectionSurfaceHit.HitPoint + projectionSurfaceHit.HitNormal * oobbSize[axisIndex] * 0.5f + (oobbSize[axisIndex] * stackBoxIndex * projectionSurfaceHit.HitNormal);
                            }
                        }

                        var objectPlacementData = new ObjectPlacementData();
                        objectPlacementData.WorldPosition = ObjectPositionCalculator.CalculateObjectHierarchyPosition(prefab, boxCenter, worldScale, worldRotation);
                        objectPlacementData.WorldScale    = worldScale;
                        objectPlacementData.WorldRotation = worldRotation;
                        objectPlacementData.Prefab        = prefab;
                        objectPlacementDataInstances.Add(objectPlacementData);
                    }
                }
            }

            return(objectPlacementDataInstances);
        }
예제 #5
0
        public override void Initialize()
        {
            base.Initialize();
            if (Octave3DWorldBuilder.ActiveInstance == null)
            {
                return;
            }

            ObjectPlacementSettings.Get().ObjectIntersectionSettings.View.IsVisible = false;

            _objectPlacementLookAndFeelSettingsView.IsVisible = false;
            _objectPlacementLookAndFeelSettingsView.BlockObjectPlacementLookAndFeelSettingsView.ToggleVisibilityBeforeRender = true;
            _objectPlacementLookAndFeelSettingsView.BlockObjectPlacementLookAndFeelSettingsView.VisibilityToggleLabel        = "Block";
            _objectPlacementLookAndFeelSettingsView.BlockObjectPlacementLookAndFeelSettingsView.IndentContent = true;
            _objectPlacementLookAndFeelSettingsView.BlockObjectPlacementLookAndFeelSettingsView.IsVisible     = false;

            _objectPlacementLookAndFeelSettingsView.PathObjectPlacementLookAndFeelSettingsView.ToggleVisibilityBeforeRender = true;
            _objectPlacementLookAndFeelSettingsView.PathObjectPlacementLookAndFeelSettingsView.VisibilityToggleLabel        = "Path";
            _objectPlacementLookAndFeelSettingsView.PathObjectPlacementLookAndFeelSettingsView.IndentContent = true;
            _objectPlacementLookAndFeelSettingsView.PathObjectPlacementLookAndFeelSettingsView.IsVisible     = false;

            _objectPlacementLookAndFeelSettingsView.DecorPaintLookAndFeelSettingsView.ToggleVisibilityBeforeRender = true;
            _objectPlacementLookAndFeelSettingsView.DecorPaintLookAndFeelSettingsView.VisibilityToggleLabel        = "Decor Paint";
            _objectPlacementLookAndFeelSettingsView.DecorPaintLookAndFeelSettingsView.IndentContent = true;
            _objectPlacementLookAndFeelSettingsView.DecorPaintLookAndFeelSettingsView.IsVisible     = false;

            ObjectGroupDatabaseView objectGroupDatabaseView = Octave3DWorldBuilder.ActiveInstance.PlacementObjectGroupDatabase.View;

            objectGroupDatabaseView.ToggleVisibilityBeforeRender = true;
            objectGroupDatabaseView.VisibilityToggleLabel        = "Object Groups";
            objectGroupDatabaseView.IsVisible       = false;
            objectGroupDatabaseView.SurroundWithBox = true;

            ObjectPlacementGuideSettings objectPlacementGuideSettings = ObjectPlacementSettings.Get().ObjectPlacementGuideSettings;

            objectPlacementGuideSettings.KeyboardRotationSettings.XAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.KeyboardRotationSettings.XAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.KeyboardRotationSettings.YAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.KeyboardRotationSettings.YAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.KeyboardRotationSettings.ZAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.KeyboardRotationSettings.ZAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.KeyboardRotationSettings.CustomAxisRotationSettings.View.VisibilityToggleLabel = "Placement Surface Normal Settings";

            objectPlacementGuideSettings.KeyboardRotationSettings.XAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.KeyboardRotationSettings.YAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.KeyboardRotationSettings.ZAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.KeyboardRotationSettings.CustomAxisRotationSettings.View.IsVisible = false;

            objectPlacementGuideSettings.MouseRotationSettings.XAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.MouseRotationSettings.XAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.MouseRotationSettings.YAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.MouseRotationSettings.YAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.MouseRotationSettings.ZAxisRotationSettings.View.VisibilityToggleLabel      = objectPlacementGuideSettings.MouseRotationSettings.ZAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            objectPlacementGuideSettings.MouseRotationSettings.CustomAxisRotationSettings.View.VisibilityToggleLabel = "Placement Surface Normal Settings";

            objectPlacementGuideSettings.MouseRotationSettings.XAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.MouseRotationSettings.YAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.MouseRotationSettings.ZAxisRotationSettings.View.IsVisible      = false;
            objectPlacementGuideSettings.MouseRotationSettings.CustomAxisRotationSettings.View.IsVisible = false;

            ObjectPlacement.Get().MirrorView.IsVisible = false;
            InteractableMirrorSettings mirrorSettings = ObjectPlacement.Get().MirrorSettings;

            mirrorSettings.View.IsVisible = false;
            mirrorSettings.View.ToggleVisibilityBeforeRender = true;
            mirrorSettings.View.VisibilityToggleLabel        = "More settings";
            mirrorSettings.View.VisibilityToggleIndent       = 1;
            mirrorSettings.View.IndentContent = true;
            mirrorSettings.KeyboardRotationSettings.XAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.KeyboardRotationSettings.XAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.KeyboardRotationSettings.YAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.KeyboardRotationSettings.YAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.KeyboardRotationSettings.ZAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.KeyboardRotationSettings.ZAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.KeyboardRotationSettings.CustomAxisRotationSettings.View.VisibilityToggleLabel = "Hover Surface Normal Settings";

            mirrorSettings.KeyboardRotationSettings.XAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.KeyboardRotationSettings.YAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.KeyboardRotationSettings.ZAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.KeyboardRotationSettings.CustomAxisRotationSettings.View.IsVisible = false;

            mirrorSettings.MouseRotationSettings.XAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.MouseRotationSettings.XAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.MouseRotationSettings.YAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.MouseRotationSettings.YAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.MouseRotationSettings.ZAxisRotationSettings.View.VisibilityToggleLabel      = mirrorSettings.MouseRotationSettings.ZAxisRotationSettings.RotationAxis.ToString() + " Axis Settings";
            mirrorSettings.MouseRotationSettings.CustomAxisRotationSettings.View.VisibilityToggleLabel = "Hover Surface Normal Settings";

            mirrorSettings.MouseRotationSettings.XAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.MouseRotationSettings.YAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.MouseRotationSettings.ZAxisRotationSettings.View.IsVisible      = false;
            mirrorSettings.MouseRotationSettings.CustomAxisRotationSettings.View.IsVisible = false;

            InteractableMirrorRenderSettingsView mirrorRenderSettingsView = ObjectPlacement.Get().MirrorRenderSettings.View;

            mirrorRenderSettingsView.VisibilityToggleLabel        = "Look and feel";
            mirrorRenderSettingsView.ToggleVisibilityBeforeRender = true;
            mirrorRenderSettingsView.IndentContent          = true;
            mirrorRenderSettingsView.VisibilityToggleIndent = 1;
            mirrorRenderSettingsView.IsVisible = false;

            ObjectRotationRandomizationSettings     placementGuideRotationRandomizationSettings     = PointAndClickObjectPlacementSettings.Get().PlacementGuideRotationRandomizationSettings;
            ObjectRotationRandomizationSettingsView placementGuideRotationRandomizationSettingsView = placementGuideRotationRandomizationSettings.View;

            placementGuideRotationRandomizationSettingsView.VisibilityToggleIndent = 1;
            placementGuideRotationRandomizationSettingsView.VisibilityToggleLabel  = "Rotation Randomization Settings";
            placementGuideRotationRandomizationSettingsView.IsVisible = false;
            placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.CustomAxisRandomizationSettings.View.VisibilityToggleLabel = "Placement Surface Normal Settings";

            placementGuideRotationRandomizationSettings     = DecorPaintObjectPlacementSettings.Get().SingleDecorPaintModeSettings.PlacementGuideRotationRandomizationSettings;
            placementGuideRotationRandomizationSettingsView = placementGuideRotationRandomizationSettings.View;
            placementGuideRotationRandomizationSettingsView.VisibilityToggleIndent = 1;
            placementGuideRotationRandomizationSettingsView.VisibilityToggleLabel  = "Rotation Randomization Settings";
            placementGuideRotationRandomizationSettingsView.IsVisible = false;
            placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.XAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.YAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.View.VisibilityToggleLabel      = placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.Axis + " Axis Settings";
            placementGuideRotationRandomizationSettings.ZAxisRandomizationSettings.View.IsVisible                  = false;
            placementGuideRotationRandomizationSettings.CustomAxisRandomizationSettings.View.VisibilityToggleLabel = "Placement Surface Normal Settings";

            ObjectScaleRandomizationSettings     placementGuideScaleRandomizationSettings = PointAndClickObjectPlacementSettings.Get().PlacementGuideScaleRandomizationSettings;
            ObjectScaleRandomizationSettingsView guideScaleRandomizationSettingsView      = placementGuideScaleRandomizationSettings.View;

            guideScaleRandomizationSettingsView.VisibilityToggleIndent = 1;
            guideScaleRandomizationSettingsView.VisibilityToggleLabel  = "Scale Randomization Settings";
            guideScaleRandomizationSettingsView.IsVisible     = false;
            guideScaleRandomizationSettingsView.IndentContent = true;

            placementGuideScaleRandomizationSettings = DecorPaintObjectPlacementSettings.Get().SingleDecorPaintModeSettings.PlacementGuideScaleRandomizationSettings;
            guideScaleRandomizationSettingsView      = placementGuideScaleRandomizationSettings.View;
            guideScaleRandomizationSettingsView.VisibilityToggleIndent = 1;
            guideScaleRandomizationSettingsView.VisibilityToggleLabel  = "Scale Randomization Settings";
            guideScaleRandomizationSettingsView.IsVisible     = false;
            guideScaleRandomizationSettingsView.IndentContent = true;

            AxisAlignmentSettingsView placementGuideSurfaceAlignmentSettingsView = PointAndClickObjectPlacementSettings.Get().PlacementGuideSurfaceAlignmentSettings.View;

            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleIndent = 1;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleLabel  = "Surface Alignment Settings";

            placementGuideSurfaceAlignmentSettingsView = PathObjectPlacementSettings.Get().PlacementGuideSurfaceAlignmentSettings.View;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleIndent = 1;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleLabel  = "Surface Alignment Settings";

            placementGuideSurfaceAlignmentSettingsView = BlockObjectPlacementSettings.Get().PlacementGuideSurfaceAlignmentSettings.View;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleIndent = 1;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleLabel  = "Surface Alignment Settings";

            placementGuideSurfaceAlignmentSettingsView = DecorPaintObjectPlacementSettings.Get().SingleDecorPaintModeSettings.PlacementGuideSurfaceAlignmentSettings.View;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleIndent = 1;
            placementGuideSurfaceAlignmentSettingsView.VisibilityToggleLabel  = "Surface Alignment Settings";

            ObjectRotationRandomizationSettings     blockObjectRotationRandomizationSettings     = ObjectPlacement.Get().BlockObjectPlacement.BlockSettings.ManualConstructionSettings.ObjectRotationRandomizationSettings;
            ObjectRotationRandomizationSettingsView blockObjectRotationRandomizationSettingsView = blockObjectRotationRandomizationSettings.View;

            blockObjectRotationRandomizationSettings.CustomAxisRandomizationSettings.View.ToggleVisibilityBeforeRender = false;
            blockObjectRotationRandomizationSettings.CustomAxisRandomizationSettings.View.IsVisible = false;
            blockObjectRotationRandomizationSettings.CustomAxisRandomizationSettings.Randomize      = false;
            blockObjectRotationRandomizationSettingsView.SurroundWithBox        = false;
            blockObjectRotationRandomizationSettingsView.VisibilityToggleIndent = 1;
            blockObjectRotationRandomizationSettings.XAxisRandomizationSettings.View.VisibilityToggleLabel = blockObjectRotationRandomizationSettings.XAxisRandomizationSettings.Axis + " Axis Settings";
            blockObjectRotationRandomizationSettings.YAxisRandomizationSettings.View.VisibilityToggleLabel = blockObjectRotationRandomizationSettings.YAxisRandomizationSettings.Axis + " Axis Settings";
            blockObjectRotationRandomizationSettings.ZAxisRandomizationSettings.View.VisibilityToggleLabel = blockObjectRotationRandomizationSettings.ZAxisRandomizationSettings.Axis + " Axis Settings";

            XZOrientedEllipseShapeRenderSettingsView xzOrientedElipseShapeRenderSettingsView = DecorPaintObjectPlacement.Get().BrushCircleRenderSettings.View;

            xzOrientedElipseShapeRenderSettingsView.ToggleVisibilityBeforeRender = true;
            xzOrientedElipseShapeRenderSettingsView.IndentContent         = true;
            xzOrientedElipseShapeRenderSettingsView.VisibilityToggleLabel = "Brush Circle";
            xzOrientedElipseShapeRenderSettingsView.IsVisible             = false;

            ObjectPivotPointsRenderSettingsView guidePivotPointsSettingsView = ObjectPlacement.Get().GuidePivotPointsRenderSettings.View;

            guidePivotPointsSettingsView.ToggleVisibilityBeforeRender = true;
            guidePivotPointsSettingsView.IndentContent         = true;
            guidePivotPointsSettingsView.VisibilityToggleLabel = "Guide Pivot Points";
            guidePivotPointsSettingsView.IsVisible             = false;

            ObjectPlacement.Get().ObjectVertexSnapSessionRenderSettings.View.IsVisible = false;

            ProjectedBoxFacePivotPointsRenderSettings     projectedBoxFacePointsRenderSettings     = ObjectPlacement.Get().GuidePivotPointsRenderSettings.ProjectedBoxFacePivotPointsRenderSettings;
            ProjectedBoxFacePivotPointsRenderSettingsView projectedBoxFacePointsRenderSettingsView = projectedBoxFacePointsRenderSettings.View;

            projectedBoxFacePointsRenderSettingsView.ToggleVisibilityBeforeRender = true;
            projectedBoxFacePointsRenderSettingsView.IndentContent         = true;
            projectedBoxFacePointsRenderSettingsView.VisibilityToggleLabel = "Projected Guide Pivot Points";
            projectedBoxFacePointsRenderSettingsView.IsVisible             = false;

            SingleObjectPivotPointRenderSettingsView activePivotPointRenderSettingsView = projectedBoxFacePointsRenderSettings.ActivePivotPointRenderSettings.View;

            activePivotPointRenderSettingsView.ToggleVisibilityBeforeRender = true;
            activePivotPointRenderSettingsView.VisibilityToggleLabel        = "Active Pivot Point";
            activePivotPointRenderSettingsView.IndentContent          = true;
            activePivotPointRenderSettingsView.VisibilityToggleIndent = 1;

            SingleObjectPivotPointRenderSettingsView inactivePivotPointRenderSettingsView = projectedBoxFacePointsRenderSettings.InactivePivotPointRenderSettings.View;

            inactivePivotPointRenderSettingsView.ToggleVisibilityBeforeRender = true;
            inactivePivotPointRenderSettingsView.VisibilityToggleLabel        = "Inactive Pivot Point";
            inactivePivotPointRenderSettingsView.IndentContent          = true;
            inactivePivotPointRenderSettingsView.VisibilityToggleIndent = 1;

            ObjectMaskView objectMaskView = DecorPaintObjectPlacement.Get().DecorPaintMask.View;

            objectMaskView.SurroundWithBox = true;

            ObjectLayerObjectMaskView objectLayerObjectMaskView = DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectLayerObjectMask.View;

            objectLayerObjectMaskView.IsVisible = false;
            objectLayerObjectMaskView.ToggleVisibilityBeforeRender = true;
            objectLayerObjectMaskView.VisibilityToggleIndent       = 1;
            objectLayerObjectMaskView.VisibilityToggleLabel        = "Object Layer Decor Paint Mask";

            ObjectCollectionMaskView objectCollectionMaskView = DecorPaintObjectPlacement.Get().DecorPaintMask.ObjectCollectionMask.View;

            objectCollectionMaskView.IsVisible = false;
            objectCollectionMaskView.ToggleVisibilityBeforeRender = true;
            objectCollectionMaskView.VisibilityToggleIndent       = 1;
            objectCollectionMaskView.VisibilityToggleLabel        = "Object Decor Paint Mask";

            LabelRenderSettings labelRenderSettings = ObjectPlacement.Get().BlockObjectPlacement.BlockRenderSettings.ManualConstructionRenderSettings.DimensionsLabelRenderSettings;

            labelRenderSettings.Bold      = true;
            labelRenderSettings.FontSize  = 15;
            labelRenderSettings.TextColor = Color.white;
            LabelRenderSettingsView labelRenderSettingsView = labelRenderSettings.View;

            labelRenderSettingsView.ToggleVisibilityBeforeRender = true;
            labelRenderSettingsView.VisibilityToggleLabel        = "Dimensions Label";
            labelRenderSettingsView.IndentContent = true;
        }
예제 #6
0
        public List <ObjectPlacementData> Calculate()
        {
            if (_block == null || _block.NumberOfSegments == 0 || !ObjectPlacementGuide.ExistsInScene)
            {
                return(new List <ObjectPlacementData>());
            }

            Prefab     placementGuidePrefab        = ObjectPlacementGuide.Instance.SourcePrefab;
            Vector3    placementGuideWorldScale    = ObjectPlacementGuide.Instance.WorldScale;
            Quaternion placementGuideWorldRotation = ObjectPlacementGuide.Instance.WorldRotation;
            float      objectMissChance            = _block.Settings.ManualConstructionSettings.ObjectMissChance;
            ObjectRotationRandomizationSettings blockObjectRotationRandomizationSettings = _block.Settings.ManualConstructionSettings.ObjectRotationRandomizationSettings;
            bool           randomizeRotations = blockObjectRotationRandomizationSettings.RandomizeRotation;
            Vector3        objectOffsetAlongExtensionPlaneNormal = _block.Settings.ManualConstructionSettings.OffsetAlongGrowDirection * _block.ExtensionPlane.normal;
            bool           allowObjectIntersection = ObjectPlacementSettings.Get().ObjectIntersectionSettings.AllowIntersectionForBlockPlacement;
            bool           randomizePrefabs        = _block.Settings.ManualConstructionSettings.RandomizePrefabs;
            PrefabCategory activePrefabCategory    = PrefabCategoryDatabase.Get().ActivePrefabCategory;

            var objectPlacementDataInstances = new List <ObjectPlacementData>(_block.NumberOfSegments * 10);

            for (int segmentIndex = 0; segmentIndex < _block.NumberOfSegments; ++segmentIndex)
            {
                ObjectPlacementBoxStackSegment segment = _block.GetSegmentByIndex(segmentIndex);
                for (int stackIndex = 0; stackIndex < segment.NumberOfStacks; ++stackIndex)
                {
                    ObjectPlacementBoxStack stack = segment.GetStackByIndex(stackIndex);
                    if (stack.IsOverlappedByAnotherStack)
                    {
                        continue;
                    }

                    for (int stackBoxIndex = 0; stackBoxIndex < stack.NumberOfBoxes; ++stackBoxIndex)
                    {
                        ObjectPlacementBox box = stack.GetBoxByIndex(stackBoxIndex);
                        if (box.IsHidden)
                        {
                            continue;
                        }

                        if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementBlockManualConstructionSettings.MinObjectMissChance, ObjectPlacementBlockManualConstructionSettings.MaxObjectMissChance))
                        {
                            continue;
                        }

                        if (!allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(box.OrientedBox, true))
                        {
                            continue;
                        }

                        Quaternion worldRotation = placementGuideWorldRotation;
                        if (randomizeRotations)
                        {
                            worldRotation = ObjectRotationRandomization.GenerateRandomRotationQuaternion(blockObjectRotationRandomizationSettings);
                        }

                        Vector3 worldScale = placementGuideWorldScale;
                        Prefab  prefab     = placementGuidePrefab;
                        if (randomizePrefabs && activePrefabCategory.NumberOfPrefabs != 0)
                        {
                            int    randomPrefabIndex = UnityEngine.Random.Range(0, activePrefabCategory.NumberOfPrefabs);
                            Prefab randomPrefab      = activePrefabCategory.GetPrefabByIndex(randomPrefabIndex);
                            if (randomPrefab != null && randomPrefab.UnityPrefab != null)
                            {
                                prefab     = activePrefabCategory.GetPrefabByIndex(randomPrefabIndex);
                                worldScale = prefab.UnityPrefab.transform.lossyScale;
                            }
                        }

                        var objectPlacementData = new ObjectPlacementData();
                        objectPlacementData.WorldPosition = ObjectPositionCalculator.CalculateObjectHierarchyPosition(prefab, box.Center + objectOffsetAlongExtensionPlaneNormal, worldScale, placementGuideWorldRotation);
                        objectPlacementData.WorldScale    = worldScale;
                        objectPlacementData.WorldRotation = worldRotation;
                        objectPlacementData.Prefab        = prefab;
                        objectPlacementDataInstances.Add(objectPlacementData);
                    }
                }
            }

            return(objectPlacementDataInstances);
        }