///////////////////////////////////////// public Component_Scene CreateScene(bool enable) { DetachAndOrDestroyScene(); scene = ComponentUtility.CreateComponent <Component_Scene>(null, true, enable); //!!!!что еще отключать? scene.OctreeEnabled = false; //rendering pipeline { var pipeline = (Component_RenderingPipeline)scene.CreateComponent(RenderingSystem.RenderingPipelineDefault, -1, false); scene.RenderingPipeline = pipeline; //!!!!что еще отключать? pipeline.DeferredShading = AutoTrueFalse.False; pipeline.LODRange = new RangeI(0, 0); //pipeline.UseRenderTargets = false; //!!!! scene.BackgroundColor = new ColorValue(0.5, 0.5, 0.5); //scene.BackgroundColor = new ColorValue( 0, 0, 0, 0 ); scene.BackgroundColorAffectLighting = 1; scene.BackgroundColorEnvironmentOverride = new ColorValue(0.8, 0.8, 0.8); pipeline.Enabled = true; } //ambient light { var light = scene.CreateComponent <Component_Light>(); light.Type = Component_Light.TypeEnum.Ambient; light.Brightness = ReferenceUtility.MakeReference("Base\\ProjectSettings.component|PreviewAmbientLightBrightness"); //light.Brightness = ProjectSettings.Get.PreviewAmbientLightBrightness.Value; } //directional light { var light = scene.CreateComponent <Component_Light>(); light.Type = Component_Light.TypeEnum.Directional; light.Transform = new Transform(new Vector3(0, 0, 0), Quaternion.FromDirectionZAxisUp(new Vector3(0, 0, -1)), Vector3.One); light.Brightness = ReferenceUtility.MakeReference("Base\\ProjectSettings.component|PreviewDirectionalLightBrightness"); //light.Brightness = ProjectSettings.Get.PreviewDirectionalLightBrightness.Value; //!!!!? light.Shadows = false; //light.Type = Component_Light.TypeEnum.Point; //light.Transform = new Transform( new Vec3( 0, 0, 2 ), Quat.Identity, Vec3.One ); } scene.ViewportUpdateGetCameraSettings += Scene_ViewportUpdateGetCameraSettings; //connect scene to viewport if (viewport != null) { viewport.AttachedScene = scene; } return(scene); }
public static void CreatePreviewObjects(Component_Scene scene, Component_Surface surface) { DestroyPreviewObjects(scene); var center = Vector3.Zero; //!!!!среднее от всех групп double minDistanceBetweenObjects; { var groups = surface.GetComponents <Component_SurfaceGroupOfElements>(); if (groups.Length != 0) { minDistanceBetweenObjects = 0; foreach (var group in groups) { minDistanceBetweenObjects += group.MinDistanceBetweenObjects; } minDistanceBetweenObjects /= groups.Length; } else { minDistanceBetweenObjects = 1; } } //!!!! var toolRadius = minDistanceBetweenObjects * 5; // CreateObjectsBrushRadius; var toolStrength = 1.0; // CreateObjectsBrushStrength; var toolHardness = 0; // CreateObjectsBrushHardness; var random = new Random(0); double GetHardnessFactor(double length) { if (length == 0 || length <= toolHardness * toolRadius) { return(1); } else { double c; if (toolRadius - toolRadius * toolHardness != 0) { c = (length - toolRadius * toolHardness) / (toolRadius - toolRadius * toolHardness); } else { c = 0; } return((float)Math.Cos(Math.PI / 2 * c)); } } //calculate object count int count; { var toolSquare = Math.PI * toolRadius * toolRadius; double radius = minDistanceBetweenObjects / 2; double objectSquare = Math.PI * radius * radius; if (objectSquare < 0.1) { objectSquare = 0.1; } double maxCount = toolSquare / objectSquare; maxCount /= 10; count = (int)(toolStrength * (double)maxCount); count = Math.Max(count, 1); count *= 20; } var data = new List <Component_GroupOfObjects.Object>(count); //create point container to check by MinDistanceBetweenObjects PointContainer3D pointContainerFindFreePlace; { double minDistanceBetweenObjectsMax = 0; foreach (var group in surface.GetComponents <Component_SurfaceGroupOfElements>()) { minDistanceBetweenObjectsMax = Math.Max(minDistanceBetweenObjectsMax, group.MinDistanceBetweenObjects); } var bounds = new Bounds(center); bounds.Expand(toolRadius + minDistanceBetweenObjectsMax); pointContainerFindFreePlace = new PointContainer3D(bounds, 100); } for (int n = 0; n < count; n++) { surface.GetRandomVariation(new Component_Surface.GetRandomVariationOptions(), random, out var groupIndex, out var elementIndex, out var positionZ, out var rotation, out var scale); var surfaceGroup = surface.GetGroup(groupIndex); Vector3?position = null; int counter = 0; while (counter < 20) { var offset = new Vector2(random.Next(toolRadius * 2) - toolRadius, random.Next(toolRadius * 2) - toolRadius); //check by radius and by hardness var length = offset.Length(); if (length <= toolRadius && random.NextDouble() <= GetHardnessFactor(length)) { var position2 = center.ToVector2() + offset; //var result = Component_Scene_Utility.CalculateObjectPositionZ( Scene, toGroupOfObjects, center.Z, position2, destinationCachedBaseObjects ); //if( result.found ) //{ var p = new Vector3(position2, 0); // result.positionZ ); //check by MinDistanceBetweenObjects if (surfaceGroup == null || !pointContainerFindFreePlace.Contains(new Sphere(p, surfaceGroup.MinDistanceBetweenObjects))) { //found place to create position = p; break; } //} } counter++; } if (position != null) { var objPosition = position.Value + new Vector3(0, 0, positionZ); var objRotation = rotation; var objScale = scale; var surfaceElement = surfaceGroup.GetElement(elementIndex); var surfaceElementMesh = surfaceElement as Component_SurfaceElement_Mesh; if (surfaceElementMesh != null) { var meshInSpace = scene.CreateComponent <Component_MeshInSpace>(enabled: false); meshInSpace.Transform = new Transform(objPosition, objRotation, objScale); //!!!!так копировать? meshInSpace.Mesh = surfaceElementMesh.Mesh; if (meshInSpace.Mesh.Value == null) { meshInSpace.Mesh = ResourceUtility.MeshInvalid; } //!!!!так копировать? if (surfaceElementMesh.ReplaceMaterial.ReferenceSpecified) { meshInSpace.ReplaceMaterial = surfaceElementMesh.ReplaceMaterial; } meshInSpace.Enabled = true; } //add to point container pointContainerFindFreePlace.Add(ref objPosition); } } }