From 13287928eaf67302caab282c106681036d931a73 Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Fri, 16 Apr 2021 09:49:10 +0300 Subject: [PATCH] Graph3D: HideObjects ShowObjects --- InstallerSamples/Graph3D/Chess3D/game2.pas | 2 + .../Graph3D/EarthImageMaterial.pas | 7 ++- .../WireFramePrism.pas | 2 + .../Spheres.pas | 10 ++-- .../KeyFrameBasedTime.pas | 46 +++++++++++++++++++ .../Graph3D/Фигуры/Замок.pas | 3 ++ bin/Lib/Graph3D.pas | 17 +++++++ 7 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 InstallerSamples/Graph3D/События клавиатуры/KeyFrameBasedTime.pas diff --git a/InstallerSamples/Graph3D/Chess3D/game2.pas b/InstallerSamples/Graph3D/Chess3D/game2.pas index cefad7ab8..b98f89077 100644 --- a/InstallerSamples/Graph3D/Chess3D/game2.pas +++ b/InstallerSamples/Graph3D/Chess3D/game2.pas @@ -175,8 +175,10 @@ begin end; begin + HideObjects; InitScene; StartupPosition; + ShowObjects; //Turns('1. c2-c4 g7-g6 2. e2-e4 Cf8-g7 3. d2-d4 d7-d6 4. Kb1-c3 Kg8-f6 5. Kg1-f3 0-0 6. Cf1-e2 e7-e5 7. Cc1-e3 Kf6-g4 8. Ce3-g5 f7-f6 9. Cg5-h4 g6-g5 10. Ch4-g3 Kg4-h6'); Turns('1. e2-e4 e7-e5 2. f1-c4 g8-f6 3. d2-d4 e5-d4 4. g1-f3 d7-d5 5. e4-d5 f8-b4 6. c2-c3 d8-e7'); end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/EarthImageMaterial.pas b/InstallerSamples/Graph3D/EarthImageMaterial.pas index ec3918a2d..fbc64678a 100644 --- a/InstallerSamples/Graph3D/EarthImageMaterial.pas +++ b/InstallerSamples/Graph3D/EarthImageMaterial.pas @@ -1,7 +1,8 @@ -uses Graph3D; +uses Graph3D; begin - View3D.Title := ' '; + HideObjects; + View3D.Title := 'Вращение Земли'; View3D.CameraMode := CameraMode.Inspect; View3D.ShowCoordinateSystem := False; View3D.ShowGridLines := False; @@ -11,6 +12,8 @@ begin var c := Sphere(0,0,0,5,Colors.Wheat); c.Material := ImageMaterial('Earth.jpg'); + ShowObjects; + var gr := 0; var dgr := 1; while True do diff --git a/InstallerSamples/Graph3D/Проволочные Модели/WireFramePrism.pas b/InstallerSamples/Graph3D/Проволочные Модели/WireFramePrism.pas index 7badbd246..e5123d02b 100644 --- a/InstallerSamples/Graph3D/Проволочные Модели/WireFramePrism.pas +++ b/InstallerSamples/Graph3D/Проволочные Модели/WireFramePrism.pas @@ -1,6 +1,7 @@ uses Graph3D; begin + HideObjects; var p := PrismWireFrame(Origin,13,3,5); var pp := p.Points; foreach var x in pp do @@ -14,5 +15,6 @@ begin end; var p1 := p.Clone; p1.MoveByX(-5); + ShowObjects; p1.AnimRotate(OrtZ,360,10).Forever.Begin; end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/Производительность/Spheres.pas b/InstallerSamples/Graph3D/Производительность/Spheres.pas index 1d12c13a8..5398cadb4 100644 --- a/InstallerSamples/Graph3D/Производительность/Spheres.pas +++ b/InstallerSamples/Graph3D/Производительность/Spheres.pas @@ -1,23 +1,23 @@ uses Graph3D; begin - //view3d.ShowCameraInfo := True; + Window.Title := 'Creation of objects... wait!'; + HideObjects; View3D.ShowGridLines := False; View3D.ShowViewCube := False; View3D.ShowCoordinateSystem := False; var l := new List; - //Invoke(()->begin var w := 1; for var x := -5 to 5 do for var y := -5 to 5 do for var z := -5 to 5 do l.Add(Sphere(x*w,y*w,z*w,w*0.5,RandomColor)); - //end); + ShowObjects; + + Window.Title := 'Spheres animation'; foreach var x in l do x.AnimMoveBy(Random,Random,Random).AutoReverse.Forever.Begin; - - //Print(Milliseconds); end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/События клавиатуры/KeyFrameBasedTime.pas b/InstallerSamples/Graph3D/События клавиатуры/KeyFrameBasedTime.pas new file mode 100644 index 000000000..7f18cb53b --- /dev/null +++ b/InstallerSamples/Graph3D/События клавиатуры/KeyFrameBasedTime.pas @@ -0,0 +1,46 @@ +uses Graph3D; + +begin + Window.Title := 'Перемещение шара - анимация на основе кадра'; + View3D.Title := 'Используйте клавиши:'; + View3D.SubTitle := 'W,A,S,D,Стрелки - перемещение'; + var c := Sphere(0,0,0,1,Colors.SeaGreen); + c.Direction := V3D(-1,0,0); + c.Velocity := 5; + + var kl,kr,ku,kd: boolean; + + BeginFrameBasedAnimationTime(dt -> begin + if kr then + c.Direction := V3D(-1,c.Direction.Y,0) + else if kl then + c.Direction := V3D(1,c.Direction.Y,0) + else c.Direction := V3D(0,c.Direction.Y,0); + if ku then + c.Direction := V3D(c.Direction.X,-1,0) + else if kd then + c.Direction := V3D(c.Direction.X,1,0) + else c.Direction := V3D(c.Direction.X,0,0); + c.MoveTime(dt); + end); + + OnKeyDown := k -> + begin + case k of + Key.w,Key.Up: begin ku := true; kd := false; end; + Key.s,Key.Down: begin kd := true; ku := false; end; + Key.a,Key.Left: begin kl := true; kr := false; end; + Key.d,Key.Right: begin kr := true; kl := false; end; + end; + end; + OnKeyUp := k -> + begin + case k of + Key.w,Key.Up: ku := false; + Key.s,Key.Down: kd := false; + Key.a,Key.Left: kl := false; + Key.d,Key.Right: kr := false; + end; + end; + +end. \ No newline at end of file diff --git a/InstallerSamples/Graph3D/Фигуры/Замок.pas b/InstallerSamples/Graph3D/Фигуры/Замок.pas index 634750a68..2f353f903 100644 --- a/InstallerSamples/Graph3D/Фигуры/Замок.pas +++ b/InstallerSamples/Graph3D/Фигуры/Замок.pas @@ -15,6 +15,7 @@ begin end; begin + HideObjects; var b := Box(0,0,2,14.5,1,4,Colors.Orange); var c := Cube(6.75,0,4.5,1,RandomColor); var c1 := Cone(6.75,0,5,1.5,0.4,RandomColor); @@ -27,6 +28,8 @@ begin var g3 := gg.Clone.MoveByX(-6); gg.MoveByX(6); var ggg := Group(gg,g1,g2,g3); + ShowObjects; + ggg.Save('Замок.xaml'); //ggg.AnimRotate(OrtZ,360,10).Forever.begin; end. \ No newline at end of file diff --git a/bin/Lib/Graph3D.pas b/bin/Lib/Graph3D.pas index 84be6d6a8..771148a5d 100644 --- a/bin/Lib/Graph3D.pas +++ b/bin/Lib/Graph3D.pas @@ -3199,6 +3199,10 @@ function Group: Group3D; function Group(params lst: array of Object3D): Group3D; /// Возвращает группу объектов из последовательности en function Group(en: sequence of Object3D): Group3D; +/// Не отображать слой графических объектов (обычно вызывается в начале до создания графических объектов) +procedure HideObjects; +/// Отображать слой графических объектов (вызывается после HideObjects и создания начальной сцены графических объектов) +procedure ShowObjects; // ----------------------------------------------------- //>> Graph3D: функции для создания 3D-объектов # Graph3D functions for creation 3D-objects @@ -3463,6 +3467,8 @@ var //{{{--doc: Конец секции 1 }}} + + ///-- procedure __InitModule__; ///-- @@ -3470,6 +3476,17 @@ procedure __FinalizeModule__; implementation +procedure HideObjects; +begin + Invoke(()->begin hvp.Visibility := Visibility.Hidden end); +end; + +procedure ShowObjects; +begin + Invoke(()->begin hvp.Visibility := Visibility.Visible end); +end; + + type CustomBinder = class(SerializationBinder) public function BindToType(assemblyName, typeName: string): System.Type; override;