Skip to content

URL processing options, useful when saving scene to file#636

Open
janadamec1 wants to merge 37 commits intomasterfrom
url-processing
Open

URL processing options, useful when saving scene to file#636
janadamec1 wants to merge 37 commits intomasterfrom
url-processing

Conversation

@janadamec1
Copy link
Member

This adds ProcessUrls procedure with several options in TUrlProcessing:

  • suChangeCastleDataToRelative: changes castle-data: URLs to relative paths to target scene filename
  • suChangeAllPathsToRelative: changes all paths to relative paths
  • suEmbedResources: stores all resources directly inside the scene
  • suCopyResourcesToSubdirectory: copies resources to "-resources" subdirectory and stores the reference as relative URL

Usage is implemented in CastleEditor, deprecated_library, and url-processing branch in CastleModelViewer/Converter. The check in GUI, the options are exposed as Radio menu items under Save As... command.

@michaliskambi
Copy link
Member

Thank you!

Please add some automatic tests (1. that ProcessUrls works right, 2. that DeepCopy of prototypes works right). Because this is a difficult thing to test, there are various options. Let's use automated testing to help us (and ensure it will keep working forever :) ).

Short primer how to add tests:

You can test running the test suite in "tests/" , see tests/README.md . Short version: compile the project there, and run it :) At the beginning, just run all tests, to make sure it is OK (it should be -- GitHub Actions also check it).

I usually use the "--console" and "--filter xxx" options when developing a new test. So I would add a method like "TestProcessUrls" to TTestX3DNodes (or maybe several methods) and then continue checking

cd tests/
castle-engine compile --mode=debug
./castle-tester --console --filter=TTestX3DNodes.TestProcessUrls

Of course you can compile and run the testsuite as you like, and use GUI or console runner, whatever is comfortable to you.

The tests don't need to be anything complex, it can be as simple as providing some hardcoded input and looking does it match hardcoded output. Like

procedure TTestX3DNodes.TestProcessUrlsEmbed;
begin
  RootNode := TX3DRootNode.Create;
  ...
  ImageTexture.SetUrl('textures/my.png');
  // add ImageTexture to some ShapeNode within RootNode

  TempLocation := GetTempFileName + '.x3d.';
  ProcessUrls(RootNode, TempLocation, suEmbedResources);

  AssertTrue(ImageTexture.Urls.Count = 1);
  AssertTrue(IsSuffix('data:', ImageTexture.Urls[0]));

  finally ... FreeAndNil everyhing :) end;
end;

@michaliskambi
Copy link
Member

Sorry for a delay with this, I have this on a list of TODOs for next week!

I see there are 2 conflicts with this PR, if you want to help me you can solve them. But you can also ignore them, I can do them too next week, look trivial :) Just conflicts around LPK / LPI that we indeed changed in CGE master in the meantime.

@janadamec1
Copy link
Member Author

No problem, I will merge it into master once the library_update PR is merged (working on it now)

@janadamec1 janadamec1 requested a review from michaliskambi March 7, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants