Debian Codegraph @

tests/code/testcases/testcastlescenecore.pas

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 // -*- compile-command: "./test_single_testcase.sh TTestSceneCore" -*-
2 {
3 Copyright 2020-2023 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Test CastleSceneCore unit. }
18 unit TestCastleSceneCore;
19
20 interface
21
22 uses
23 Classes, SysUtils,
24 CastleTester, CastleSceneCore, X3DNodes;
25
26 type
27 TTestSceneCore = class(TCastleTestCase)
28 strict private
29 SearchingForDescription: string;
30 WarningFlag: Boolean;
31 function SearchingForDescriptionCallback(Node: TX3DNode): Pointer;
32 procedure NodeMultipleTimesWarning(const Category, S: string);
33 procedure OnWarningFlag(const Category, S: string);
34 { Load scene and expect a warning during loading.
35 Raises error if no warnings occurred. }
36 procedure LoadSceneRequireWarning(const Scene: TCastleSceneCore; const Url: String);
37 published
38 procedure TestBorderManifoldEdges;
39 procedure TestIterator;
40 { $define ITERATOR_SPEED_TEST}
41 {$ifdef ITERATOR_SPEED_TEST}
42 procedure TestIteratorSpeed;
43 {$endif ITERATOR_SPEED_TEST}
44 procedure TestFind;
45 procedure TestViewpointBillboardTricky;
46 procedure TestManifold;
47 procedure TestMultipleScenesOneNodeIncorrect;
48 procedure TestMultipleScenesOneNodeCorrect;
49 procedure TestSpineUtf8Names;
50 procedure TestAnimsInSwitch;
51 procedure TestLoadGzipped;
52 procedure TestStarlingAndAnchors;
53 procedure TestCocos;
54 procedure TestImageAsNode;
55 procedure TestPlayStopAnim;
56 procedure TestFontStyleChanges;
57 procedure TestUnassociate;
58 procedure TestUnassociate2;
59 procedure TestUnassociate3;
60 procedure TestUnassociateChangeMaterialOneLeft;
61 procedure TestUnassociateChangeMaterialSharedAppearance;
62 procedure TestUnassociateChangeAppearance;
63 procedure TestUnassociateAbstractPrimitive;
64 procedure TestUnassociateAbstractPrimitiveSimplified;
65 procedure TestNonGenericNode;
66 {$ifdef GENERIC_METHODS}
67 procedure TestGenericNode;
68 {$endif}
69 procedure TestNonGenericNodeAndFindNodeOptions;
70 procedure TestGeometryNodesInShape;
71 procedure TestExposedTransforms;
72 //procedure TestInternalNodesReadOnly;
73 end;
74
75 implementation
76
77 uses X3DLoad, CastleVectors, CastleShapes,
78 CastleTimeUtils, CastleStringUtils, X3DFields, CastleViewport, CastleBoxes,
79 CastleFilesUtils, CastleScene, CastleTransform, CastleApplicationProperties,
80 CastleUriUtils, CastleColors;
81
82 procedure TTestSceneCore.TestBorderManifoldEdges;
83 var
84 Scene: TCastleSceneCore;
85 Manifold, Border: Cardinal;
86 begin
87 Scene := TCastleSceneCore.Create(nil);
88 try
89 Scene.Load('castle-data:/model_manifold.wrl');
90 Scene.EdgesCount(Manifold, Border);
91 AssertEquals(0, Border);
92 finally FreeAndNil(Scene) end;
93 end;
94
95 {$ifdef ITERATOR_SPEED_TEST}
96 procedure TTestSceneCore.TestIteratorSpeed;
97
98 procedure CheckIteratorSpeed(const FileName: string;
99 const TestCount: Integer = 1000);
100 var
101 Scene: TCastleSceneCore;
102 List: TShapesList;
103 SI: TShapeTreeIterator;
104 OnlyActive: boolean;
105 I: Integer;
106 Test: Integer;
107 begin
108 Writeln('CheckIteratorSpeed on ', FileName);
109
110 Scene := TCastleSceneCore.Create(nil);
111 try
112 Scene.Load(FileName);
113 for OnlyActive := false to true do
114 begin
115 ProcessTimerBegin;
116 for Test := 0 to TestCount - 1 do
117 begin
118 List := TShapesList.Create(Scene.Shapes, OnlyActive);
119 for I := 0 to List.Count - 1 do
120 { Just do anything that requires access to List[I] }
121 PointerToStr(List[I].Geometry);
122 FreeAndNil(List);
123 end;
124 Writeln('TShapesList traverse: ', ProcessTimerEnd:1:2);
125
126 ProcessTimerBegin;
127 for Test := 0 to TestCount - 1 do
128 begin
129 SI := TShapeTreeIterator.Create(Scene.Shapes, OnlyActive);
130 while SI.GetNext do
131 PointerToStr(SI.Current.Geometry);
132 FreeAndNil(SI);
133 end;
134 Writeln('TShapeTreeIterator: ', ProcessTimerEnd:1:2);
135
136 end;
137 finally FreeAndNil(Scene) end;
138 end;
139
140 begin
141 CheckIteratorSpeed('../../demo_models/x3d/deranged_house_final.x3dv');
142 CheckIteratorSpeed('../../demo_models/x3d/anchor_test.x3dv');
143 CheckIteratorSpeed('../../demo_models/x3d/switches_and_transforms.x3dv');
144 CheckIteratorSpeed('../../demo_models/x3d/key_sensor.x3dv');
145
146 CheckIteratorSpeed('castle-data:/switches_and_transforms_2.x3dv');
147 CheckIteratorSpeed('castle-data:/key_sensor_2.x3dv');
148
149 CheckIteratorSpeed('/home/michalis/sources/rrtankticks2/rrtankticks3/rrtt.wrl',
150 10); { smaller TestCount, as it's quite slow }
151 end;
152 {$endif ITERATOR_SPEED_TEST}
153
154 procedure TTestSceneCore.TestIterator;
155
156 procedure CheckIterator(const FileName: string);
157 var
158 Scene: TCastleSceneCore;
159 List: TShapeList;
160 SI: TShapeTreeIterator;
161 OnlyActive: boolean;
162 I: Integer;
163 begin
164 Scene := TCastleSceneCore.Create(nil);
165 try
166 Scene.Load(FileName);
167 for OnlyActive := false to true do
168 begin
169 { Compare the simple iterator implementation (that just calls
170 Traverse and gathers results to the list) with actual sophisticated
171 implementation in TShapeTreeIterator. }
172 List := TShapeList.Create(Scene.Shapes, OnlyActive);
173 SI := TShapeTreeIterator.Create(Scene.Shapes, OnlyActive);
174 for I := 0 to List.Count - 1 do
175 begin
176 AssertTrue('SI.GetNext', SI.GetNext);
177 AssertTrue('SI.Current', SI.Current = List[I]);
178 end;
179 AssertTrue('not SI.GetNext', not SI.GetNext);
180
181 // writeln('done for ', FileName, ' active: ', OnlyActive, ' count is ', List.Count);
182
183 FreeAndNil(List);
184 FreeAndNil(SI);
185 end;
186 finally FreeAndNil(Scene) end;
187 end;
188
189 begin
190 CheckIterator('castle-data:/demo-models-copy/deranged_house_final.x3dv');
191 CheckIterator('castle-data:/demo-models-copy/anchor_test.x3dv');
192 CheckIterator('castle-data:/switches_and_transforms_2.x3dv');
193 CheckIterator('castle-data:/key_sensor_2.x3dv');
194 CheckIterator('castle-data:/extrusion_empty_spine.x3dv');
195 CheckIterator('castle-data:/extrusion_empty_spine_concave.x3dv');
196 CheckIterator('castle-data:/extrusion_empty_spine_smooth.x3dv');
197
198 // This once failed to be read with FPC 3.1.1
199 CheckIterator('castle-data:/spine/escape_from_the_universe_boss/boss.json');
200
201 // This once failed to be read, as the Spine has DefaultSkin = nil
202 CheckIterator('castle-data:/spine/empty_spine.json');
203
204 // This once failed with access violation because TClippingAttachment.BuildNodes didn't assign Material
205 CheckIterator('castle-data:/spine/clip_region/skeleton.json');
206 end;
207
208 procedure TTestSceneCore.TestFind;
209 var
210 Scene: TCastleSceneCore;
211 begin
212 Scene := TCastleSceneCore.Create(nil);
213 try
214 try
215 Scene.Node('Left');
216 Fail('Should fail with EX3DNotFound');
217 except on EX3DNotFound do ; end;
218
219 try
220 Scene.Field('Left', 'translation');
221 Fail('Should fail with EX3DNotFound');
222 except on EX3DNotFound do ; end;
223
224 try
225 Scene.Event('Left', 'addChildren');
226 Fail('Should fail with EX3DNotFound');
227 except on EX3DNotFound do ; end;
228
229 Scene.URL := 'castle-data:/switches_and_transforms_2.x3dv';
230 Scene.Node('Left');
231 Scene.Field('Left', 'translation');
232 Scene.Event('Left', 'addChildren');
233
234 try
235 Scene.Node('Blah');
236 Fail('Should fail with EX3DNotFound');
237 except on EX3DNotFound do ; end;
238
239 try
240 Scene.Field('Blah', 'translation');
241 Fail('Should fail with EX3DNotFound');
242 except on EX3DNotFound do ; end;
243
244 try
245 Scene.Event('Blah', 'addChildren');
246 Fail('Should fail with EX3DNotFound');
247 except on EX3DNotFound do ; end;
248
249 try
250 Scene.Field('Left', 'blah');
251 Fail('Should fail with EX3DNotFound');
252 except on EX3DNotFound do ; end;
253
254 try
255 Scene.Event('Left', 'blah');
256 Fail('Should fail with EX3DNotFound');
257 except on EX3DNotFound do ; end;
258 finally FreeAndNil(Scene) end;
259 end;
260
261 function TTestSceneCore.SearchingForDescriptionCallback(Node: TX3DNode): Pointer;
262 begin
263 if (Node is TAbstractViewpointNode) and
264 (TAbstractViewpointNode(Node).SmartDescription = SearchingForDescription) then
265 Result := Node else
266 Result := nil;
267 end;
268
269 procedure TTestSceneCore.TestViewpointBillboardTricky;
270 { Unfortunately, it cannot reproduce bug #38 for some reason...
271 Probably it misses something that triggers it interactively. }
272 var
273 Scene: TCastleScene;
274
275 function FindViewpointByDescription(const Description: string): TAbstractViewpointNode;
276 begin
277 SearchingForDescription := Description;
278 AssertTrue(Scene.RootNode <> nil);
279 Result := TAbstractViewpointNode(
280 Scene.RootNode.SearchNodes({$ifdef FPC}@{$endif}SearchingForDescriptionCallback, true));
281 AssertTrue(Result <> nil);
282 end;
283
284 var
285 Viewpoint: TAbstractViewpointNode;
286 Viewport: TCastleViewport;
287 FakeRemoveMe: TRemoveType;
288 begin
289 Viewport := TCastleSceneManager.Create(nil);
290 try
291 Viewport.FullSize := true;
292 Viewport.AutoCamera := true;
293 Scene := TCastleScene.Create(nil);
294 try
295 Scene.URL := 'castle-data:/city_from_bugreport_38.x3dv';
296 Scene.ProcessEvents := true;
297 Scene.PreciseCollisions := true;
298 Viewport.Items.Add(Scene);
299 Viewport.Items.MainScene := Scene;
300
301 Scene.InternalCameraChanged;
302 FakeRemoveMe := rtNone;
303 Scene.Update(1, FakeRemoveMe);
304
305 Viewpoint := FindViewpointByDescription('City plan');
306 Viewpoint.Bound := true;
307
308 Scene.InternalCameraChanged;
309 FakeRemoveMe := rtNone;
310 Scene.Update(1, FakeRemoveMe);
311 finally FreeAndNil(Scene) end;
312 finally FreeAndNil(Viewport) end;
313 end;
314
315 procedure TTestSceneCore.TestManifold;
316 var
317 Scene: TCastleSceneCore;
318 ManifoldEdges, BorderEdges: Cardinal;
319 begin
320 Scene := TCastleSceneCore.Create(nil);
321 try
322 Scene.URL := 'castle-data:/shadow_volumes_tests/should_be_manifold.x3d';
323 Scene.EdgesCount(ManifoldEdges, BorderEdges);
324 AssertEquals(0, BorderEdges);
325 AssertEquals(210, ManifoldEdges);
326 finally FreeAndNil(Scene) end;
327 end;
328
329 type
330 ENodeMultipleTimes = class(Exception);
331
332 procedure TTestSceneCore.NodeMultipleTimesWarning(const Category, S: string);
333 begin
334 if Pos('is already part of another TCastleScene instance', S) <> 0 then
335 raise ENodeMultipleTimes.Create('We want this warning, good: ' + S)
336 else
337 raise Exception.Create('Some invalid warning: ' + S);
338 end;
339
340 procedure TTestSceneCore.TestMultipleScenesOneNodeIncorrect;
341
342 { Deliberately do something incorrect: place the same TX3DRootNode
343 in multiple TCastleScene instances.
344 Check that we make a warning about it. }
345
346 var
347 Node: TX3DRootNode;
348 Scene1, Scene2: TCastleScene;
349 begin
350 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}NodeMultipleTimesWarning);
351 try
352 try
353 Node := nil;
354 Scene1 := nil;
355 Scene2 := nil;
356 try
357 Node := LoadNode('castle-data:/game/scene.x3d');
358 Scene1 := TCastleScene.Create(nil);
359 Scene2 := TCastleScene.Create(nil);
360 Scene1.Load(Node, false);
361 Scene2.Load(Node, false);
362 raise Exception.Create('We should not get here, expected ENodeMultipleTimes on the way');
363 finally
364 FreeAndNil(Scene1);
365 FreeAndNil(Scene2);
366 // Note: you must free Node after freeing Scene1,2
367 FreeAndNil(Node);
368 end;
369 except
370 on ENodeMultipleTimes do ; { good, silence this for the sake of test }
371 end;
372 finally
373 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}NodeMultipleTimesWarning);
374 end;
375 end;
376
377 procedure TTestSceneCore.TestMultipleScenesOneNodeCorrect;
378 var
379 Node: TX3DRootNode;
380 Scene1, Scene2, SceneTemplate: TCastleScene;
381 begin
382 { When using InternalNodesReadOnly (no longer available),
383 it is allowed to have the same TX3DRootNode reused: }
384 (*
385
386 Node := nil;
387 Scene1 := nil;
388 Scene2 := nil;
389 try
390 Node := LoadNode('castle-data:/game/scene.x3d');
391 Scene1 := TCastleScene.Create(nil);
392 Scene1.InternalNodesReadOnly := true;
393 Scene2 := TCastleScene.Create(nil);
394 Scene2.InternalNodesReadOnly := true;
395 Scene1.Load(Node, false);
396 Scene2.Load(Node, false);
397 finally
398 FreeAndNil(Scene1);
399 FreeAndNil(Scene2);
400 // Note: you must free Node after freeing Scene1,2
401 FreeAndNil(Node);
402 end;
403 *)
404
405 // Using DeepCopy you can also share node, without InternalNodesReadOnly
406
407 Node := nil;
408 Scene1 := nil;
409 Scene2 := nil;
410 try
411 Node := LoadNode('castle-data:/game/scene.x3d');
412 Scene1 := TCastleScene.Create(nil);
413 Scene2 := TCastleScene.Create(nil);
414 Scene1.Load(Node.DeepCopy as TX3DRootNode, true);
415 Scene2.Load(Node.DeepCopy as TX3DRootNode, true);
416 finally
417 FreeAndNil(Node);
418 FreeAndNil(Scene1);
419 FreeAndNil(Scene2);
420 end;
421
422 // Using Clone you can also share node, without InternalNodesReadOnly
423
424 SceneTemplate := nil;
425 Scene1 := nil;
426 Scene2 := nil;
427 try
428 SceneTemplate := TCastleScene.Create(nil);
429 SceneTemplate.Load('castle-data:/game/scene.x3d');
430 Scene1 := SceneTemplate.Clone(nil);
431 Scene2 := SceneTemplate.Clone(nil);
432 finally
433 FreeAndNil(SceneTemplate);
434 FreeAndNil(Scene1);
435 FreeAndNil(Scene2);
436 end;
437 end;
438
439 procedure TTestSceneCore.TestSpineUtf8Names;
440 var
441 Scene: TCastleScene;
442 begin
443 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
444 try
445 Scene := TCastleScene.Create(nil);
446 try
447 Scene.Load('castle-data:/spine/uhholy_chapter_one_end/skeleton.json');
448 Scene.Load('castle-data:/spine/unholy_transition/phone.json');
449 finally FreeAndNil(Scene) end;
450 finally
451 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
452 end;
453 end;
454
455 procedure TTestSceneCore.TestAnimsInSwitch;
456 var
457 Scene: TCastleScene;
458 Anims: TStrings;
459 begin
460 Scene := TCastleScene.Create(nil);
461 try
462 Scene.Load('castle-data:/animation_under_switch/both.x3dv');
463 Anims := Scene.AnimationsList;
464 AssertTrue(Anims.IndexOf('Attack') <> -1);
465 AssertTrue(Anims.IndexOf('Damaged') <> -1);
466 AssertTrue(Anims.IndexOf('flying') <> -1);
467 AssertTrue(Anims.IndexOf('flying_left') <> -1);
468 finally FreeAndNil(Scene) end;
469 end;
470
471 procedure TTestSceneCore.TestLoadGzipped;
472
473 procedure TestSphere(const Url: String);
474 var
475 Scene: TCastleScene;
476 Shape: TShapeNode;
477 Sphere: TSphereNode;
478 begin
479 Scene := TCastleScene.Create(nil);
480 try
481 Scene.Load(Url);
482 AssertEquals(1, Scene.RootNode.FdChildren.Count);
483 AssertTrue(Scene.RootNode.FdChildren[0] is TShapeNode);
484 Shape := Scene.RootNode.FdChildren[0] as TShapeNode;
485 AssertTrue(Shape.Geometry is TSphereNode);
486 Sphere := Shape.Geometry as TSphereNode;
487 { Special epsilon necessary to pass test on Raspberry Pi (Linux/Arm). }
488 AssertSameValue(123.456, Sphere.Radius, 0.0001);
489 finally FreeAndNil(Scene) end;
490 end;
491
492 begin
493 TestSphere('castle-data:/gzipped_x3d/sphere.wrl');
494 TestSphere('castle-data:/gzipped_x3d/sphere.wrl.gz');
495 TestSphere('castle-data:/gzipped_x3d/sphere.wrz');
496 TestSphere('castle-data:/gzipped_x3d/sphere.x3d');
497 TestSphere('castle-data:/gzipped_x3d/sphere.x3d.gz');
498 TestSphere('castle-data:/gzipped_x3d/sphere.x3dv');
499 TestSphere('castle-data:/gzipped_x3d/sphere.x3dv.gz');
500 TestSphere('castle-data:/gzipped_x3d/sphere.x3dvz');
501 TestSphere('castle-data:/gzipped_x3d/sphere.x3dz');
502 TestSphere('castle-data:/gzipped_x3d/sphere_normal_extension_but_gzipped.wrl');
503 TestSphere('castle-data:/gzipped_x3d/sphere_normal_extension_but_gzipped.x3dv');
504 end;
505
506 procedure TTestSceneCore.OnWarningFlag(const Category, S: string);
507 begin
508 WarningFlag := true;
509 end;
510
511 procedure TTestSceneCore.LoadSceneRequireWarning(const Scene: TCastleSceneCore; const Url: String);
512 begin
513 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningFlag);
514 try
515 WarningFlag := false;
516 Scene.Load(Url);
517 if not WarningFlag then
518 Fail(Format('Expected to get some warning during loading of "%s"',
519 [UriDisplay(Url)]));
520 finally
521 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningFlag);
522 end;
523 end;
524
525 procedure TTestSceneCore.TestStarlingAndAnchors;
526 var
527 Scene: TCastleScene;
528 begin
529 Scene := TCastleScene.Create(nil);
530 try
531 Scene.Load('castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml');
532 AssertEquals(45, Scene.AnimationsList.Count);
533 AssertEquals(-1, Scene.AnimationsList.IndexOf('walk'));
534 finally FreeAndNil(Scene) end;
535
536 Scene := TCastleScene.Create(nil);
537 try
538 Scene.Load('castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#anim-naming:strict-underscore');
539 AssertEquals(45, Scene.AnimationsList.Count);
540 AssertEquals(-1, Scene.AnimationsList.IndexOf('walk'));
541 finally FreeAndNil(Scene) end;
542
543 Scene := TCastleScene.Create(nil);
544 try
545 Scene.Load('castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#fps:10,anim-naming:strict-underscore');
546 AssertEquals(45, Scene.AnimationsList.Count);
547 AssertEquals(-1, Scene.AnimationsList.IndexOf('walk'));
548 finally FreeAndNil(Scene) end;
549
550 Scene := TCastleScene.Create(nil);
551 try
552 Scene.Load('castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#anim-naming:trailing-number');
553 AssertEquals(31, Scene.AnimationsList.Count);
554 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
555 finally FreeAndNil(Scene) end;
556
557 Scene := TCastleScene.Create(nil);
558 try
559 Scene.Load('castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#fps:10,anim-naming:trailing-number');
560 AssertEquals(31, Scene.AnimationsList.Count);
561 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
562 finally FreeAndNil(Scene) end;
563
564 Scene := TCastleScene.Create(nil);
565 try
566 LoadSceneRequireWarning(Scene, 'castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#invalid-anchor,fps:10,anim-naming:trailing-number');
567 finally FreeAndNil(Scene) end;
568
569 Scene := TCastleScene.Create(nil);
570 try
571 LoadSceneRequireWarning(Scene, 'castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#invalid-anchor:blahblah,fps:10,anim-naming:trailing-number');
572 finally FreeAndNil(Scene) end;
573
574 Scene := TCastleScene.Create(nil);
575 try
576 LoadSceneRequireWarning(Scene, 'castle-data:/sprite-sheets/starling_kenney_robot/character_robot_sheet.starling-xml#fps:10,anim-naming:invalid-name');
577 finally FreeAndNil(Scene) end;
578 end;
579
580 procedure TTestSceneCore.TestCocos;
581 var
582 Scene: TCastleScene;
583 begin
584 Scene := TCastleScene.Create(nil);
585 try
586 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist');
587 AssertEquals(4, Scene.AnimationsList.Count);
588 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
589 finally FreeAndNil(Scene) end;
590
591 Scene := TCastleScene.Create(nil);
592 try
593 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist#fps:10');
594 AssertEquals(4, Scene.AnimationsList.Count);
595 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
596 finally FreeAndNil(Scene) end;
597
598 Scene := TCastleScene.Create(nil);
599 try
600 LoadSceneRequireWarning(Scene, 'castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist#fps:10,anim-naming:trailing-number');
601 AssertEquals(4, Scene.AnimationsList.Count);
602 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
603 finally FreeAndNil(Scene) end;
604 end;
605
606 procedure TTestSceneCore.TestImageAsNode;
607 var
608 Scene: TCastleScene;
609 begin
610 Scene := TCastleScene.Create(nil);
611 try
612 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.png');
613 AssertEquals(0, Scene.AnimationsList.Count);
614 finally FreeAndNil(Scene) end;
615
616 Scene := TCastleScene.Create(nil);
617 try
618 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.png#left:100,bottom:100,width:256,height:256');
619 AssertEquals(0, Scene.AnimationsList.Count);
620 finally FreeAndNil(Scene) end;
621 end;
622
623 procedure TTestSceneCore.TestPlayStopAnim;
624 var
625 Scene: TCastleScene;
626 begin
627 Scene := TCastleScene.Create(nil);
628 try
629 Scene.ProcessEvents := true;
630 Scene.Load('castle-data:/spine/escape_from_the_universe_boss/boss.json');
631 Scene.Exists := false; // doesn't matter for animation playing
632
633 Scene.PlayAnimation('flying', true);
634 AssertTrue(Scene.CurrentAnimation <> nil);
635 AssertEquals('flying', Scene.CurrentAnimation.X3DName);
636
637 Scene.StopAnimation;
638 AssertTrue(Scene.CurrentAnimation = nil);
639 finally FreeAndNil(Scene) end;
640 end;
641
642 procedure TTestSceneCore.TestFontStyleChanges;
643 var
644 FontStyleNode: TFontStyleNode;
645 TextNode: TTextNode;
646 TextShape: TShapeNode;
647 RootNode: TX3DRootNode;
648 Scene: TCastleScene;
649 Box: TBox3D;
650 begin
651 FontStyleNode := TFontStyleNode.Create;
652
653 TextNode := TTextNode.CreateWithShape(TextShape);
654 TextNode.FontStyle := FontStyleNode;
655 TextNode.SetString(['one line of text']);
656
657 RootNode := TX3DRootNode.Create;
658 RootNode.AddChildren(TextShape);
659
660 Scene := TCastleScene.Create(nil);
661 try
662 // Scene.ProcessEvents := true; // this should work even without process events, TCastleText depends on it
663 Scene.Load(RootNode, true);
664
665 Box := Scene.BoundingBox;
666 //Writeln(Box.ToString);
667 AssertSameValue(1, Box.Size.Y);
668
669 FontStyleNode.Size := 10;
670 Box := Scene.BoundingBox;
671 //Writeln(Box.ToString);
672 AssertSameValue(10, Box.Size.Y);
673
674 FontStyleNode.Size := 100;
675 Box := Scene.BoundingBox;
676 //Writeln(Box.ToString);
677 AssertSameValue(100, Box.Size.Y);
678
679 finally FreeAndNil(Scene) end;
680 end;
681
682 procedure TTestSceneCore.TestUnassociate;
683 var
684 Box: TCastleBox;
685 begin
686 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
687 try
688 Box := TCastleBox.Create(nil);
689 try
690 Box.Material := pmUnlit;
691 Box.Material := pmPhysical;
692 finally FreeAndNil(Box) end;
693 finally
694 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
695 end;
696 end;
697
698 procedure TTestSceneCore.TestUnassociate2;
699 var
700 Shape: TShapeNode;
701 NewMaterial: TMaterialNode;
702 Scene: TCastleScene;
703 begin
704 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
705 try
706 Scene := TCastleScene.Create(nil);
707 try
708 Scene.Load('castle-data:/test_for_material_change.x3dv');
709 Scene.PreciseCollisions := true;
710 Scene.ProcessEvents := true;
711
712 Shape := Scene.Node('MyShape') as TShapeNode;
713
714 NewMaterial := TMaterialNode.Create;
715 NewMaterial.Scene := Scene;
716 NewMaterial.DiffuseColor := Vector3(0, 1, 1);
717 Shape.Material := NewMaterial; // using deprecated Shape.Material, TestUnassociate3 will test undeprecated way
718 finally FreeAndNil(Scene) end;
719 finally
720 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
721 end;
722 end;
723
724 procedure TTestSceneCore.TestUnassociate3;
725 var
726 Shape: TShapeNode;
727 Appearance: TAppearanceNode;
728 NewMaterial: TMaterialNode;
729 Scene: TCastleScene;
730 begin
731 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
732 try
733 Scene := TCastleScene.Create(nil);
734 try
735 Scene.Load('castle-data:/test_for_material_change.x3dv');
736 Scene.PreciseCollisions := true;
737 Scene.ProcessEvents := true;
738
739 Shape := Scene.Node('MyShape') as TShapeNode;
740
741 NewMaterial := TMaterialNode.Create;
742 NewMaterial.Scene := Scene;
743 NewMaterial.DiffuseColor := Vector3(0, 1, 1);
744
745 Appearance := TAppearanceNode.Create;
746 Appearance.Material := NewMaterial;
747
748 Shape.Appearance := Appearance;
749 finally FreeAndNil(Scene) end;
750 finally
751 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
752 end;
753 end;
754
755 procedure TTestSceneCore.TestUnassociateChangeMaterialOneLeft;
756 var
757 RootNode: TX3DRootNode;
758 Shape1, Shape2: TShapeNode;
759 OldMaterial: TMaterialNode;
760 NewMaterial: TUnlitMaterialNode;
761 Scene: TCastleScene;
762 begin
763 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
764 try
765 Scene := TCastleScene.Create(nil);
766 try
767 RootNode := TX3DRootNode.Create;
768
769 OldMaterial := TMaterialNode.Create;
770
771 Shape1 := TShapeNode.Create;
772 Shape1.Material := OldMaterial; // will also auto-create Shape.Appearance, OK
773 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
774 RootNode.AddChildren(Shape1);
775
776 Shape2 := TShapeNode.Create;
777 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
778 Shape2.Material := OldMaterial; // will also auto-create Shape.Appearance, OK
779 RootNode.AddChildren(Shape2);
780
781 Scene.Load(RootNode, true);
782 Scene.PreciseCollisions := true;
783 Scene.ProcessEvents := true;
784
785 NewMaterial := TUnlitMaterialNode.Create;
786
787 AssertTrue(OldMaterial.Scene <> nil);
788 AssertTrue(NewMaterial.Scene = nil);
789 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldMaterial));
790 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewMaterial));
791 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape1.Appearance));
792 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape2.Appearance));
793
794 // NewMaterial.Scene := Scene; // should work with and without this
795 Shape1.Material := NewMaterial; // but leave Shape2 unchanged
796
797 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldMaterial));
798 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewMaterial));
799 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape1.Appearance));
800 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape2.Appearance));
801 finally FreeAndNil(Scene) end;
802 finally
803 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
804 end;
805 end;
806
807 procedure TTestSceneCore.TestUnassociateChangeMaterialSharedAppearance;
808 var
809 RootNode: TX3DRootNode;
810 Shape1, Shape2: TShapeNode;
811 OldMaterial: TMaterialNode;
812 NewMaterial: TUnlitMaterialNode;
813 SharedAppearance: TAppearanceNode;
814 Scene: TCastleScene;
815 begin
816 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
817 try
818 Scene := TCastleScene.Create(nil);
819 try
820 RootNode := TX3DRootNode.Create;
821
822 OldMaterial := TMaterialNode.Create;
823 OldMaterial.KeepExistingBegin; // otherwise it would be destroyed by assigning other node
824
825 SharedAppearance := TAppearanceNode.Create;
826 SharedAppearance.Material := OldMaterial;
827
828 Shape1 := TShapeNode.Create;
829 Shape1.Appearance := SharedAppearance;
830 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
831 RootNode.AddChildren(Shape1);
832
833 Shape2 := TShapeNode.Create;
834 Shape2.Appearance := SharedAppearance;
835 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
836 RootNode.AddChildren(Shape2);
837
838 Scene.Load(RootNode, true);
839 Scene.PreciseCollisions := true;
840 Scene.ProcessEvents := true;
841
842 NewMaterial := TUnlitMaterialNode.Create;
843
844 AssertTrue(SharedAppearance.Scene <> nil);
845 AssertTrue(OldMaterial.Scene <> nil);
846 AssertTrue(NewMaterial.Scene = nil);
847 AssertEquals(2, TShapeTree.AssociatedShapesCount(SharedAppearance));
848 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldMaterial));
849 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewMaterial));
850
851 // NewMaterial.Scene := Scene; // should work with and without this
852 Shape1.Material := NewMaterial; // equivalent to SharedAppearance.Material := NewMaterial;
853 //SharedAppearance.Material := NewMaterial;
854
855 AssertEquals(2, TShapeTree.AssociatedShapesCount(SharedAppearance));
856 AssertEquals(0, TShapeTree.AssociatedShapesCount(OldMaterial));
857 AssertEquals(2, TShapeTree.AssociatedShapesCount(NewMaterial));
858
859 // OldMaterial now unused
860 OldMaterial.KeepExistingEnd;
861 FreeIfUnusedAndNil(OldMaterial);
862 AssertTrue(OldMaterial = nil);
863 finally FreeAndNil(Scene) end;
864 finally
865 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
866 end;
867 end;
868
869 procedure TTestSceneCore.TestUnassociateChangeAppearance;
870 var
871 RootNode: TX3DRootNode;
872 Shape1, Shape2: TShapeNode;
873 OldAppearance: TAppearanceNode;
874 NewAppearance: TAppearanceNode;
875 Scene: TCastleScene;
876 begin
877 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
878 try
879 Scene := TCastleScene.Create(nil);
880 try
881 RootNode := TX3DRootNode.Create;
882
883 OldAppearance := TAppearanceNode.Create;
884 OldAppearance.Material := TMaterialNode.Create;
885
886 NewAppearance := TAppearanceNode.Create;
887 NewAppearance.Material := TMaterialNode.Create;
888
889 Shape1 := TShapeNode.Create;
890 Shape1.Appearance := OldAppearance;
891 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
892 RootNode.AddChildren(Shape1);
893
894 Shape2 := TShapeNode.Create;
895 Shape2.Appearance := OldAppearance;
896 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
897 RootNode.AddChildren(Shape2);
898
899 Scene.Load(RootNode, true);
900 Scene.PreciseCollisions := true;
901 Scene.ProcessEvents := true;
902
903 AssertTrue(OldAppearance.Scene <> nil);
904 AssertTrue(NewAppearance.Scene = nil);
905 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldAppearance));
906 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewAppearance));
907 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldAppearance.Material));
908 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewAppearance.Material));
909
910 Shape1.Appearance := NewAppearance; // but leave Shape2 unchanged
911
912 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldAppearance));
913 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewAppearance));
914 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldAppearance.Material));
915 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewAppearance.Material));
916 finally FreeAndNil(Scene) end;
917 finally
918 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
919 end;
920 end;
921
922 type
923 { Testcase from https://forum.castle-engine.io/t/warning-calling-tglsceneshape-unassociatenode/713 }
924 TMyClass = class(TCastleAbstractPrimitive)
925 private
926 FGeometry: TIndexedTriangleSetNode;
927 FCoordinate: TCoordinateNode;
928 FTextureCoordinate: TTextureCoordinateNode;
929 public
930 constructor Create(AOwner: TComponent); override;
931 end;
932
933 constructor TMyClass.Create(AOwner: TComponent);
934 begin
935 inherited;
936 Texture := 'castle-data:/images/no_alpha.png';
937 Material := pmUnlit;
938 FGeometry := TIndexedTriangleSetNode.Create;
939 FCoordinate := TCoordinateNode.Create;
940 FTextureCoordinate := TTextureCoordinateNode.Create;
941 FGeometry.Coord := FCoordinate;
942 ShapeNode.Geometry := FGeometry;
943 FCoordinate.SetPoint([
944 Vector3(0 , 0, 0),
945 Vector3(100, 0, 0),
946 Vector3(100, 100, 0),
947 Vector3(0 , 100, 0),
948 Vector3(0 , 0, 0),
949 Vector3(100, 100, 0)
950 ]);
951 FTextureCoordinate.SetPoint([
952 Vector2(0, 0),
953 Vector2(1, 0),
954 Vector2(1, 1),
955 Vector2(0, 1),
956 Vector2(0, 0),
957 Vector2(1, 1)
958 ]);
959 FGeometry.SetIndex([0, 1, 2, 3, 4, 5]);
960 FGeometry.TexCoord := FTextureCoordinate;
961 end;
962
963 procedure TTestSceneCore.TestUnassociateAbstractPrimitive;
964 var
965 MyObject: TMyClass;
966 begin
967 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
968 try
969 MyObject := TMyClass.Create(nil);
970 try
971 finally FreeAndNil(MyObject) end;
972 finally
973 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
974 end;
975 end;
976
977 procedure TTestSceneCore.TestUnassociateAbstractPrimitiveSimplified;
978 var
979 Scene: TCastleScene;
980 ShapeNode: TShapeNode;
981 RootNode: TX3DRootNode;
982 Geometry: TIndexedTriangleSetNode;
983 TextureCoordinate: TTextureCoordinateNode;
984 begin
985 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
986 try
987 Scene := TCastleScene.Create(nil);
988 try
989 ShapeNode := TShapeNode.Create;
990 RootNode := TX3DRootNode.Create;
991 RootNode.AddChildren(ShapeNode);
992 Scene.Load(RootNode, true);
993
994 Geometry := TIndexedTriangleSetNode.Create;
995 TextureCoordinate := TTextureCoordinateNode.Create;
996 ShapeNode.Geometry := Geometry;
997 Geometry.TexCoord := TextureCoordinate;
998 finally FreeAndNil(Scene) end
999 finally
1000 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
1001 end;
1002 end;
1003
1004 procedure TTestSceneCore.TestNonGenericNode;
1005 var
1006 Mat: TPhysicalMaterialNode;
1007 Appearance: TAppearanceNode;
1008 Shape: TShapeNode;
1009 Box: TBoxNode;
1010 Switch: TSwitchNode;
1011 RootNode: TX3DRootNode;
1012 Scene: TCastleSceneCore;
1013 begin
1014 Mat := TPhysicalMaterialNode.Create('Foo');
1015 Mat.BaseColor := RedRGB;
1016
1017 Appearance := TAppearanceNode.Create('Foo');
1018 Appearance.Material := Mat;
1019
1020 Box := TBoxNode.CreateWithShape(Shape);
1021 Box.X3DName := 'Foo';
1022 Box.Size := Vector3(1, 2, 3);
1023 Shape.X3DName := 'Foo';
1024 Shape.Appearance := Appearance;
1025
1026 Switch := TSwitchNode.Create;
1027 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1028 Switch.AddChildren(Shape);
1029
1030 RootNode := TX3DRootNode.Create;
1031 RootNode.AddChildren(Switch);
1032
1033 Scene := TCastleSceneCore.Create(nil);
1034 try
1035 Scene.Load(RootNode, true);
1036
1037 AssertTrue(Scene.Node(TX3DNode, 'Foo') <> nil); // undefined which node it will be
1038
1039 AssertTrue((Scene.Node(TPhysicalMaterialNode, 'Foo') as TPhysicalMaterialNode) <> nil);
1040 AssertVectorEquals(RedRGB, (Scene.Node(TPhysicalMaterialNode, 'Foo') as TPhysicalMaterialNode).BaseColor);
1041
1042 AssertTrue((Scene.Node(TBoxNode, 'Foo') as TBoxNode) <> nil);
1043 AssertVectorEquals(Vector3(1, 2, 3), (Scene.Node(TBoxNode, 'Foo') as TBoxNode).Size);
1044 finally FreeAndNil(Scene) end;
1045 end;
1046
1047 {$ifdef GENERIC_METHODS}
1048
1049 procedure TTestSceneCore.TestGenericNode;
1050 var
1051 Mat: TPhysicalMaterialNode;
1052 Appearance: TAppearanceNode;
1053 Shape: TShapeNode;
1054 Box: TBoxNode;
1055 Switch: TSwitchNode;
1056 RootNode: TX3DRootNode;
1057 Scene: TCastleSceneCore;
1058 begin
1059 Mat := TPhysicalMaterialNode.Create('Foo');
1060 Mat.BaseColor := RedRGB;
1061
1062 Appearance := TAppearanceNode.Create('Foo');
1063 Appearance.Material := Mat;
1064
1065 Box := TBoxNode.CreateWithShape(Shape);
1066 Box.X3DName := 'Foo';
1067 Box.Size := Vector3(1, 2, 3);
1068 Shape.X3DName := 'Foo';
1069 Shape.Appearance := Appearance;
1070
1071 Switch := TSwitchNode.Create;
1072 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1073 Switch.AddChildren(Shape);
1074
1075 RootNode := TX3DRootNode.Create;
1076 RootNode.AddChildren(Switch);
1077
1078 Scene := TCastleSceneCore.Create(nil);
1079 try
1080 Scene.Load(RootNode, true);
1081
1082 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TX3DNode>('Foo') <> nil); // undefined which node it will be
1083
1084 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TPhysicalMaterialNode>('Foo') <> nil);
1085 AssertVectorEquals(RedRGB, Scene.{$ifdef FPC}specialize{$endif} Node<TPhysicalMaterialNode>('Foo').BaseColor);
1086
1087 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TBoxNode>('Foo') <> nil);
1088 AssertVectorEquals(Vector3(1, 2, 3), Scene.{$ifdef FPC}specialize{$endif} Node<TBoxNode>('Foo').Size);
1089 finally FreeAndNil(Scene) end;
1090 end;
1091
1092 {$endif GENERIC_METHODS}
1093
1094 procedure TTestSceneCore.TestNonGenericNodeAndFindNodeOptions;
1095 var
1096 Mat: TPhysicalMaterialNode;
1097 Appearance: TAppearanceNode;
1098 Shape: TShapeNode;
1099 Box: TBoxNode;
1100 Switch: TSwitchNode;
1101 RootNode: TX3DRootNode;
1102 Scene: TCastleSceneCore;
1103 begin
1104 Mat := TPhysicalMaterialNode.Create('M');
1105 Mat.BaseColor := RedRGB;
1106
1107 Appearance := TAppearanceNode.Create('A');
1108 Appearance.Material := Mat;
1109
1110 Box := TBoxNode.CreateWithShape(Shape);
1111 Box.X3DName := 'B';
1112 Box.Size := Vector3(1, 2, 3);
1113 Shape.X3DName := 'S';
1114 Shape.Appearance := Appearance;
1115
1116 Switch := TSwitchNode.Create;
1117 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1118 Switch.AddChildren(Shape);
1119
1120 RootNode := TX3DRootNode.Create;
1121 RootNode.AddChildren(Switch);
1122
1123 Scene := TCastleSceneCore.Create(nil);
1124 try
1125 { Test with Scene.RootNode = nil }
1126 AssertTrue(Scene.RootNode = nil);
1127
1128 try
1129 Scene.Node(TX3DNode, 'Foo');
1130 Fail('This should have raised exception');
1131 except on E: EX3DNotFound do { valid response }; end;
1132
1133 AssertTrue(Scene.Node(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1134
1135 { Test with Scene.RootNode <> nil }
1136 Scene.Load(RootNode, true);
1137 AssertTrue(Scene.RootNode <> nil);
1138
1139 try
1140 Scene.Node(TX3DNode, 'Foo');
1141 Fail('This should have raised exception');
1142 except on E: EX3DNotFound do { valid response }; end;
1143
1144 AssertTrue(Scene.Node(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1145
1146 try
1147 Scene.RootNode.FindNode(TX3DNode, 'Foo');
1148 Fail('This should have raised exception');
1149 except on E: EX3DNotFound do { valid response }; end;
1150
1151 AssertTrue(Scene.RootNode.FindNode(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1152
1153 { Test fnOnlyActive: box is only in active subgraph }
1154 try
1155 Scene.RootNode.FindNode(TBoxNode, 'B', [fnOnlyActive]);
1156 Fail('This should have raised exception');
1157 except on E: EX3DNotFound do { valid response }; end;
1158 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', [fnOnlyActive, fnNilOnMissing]) = nil);
1159 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', []) <> nil);
1160 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', [fnNilOnMissing]) <> nil);
1161 finally FreeAndNil(Scene) end;
1162 end;
1163
1164 procedure TTestSceneCore.TestGeometryNodesInShape;
1165 var
1166 Scene: TCastleSceneCore;
1167 begin
1168 Scene := TCastleSceneCore.Create(nil);
1169 try
1170 Scene.Url := 'castle-data:/geometry_not_in_shape.x3dv';
1171 finally FreeAndNil(Scene) end;
1172 end;
1173
1174 procedure TTestSceneCore.TestExposedTransforms;
1175
1176 { See also what testcase from https://github.com/castle-engine/castle-engine/issues/600
1177 is doing. }
1178
1179 var
1180 Scene: TCastleSceneCore;
1181 T1, T2: TCastleTransform;
1182 begin
1183 Scene := TCastleSceneCore.Create(nil);
1184 try
1185 Scene.Load('castle-data:/exposed_transforms_names.x3dv');
1186
1187 T1 := TCastleTransform.Create(nil);
1188 T1.Name := 'MyBoneName_123';
1189 Scene.Add(T1);
1190
1191 T2 := TCastleTransform.Create(nil);
1192 // Pascal component names must match bone names, but with invalid chars -> underscores
1193 T2.Name := 'MyBoneName_with_spaces';
1194 Scene.Add(T2);
1195
1196 AssertEquals(2, Scene.Count);
1197
1198 Scene.ExposeTransforms.AddStrings([
1199 'MyBoneName_123',
1200 // here we provide the bone name, not the Pascal component name, so spaces are OK
1201 'MyBoneName with spaces'
1202 ]);
1203
1204 // Make sure TCastleSceneCore.ExposeTransformsChange didn't create any new components
1205 AssertEquals(2, Scene.Count);
1206 finally
1207 FreeAndNil(Scene);
1208 FreeAndNil(T1);
1209 FreeAndNil(T2);
1210 end;
1211 end;
1212
1213 (* InternalNodesReadOnly no longer available,
1214 it was very cumbersome to implement.
1215 Sharing nodes is just not possible across scenes now.
1216
1217 procedure TTestSceneCore.TestInternalNodesReadOnly;
1218 var
1219 RootNode: TX3DRootNode;
1220 SomeShape: TShapeNode;
1221 SomeGeometry: TSphereNode;
1222 SceneNormal, SceneReadOnly: TCastleSceneCore;
1223 begin
1224 // create simple X3D nodes graph
1225 RootNode := TX3DRootNode.Create;
1226 SomeGeometry := TSphereNode.Create;
1227 SomeShape := TShapeNode.Create;
1228 SomeShape.Geometry := SomeGeometry;
1229 RootNode.AddChildren(SomeShape);
1230
1231 AssertTrue(RootNode.Scene = nil);
1232 AssertTrue(SomeGeometry.Scene = nil);
1233 AssertTrue(SomeShape.Scene = nil);
1234
1235 SceneNormal := TCastleSceneCore.Create(nil);
1236 try
1237 SceneNormal.Load(RootNode, true);
1238 SceneNormal.ProcessEvents := true;
1239
1240 AssertTrue(RootNode.Scene = SceneNormal);
1241 AssertTrue(SomeGeometry.Scene = SceneNormal);
1242 AssertTrue(SomeShape.Scene = SceneNormal);
1243
1244 SceneReadOnly := TCastleSceneCore.Create(nil);
1245 SceneReadOnly.InternalNodesReadOnly := true;
1246 SceneReadOnly.Load(RootNode, true);
1247
1248 // nodes are still associated with SceneNormal, not SceneReadOnly
1249 AssertTrue(RootNode.Scene = SceneNormal);
1250 AssertTrue(SomeGeometry.Scene = SceneNormal);
1251 AssertTrue(SomeShape.Scene = SceneNormal);
1252
1253 FreeAndNil(SceneReadOnly);
1254
1255 // nodes are still associated with SceneNormal, not SceneReadOnly. not nil
1256 AssertTrue(RootNode.Scene = SceneNormal);
1257 AssertTrue(SomeGeometry.Scene = SceneNormal);
1258 AssertTrue(SomeShape.Scene = SceneNormal);
1259 finally
1260 FreeAndNil(SceneNormal);
1261 end;
1262
1263 AssertTrue(RootNode.Scene = nil);
1264 AssertTrue(SomeGeometry.Scene = nil);
1265 AssertTrue(SomeShape.Scene = nil);
1266 end;
1267 *)
1268
1269 initialization
1270 RegisterTest(TTestSceneCore);
1271 end.