Debian Codegraph @

tests/code/testcases/testcastlescenecore.pas

raw ◀ ▶
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 {$IFNDEF CPUARMEL}
585 Scene := TCastleScene.Create(nil);
586 try
587 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist');
588 AssertEquals(4, Scene.AnimationsList.Count);
589 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
590 finally FreeAndNil(Scene) end;
591
592 Scene := TCastleScene.Create(nil);
593 try
594 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist#fps:10');
595 AssertEquals(4, Scene.AnimationsList.Count);
596 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
597 finally FreeAndNil(Scene) end;
598
599 Scene := TCastleScene.Create(nil);
600 try
601 LoadSceneRequireWarning(Scene, 'castle-data:/sprite-sheets/cocos2d_wolf/wolf.plist#fps:10,anim-naming:trailing-number');
602 AssertEquals(4, Scene.AnimationsList.Count);
603 AssertTrue(-1 <> Scene.AnimationsList.IndexOf('walk'));
604 finally FreeAndNil(Scene) end;
•605 {$ENDIF CPUARMEL}
606 end;
607
608 procedure TTestSceneCore.TestImageAsNode;
609 var
610 Scene: TCastleScene;
611 begin
612 Scene := TCastleScene.Create(nil);
613 try
614 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.png');
615 AssertEquals(0, Scene.AnimationsList.Count);
616 finally FreeAndNil(Scene) end;
617
618 Scene := TCastleScene.Create(nil);
619 try
620 Scene.Load('castle-data:/sprite-sheets/cocos2d_wolf/wolf.png#left:100,bottom:100,width:256,height:256');
621 AssertEquals(0, Scene.AnimationsList.Count);
622 finally FreeAndNil(Scene) end;
623 end;
624
625 procedure TTestSceneCore.TestPlayStopAnim;
626 var
627 Scene: TCastleScene;
628 begin
629 Scene := TCastleScene.Create(nil);
630 try
631 Scene.ProcessEvents := true;
632 Scene.Load('castle-data:/spine/escape_from_the_universe_boss/boss.json');
633 Scene.Exists := false; // doesn't matter for animation playing
634
635 Scene.PlayAnimation('flying', true);
636 AssertTrue(Scene.CurrentAnimation <> nil);
637 AssertEquals('flying', Scene.CurrentAnimation.X3DName);
638
639 Scene.StopAnimation;
640 AssertTrue(Scene.CurrentAnimation = nil);
641 finally FreeAndNil(Scene) end;
642 end;
643
644 procedure TTestSceneCore.TestFontStyleChanges;
645 var
646 FontStyleNode: TFontStyleNode;
647 TextNode: TTextNode;
648 TextShape: TShapeNode;
649 RootNode: TX3DRootNode;
650 Scene: TCastleScene;
651 Box: TBox3D;
652 begin
653 FontStyleNode := TFontStyleNode.Create;
654
655 TextNode := TTextNode.CreateWithShape(TextShape);
656 TextNode.FontStyle := FontStyleNode;
657 TextNode.SetString(['one line of text']);
658
659 RootNode := TX3DRootNode.Create;
660 RootNode.AddChildren(TextShape);
661
662 Scene := TCastleScene.Create(nil);
663 try
664 // Scene.ProcessEvents := true; // this should work even without process events, TCastleText depends on it
665 Scene.Load(RootNode, true);
666
667 Box := Scene.BoundingBox;
668 //Writeln(Box.ToString);
669 AssertSameValue(1, Box.Size.Y);
670
671 FontStyleNode.Size := 10;
672 Box := Scene.BoundingBox;
673 //Writeln(Box.ToString);
674 AssertSameValue(10, Box.Size.Y);
675
676 FontStyleNode.Size := 100;
677 Box := Scene.BoundingBox;
678 //Writeln(Box.ToString);
679 AssertSameValue(100, Box.Size.Y);
680
681 finally FreeAndNil(Scene) end;
682 end;
683
684 procedure TTestSceneCore.TestUnassociate;
685 var
686 Box: TCastleBox;
687 begin
688 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
689 try
690 Box := TCastleBox.Create(nil);
691 try
692 Box.Material := pmUnlit;
693 Box.Material := pmPhysical;
694 finally FreeAndNil(Box) end;
695 finally
696 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
697 end;
698 end;
699
700 procedure TTestSceneCore.TestUnassociate2;
701 var
702 Shape: TShapeNode;
703 NewMaterial: TMaterialNode;
704 Scene: TCastleScene;
705 begin
706 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
707 try
708 Scene := TCastleScene.Create(nil);
709 try
710 Scene.Load('castle-data:/test_for_material_change.x3dv');
711 Scene.PreciseCollisions := true;
712 Scene.ProcessEvents := true;
713
714 Shape := Scene.Node('MyShape') as TShapeNode;
715
716 NewMaterial := TMaterialNode.Create;
717 NewMaterial.Scene := Scene;
718 NewMaterial.DiffuseColor := Vector3(0, 1, 1);
719 Shape.Material := NewMaterial; // using deprecated Shape.Material, TestUnassociate3 will test undeprecated way
720 finally FreeAndNil(Scene) end;
721 finally
722 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
723 end;
724 end;
725
726 procedure TTestSceneCore.TestUnassociate3;
727 var
728 Shape: TShapeNode;
729 Appearance: TAppearanceNode;
730 NewMaterial: TMaterialNode;
731 Scene: TCastleScene;
732 begin
733 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
734 try
735 Scene := TCastleScene.Create(nil);
736 try
737 Scene.Load('castle-data:/test_for_material_change.x3dv');
738 Scene.PreciseCollisions := true;
739 Scene.ProcessEvents := true;
740
741 Shape := Scene.Node('MyShape') as TShapeNode;
742
743 NewMaterial := TMaterialNode.Create;
744 NewMaterial.Scene := Scene;
745 NewMaterial.DiffuseColor := Vector3(0, 1, 1);
746
747 Appearance := TAppearanceNode.Create;
748 Appearance.Material := NewMaterial;
749
750 Shape.Appearance := Appearance;
751 finally FreeAndNil(Scene) end;
752 finally
753 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
754 end;
755 end;
756
757 procedure TTestSceneCore.TestUnassociateChangeMaterialOneLeft;
758 var
759 RootNode: TX3DRootNode;
760 Shape1, Shape2: TShapeNode;
761 OldMaterial: TMaterialNode;
762 NewMaterial: TUnlitMaterialNode;
763 Scene: TCastleScene;
764 begin
765 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
766 try
767 Scene := TCastleScene.Create(nil);
768 try
769 RootNode := TX3DRootNode.Create;
770
771 OldMaterial := TMaterialNode.Create;
772
773 Shape1 := TShapeNode.Create;
774 Shape1.Material := OldMaterial; // will also auto-create Shape.Appearance, OK
775 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
776 RootNode.AddChildren(Shape1);
777
778 Shape2 := TShapeNode.Create;
779 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
780 Shape2.Material := OldMaterial; // will also auto-create Shape.Appearance, OK
781 RootNode.AddChildren(Shape2);
782
783 Scene.Load(RootNode, true);
784 Scene.PreciseCollisions := true;
785 Scene.ProcessEvents := true;
786
787 NewMaterial := TUnlitMaterialNode.Create;
788
789 AssertTrue(OldMaterial.Scene <> nil);
790 AssertTrue(NewMaterial.Scene = nil);
791 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldMaterial));
792 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewMaterial));
793 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape1.Appearance));
794 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape2.Appearance));
795
796 // NewMaterial.Scene := Scene; // should work with and without this
797 Shape1.Material := NewMaterial; // but leave Shape2 unchanged
798
799 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldMaterial));
800 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewMaterial));
801 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape1.Appearance));
802 AssertEquals(1, TShapeTree.AssociatedShapesCount(Shape2.Appearance));
803 finally FreeAndNil(Scene) end;
804 finally
805 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
806 end;
807 end;
808
809 procedure TTestSceneCore.TestUnassociateChangeMaterialSharedAppearance;
810 var
811 RootNode: TX3DRootNode;
812 Shape1, Shape2: TShapeNode;
813 OldMaterial: TMaterialNode;
814 NewMaterial: TUnlitMaterialNode;
815 SharedAppearance: TAppearanceNode;
816 Scene: TCastleScene;
817 begin
818 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
819 try
820 Scene := TCastleScene.Create(nil);
821 try
822 RootNode := TX3DRootNode.Create;
823
824 OldMaterial := TMaterialNode.Create;
825 OldMaterial.KeepExistingBegin; // otherwise it would be destroyed by assigning other node
826
827 SharedAppearance := TAppearanceNode.Create;
828 SharedAppearance.Material := OldMaterial;
829
830 Shape1 := TShapeNode.Create;
831 Shape1.Appearance := SharedAppearance;
832 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
833 RootNode.AddChildren(Shape1);
834
835 Shape2 := TShapeNode.Create;
836 Shape2.Appearance := SharedAppearance;
837 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
838 RootNode.AddChildren(Shape2);
839
840 Scene.Load(RootNode, true);
841 Scene.PreciseCollisions := true;
842 Scene.ProcessEvents := true;
843
844 NewMaterial := TUnlitMaterialNode.Create;
845
846 AssertTrue(SharedAppearance.Scene <> nil);
847 AssertTrue(OldMaterial.Scene <> nil);
848 AssertTrue(NewMaterial.Scene = nil);
849 AssertEquals(2, TShapeTree.AssociatedShapesCount(SharedAppearance));
850 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldMaterial));
851 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewMaterial));
852
853 // NewMaterial.Scene := Scene; // should work with and without this
854 Shape1.Material := NewMaterial; // equivalent to SharedAppearance.Material := NewMaterial;
855 //SharedAppearance.Material := NewMaterial;
856
857 AssertEquals(2, TShapeTree.AssociatedShapesCount(SharedAppearance));
858 AssertEquals(0, TShapeTree.AssociatedShapesCount(OldMaterial));
859 AssertEquals(2, TShapeTree.AssociatedShapesCount(NewMaterial));
860
861 // OldMaterial now unused
862 OldMaterial.KeepExistingEnd;
863 FreeIfUnusedAndNil(OldMaterial);
864 AssertTrue(OldMaterial = nil);
865 finally FreeAndNil(Scene) end;
866 finally
867 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
868 end;
869 end;
870
871 procedure TTestSceneCore.TestUnassociateChangeAppearance;
872 var
873 RootNode: TX3DRootNode;
874 Shape1, Shape2: TShapeNode;
875 OldAppearance: TAppearanceNode;
876 NewAppearance: TAppearanceNode;
877 Scene: TCastleScene;
878 begin
879 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
880 try
881 Scene := TCastleScene.Create(nil);
882 try
883 RootNode := TX3DRootNode.Create;
884
885 OldAppearance := TAppearanceNode.Create;
886 OldAppearance.Material := TMaterialNode.Create;
887
888 NewAppearance := TAppearanceNode.Create;
889 NewAppearance.Material := TMaterialNode.Create;
890
891 Shape1 := TShapeNode.Create;
892 Shape1.Appearance := OldAppearance;
893 Shape1.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
894 RootNode.AddChildren(Shape1);
895
896 Shape2 := TShapeNode.Create;
897 Shape2.Appearance := OldAppearance;
898 Shape2.Geometry := TBoxNode.Create; // anything non-nil, otherwise it's ignored in Scene.Shapes tree
899 RootNode.AddChildren(Shape2);
900
901 Scene.Load(RootNode, true);
902 Scene.PreciseCollisions := true;
903 Scene.ProcessEvents := true;
904
905 AssertTrue(OldAppearance.Scene <> nil);
906 AssertTrue(NewAppearance.Scene = nil);
907 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldAppearance));
908 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewAppearance));
909 AssertEquals(2, TShapeTree.AssociatedShapesCount(OldAppearance.Material));
910 AssertEquals(0, TShapeTree.AssociatedShapesCount(NewAppearance.Material));
911
912 Shape1.Appearance := NewAppearance; // but leave Shape2 unchanged
913
914 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldAppearance));
915 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewAppearance));
916 AssertEquals(1, TShapeTree.AssociatedShapesCount(OldAppearance.Material));
917 AssertEquals(1, TShapeTree.AssociatedShapesCount(NewAppearance.Material));
918 finally FreeAndNil(Scene) end;
919 finally
920 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
921 end;
922 end;
923
924 type
925 { Testcase from https://forum.castle-engine.io/t/warning-calling-tglsceneshape-unassociatenode/713 }
926 TMyClass = class(TCastleAbstractPrimitive)
927 private
928 FGeometry: TIndexedTriangleSetNode;
929 FCoordinate: TCoordinateNode;
930 FTextureCoordinate: TTextureCoordinateNode;
931 public
932 constructor Create(AOwner: TComponent); override;
933 end;
934
935 constructor TMyClass.Create(AOwner: TComponent);
936 begin
937 inherited;
938 Texture := 'castle-data:/images/no_alpha.png';
939 Material := pmUnlit;
940 FGeometry := TIndexedTriangleSetNode.Create;
941 FCoordinate := TCoordinateNode.Create;
942 FTextureCoordinate := TTextureCoordinateNode.Create;
943 FGeometry.Coord := FCoordinate;
944 ShapeNode.Geometry := FGeometry;
945 FCoordinate.SetPoint([
946 Vector3(0 , 0, 0),
947 Vector3(100, 0, 0),
948 Vector3(100, 100, 0),
949 Vector3(0 , 100, 0),
950 Vector3(0 , 0, 0),
951 Vector3(100, 100, 0)
952 ]);
953 FTextureCoordinate.SetPoint([
954 Vector2(0, 0),
955 Vector2(1, 0),
956 Vector2(1, 1),
957 Vector2(0, 1),
958 Vector2(0, 0),
959 Vector2(1, 1)
960 ]);
961 FGeometry.SetIndex([0, 1, 2, 3, 4, 5]);
962 FGeometry.TexCoord := FTextureCoordinate;
963 end;
964
965 procedure TTestSceneCore.TestUnassociateAbstractPrimitive;
966 var
967 MyObject: TMyClass;
968 begin
969 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
970 try
971 MyObject := TMyClass.Create(nil);
972 try
973 finally FreeAndNil(MyObject) end;
974 finally
975 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
976 end;
977 end;
978
979 procedure TTestSceneCore.TestUnassociateAbstractPrimitiveSimplified;
980 var
981 Scene: TCastleScene;
982 ShapeNode: TShapeNode;
983 RootNode: TX3DRootNode;
984 Geometry: TIndexedTriangleSetNode;
985 TextureCoordinate: TTextureCoordinateNode;
986 begin
987 ApplicationProperties.OnWarning.Add({$ifdef FPC}@{$endif}OnWarningRaiseException);
988 try
989 Scene := TCastleScene.Create(nil);
990 try
991 ShapeNode := TShapeNode.Create;
992 RootNode := TX3DRootNode.Create;
993 RootNode.AddChildren(ShapeNode);
994 Scene.Load(RootNode, true);
995
996 Geometry := TIndexedTriangleSetNode.Create;
997 TextureCoordinate := TTextureCoordinateNode.Create;
998 ShapeNode.Geometry := Geometry;
999 Geometry.TexCoord := TextureCoordinate;
1000 finally FreeAndNil(Scene) end
1001 finally
1002 ApplicationProperties.OnWarning.Remove({$ifdef FPC}@{$endif}OnWarningRaiseException);
1003 end;
1004 end;
1005
1006 procedure TTestSceneCore.TestNonGenericNode;
1007 var
1008 Mat: TPhysicalMaterialNode;
1009 Appearance: TAppearanceNode;
1010 Shape: TShapeNode;
1011 Box: TBoxNode;
1012 Switch: TSwitchNode;
1013 RootNode: TX3DRootNode;
1014 Scene: TCastleSceneCore;
1015 begin
1016 Mat := TPhysicalMaterialNode.Create('Foo');
1017 Mat.BaseColor := RedRGB;
1018
1019 Appearance := TAppearanceNode.Create('Foo');
1020 Appearance.Material := Mat;
1021
1022 Box := TBoxNode.CreateWithShape(Shape);
1023 Box.X3DName := 'Foo';
1024 Box.Size := Vector3(1, 2, 3);
1025 Shape.X3DName := 'Foo';
1026 Shape.Appearance := Appearance;
1027
1028 Switch := TSwitchNode.Create;
1029 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1030 Switch.AddChildren(Shape);
1031
1032 RootNode := TX3DRootNode.Create;
1033 RootNode.AddChildren(Switch);
1034
1035 Scene := TCastleSceneCore.Create(nil);
1036 try
1037 Scene.Load(RootNode, true);
1038
1039 AssertTrue(Scene.Node(TX3DNode, 'Foo') <> nil); // undefined which node it will be
1040
1041 AssertTrue((Scene.Node(TPhysicalMaterialNode, 'Foo') as TPhysicalMaterialNode) <> nil);
1042 AssertVectorEquals(RedRGB, (Scene.Node(TPhysicalMaterialNode, 'Foo') as TPhysicalMaterialNode).BaseColor);
1043
1044 AssertTrue((Scene.Node(TBoxNode, 'Foo') as TBoxNode) <> nil);
1045 AssertVectorEquals(Vector3(1, 2, 3), (Scene.Node(TBoxNode, 'Foo') as TBoxNode).Size);
1046 finally FreeAndNil(Scene) end;
1047 end;
1048
1049 {$ifdef GENERIC_METHODS}
1050
1051 procedure TTestSceneCore.TestGenericNode;
1052 var
1053 Mat: TPhysicalMaterialNode;
1054 Appearance: TAppearanceNode;
1055 Shape: TShapeNode;
1056 Box: TBoxNode;
1057 Switch: TSwitchNode;
1058 RootNode: TX3DRootNode;
1059 Scene: TCastleSceneCore;
1060 begin
1061 Mat := TPhysicalMaterialNode.Create('Foo');
1062 Mat.BaseColor := RedRGB;
1063
1064 Appearance := TAppearanceNode.Create('Foo');
1065 Appearance.Material := Mat;
1066
1067 Box := TBoxNode.CreateWithShape(Shape);
1068 Box.X3DName := 'Foo';
1069 Box.Size := Vector3(1, 2, 3);
1070 Shape.X3DName := 'Foo';
1071 Shape.Appearance := Appearance;
1072
1073 Switch := TSwitchNode.Create;
1074 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1075 Switch.AddChildren(Shape);
1076
1077 RootNode := TX3DRootNode.Create;
1078 RootNode.AddChildren(Switch);
1079
1080 Scene := TCastleSceneCore.Create(nil);
1081 try
1082 Scene.Load(RootNode, true);
1083
1084 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TX3DNode>('Foo') <> nil); // undefined which node it will be
1085
1086 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TPhysicalMaterialNode>('Foo') <> nil);
1087 AssertVectorEquals(RedRGB, Scene.{$ifdef FPC}specialize{$endif} Node<TPhysicalMaterialNode>('Foo').BaseColor);
1088
1089 AssertTrue(Scene.{$ifdef FPC}specialize{$endif} Node<TBoxNode>('Foo') <> nil);
1090 AssertVectorEquals(Vector3(1, 2, 3), Scene.{$ifdef FPC}specialize{$endif} Node<TBoxNode>('Foo').Size);
1091 finally FreeAndNil(Scene) end;
1092 end;
1093
1094 {$endif GENERIC_METHODS}
1095
1096 procedure TTestSceneCore.TestNonGenericNodeAndFindNodeOptions;
1097 var
1098 Mat: TPhysicalMaterialNode;
1099 Appearance: TAppearanceNode;
1100 Shape: TShapeNode;
1101 Box: TBoxNode;
1102 Switch: TSwitchNode;
1103 RootNode: TX3DRootNode;
1104 Scene: TCastleSceneCore;
1105 begin
1106 Mat := TPhysicalMaterialNode.Create('M');
1107 Mat.BaseColor := RedRGB;
1108
1109 Appearance := TAppearanceNode.Create('A');
1110 Appearance.Material := Mat;
1111
1112 Box := TBoxNode.CreateWithShape(Shape);
1113 Box.X3DName := 'B';
1114 Box.Size := Vector3(1, 2, 3);
1115 Shape.X3DName := 'S';
1116 Shape.Appearance := Appearance;
1117
1118 Switch := TSwitchNode.Create;
1119 Switch.WhichChoice := -1; // Shape is inactive, but it doesn't matter for Find
1120 Switch.AddChildren(Shape);
1121
1122 RootNode := TX3DRootNode.Create;
1123 RootNode.AddChildren(Switch);
1124
1125 Scene := TCastleSceneCore.Create(nil);
1126 try
1127 { Test with Scene.RootNode = nil }
1128 AssertTrue(Scene.RootNode = nil);
1129
1130 try
1131 Scene.Node(TX3DNode, 'Foo');
1132 Fail('This should have raised exception');
1133 except on E: EX3DNotFound do { valid response }; end;
1134
1135 AssertTrue(Scene.Node(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1136
1137 { Test with Scene.RootNode <> nil }
1138 Scene.Load(RootNode, true);
1139 AssertTrue(Scene.RootNode <> nil);
1140
1141 try
1142 Scene.Node(TX3DNode, 'Foo');
1143 Fail('This should have raised exception');
1144 except on E: EX3DNotFound do { valid response }; end;
1145
1146 AssertTrue(Scene.Node(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1147
1148 try
1149 Scene.RootNode.FindNode(TX3DNode, 'Foo');
1150 Fail('This should have raised exception');
1151 except on E: EX3DNotFound do { valid response }; end;
1152
1153 AssertTrue(Scene.RootNode.FindNode(TX3DNode, 'Foo', [fnNilOnMissing]) = nil);
1154
1155 { Test fnOnlyActive: box is only in active subgraph }
1156 try
1157 Scene.RootNode.FindNode(TBoxNode, 'B', [fnOnlyActive]);
1158 Fail('This should have raised exception');
1159 except on E: EX3DNotFound do { valid response }; end;
1160 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', [fnOnlyActive, fnNilOnMissing]) = nil);
1161 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', []) <> nil);
1162 AssertTrue(Scene.RootNode.FindNode(TBoxNode, 'B', [fnNilOnMissing]) <> nil);
1163 finally FreeAndNil(Scene) end;
1164 end;
1165
1166 procedure TTestSceneCore.TestGeometryNodesInShape;
1167 var
1168 Scene: TCastleSceneCore;
1169 begin
1170 Scene := TCastleSceneCore.Create(nil);
1171 try
1172 Scene.Url := 'castle-data:/geometry_not_in_shape.x3dv';
1173 finally FreeAndNil(Scene) end;
1174 end;
1175
1176 procedure TTestSceneCore.TestExposedTransforms;
1177
1178 { See also what testcase from https://github.com/castle-engine/castle-engine/issues/600
1179 is doing. }
1180
1181 var
1182 Scene: TCastleSceneCore;
1183 T1, T2: TCastleTransform;
1184 begin
1185 Scene := TCastleSceneCore.Create(nil);
1186 try
1187 Scene.Load('castle-data:/exposed_transforms_names.x3dv');
1188
1189 T1 := TCastleTransform.Create(nil);
1190 T1.Name := 'MyBoneName_123';
1191 Scene.Add(T1);
1192
1193 T2 := TCastleTransform.Create(nil);
1194 // Pascal component names must match bone names, but with invalid chars -> underscores
1195 T2.Name := 'MyBoneName_with_spaces';
1196 Scene.Add(T2);
1197
1198 AssertEquals(2, Scene.Count);
1199
1200 Scene.ExposeTransforms.AddStrings([
1201 'MyBoneName_123',
1202 // here we provide the bone name, not the Pascal component name, so spaces are OK
1203 'MyBoneName with spaces'
1204 ]);
1205
1206 // Make sure TCastleSceneCore.ExposeTransformsChange didn't create any new components
1207 AssertEquals(2, Scene.Count);
1208 finally
1209 FreeAndNil(Scene);
1210 FreeAndNil(T1);
1211 FreeAndNil(T2);
1212 end;
1213 end;
1214
1215 (* InternalNodesReadOnly no longer available,
1216 it was very cumbersome to implement.
1217 Sharing nodes is just not possible across scenes now.
1218
1219 procedure TTestSceneCore.TestInternalNodesReadOnly;
1220 var
1221 RootNode: TX3DRootNode;
1222 SomeShape: TShapeNode;
1223 SomeGeometry: TSphereNode;
1224 SceneNormal, SceneReadOnly: TCastleSceneCore;
1225 begin
1226 // create simple X3D nodes graph
1227 RootNode := TX3DRootNode.Create;
1228 SomeGeometry := TSphereNode.Create;
1229 SomeShape := TShapeNode.Create;
1230 SomeShape.Geometry := SomeGeometry;
1231 RootNode.AddChildren(SomeShape);
1232
1233 AssertTrue(RootNode.Scene = nil);
1234 AssertTrue(SomeGeometry.Scene = nil);
1235 AssertTrue(SomeShape.Scene = nil);
1236
1237 SceneNormal := TCastleSceneCore.Create(nil);
1238 try
1239 SceneNormal.Load(RootNode, true);
1240 SceneNormal.ProcessEvents := true;
1241
1242 AssertTrue(RootNode.Scene = SceneNormal);
1243 AssertTrue(SomeGeometry.Scene = SceneNormal);
1244 AssertTrue(SomeShape.Scene = SceneNormal);
1245
1246 SceneReadOnly := TCastleSceneCore.Create(nil);
1247 SceneReadOnly.InternalNodesReadOnly := true;
1248 SceneReadOnly.Load(RootNode, true);
1249
1250 // nodes are still associated with SceneNormal, not SceneReadOnly
1251 AssertTrue(RootNode.Scene = SceneNormal);
1252 AssertTrue(SomeGeometry.Scene = SceneNormal);
1253 AssertTrue(SomeShape.Scene = SceneNormal);
1254
1255 FreeAndNil(SceneReadOnly);
1256
1257 // nodes are still associated with SceneNormal, not SceneReadOnly. not nil
1258 AssertTrue(RootNode.Scene = SceneNormal);
1259 AssertTrue(SomeGeometry.Scene = SceneNormal);
1260 AssertTrue(SomeShape.Scene = SceneNormal);
1261 finally
1262 FreeAndNil(SceneNormal);
1263 end;
1264
1265 AssertTrue(RootNode.Scene = nil);
1266 AssertTrue(SomeGeometry.Scene = nil);
1267 AssertTrue(SomeShape.Scene = nil);
1268 end;
1269 *)
1270
1271 initialization
1272 RegisterTest(TTestSceneCore);
1273 end.