Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ let package = Package(
// @UntoldMenu, reflection, scene storage and the per-frame system. Platform neutral.
.library(name: "UntoldComponentKit", targets: ["UntoldComponentKit"]),

// Cook-time mesh work: the automatic LOD chains of cooked models. For tools
// that cook assets (the CLI, an editor), not for the apps that load them.
.library(name: "UntoldEngineMeshCook", targets: ["UntoldEngineMeshCook"]),

// NOTE: Demo executables are intentionally NOT declared as products so they
// stay hidden from consumers of the package. SwiftPM creates implicit
// products for executable targets in the root package, so they remain
Expand All @@ -88,6 +92,14 @@ let package = Package(
.headerSearchPath("include"),
]
),
// meshoptimizer (MIT), unmodified: the mesh simplifier behind the cook's automatic
// LOD chains. UntoldEngineMeshCook calls it from Swift through its C API.
.target(
name: "CMeshOptimizer",
path: "Sources/CMeshOptimizer",
exclude: ["LICENSE.md", "README.md"],
publicHeadersPath: "include"
),
.target(
name: "UntoldEngine",
dependencies: ["CShaderTypes"],
Expand Down Expand Up @@ -121,6 +133,17 @@ let package = Package(
]
),

// The cook's mesh work. A module of its own so that UntoldEngine does not import
// CMeshOptimizer: whatever compiles against a built UntoldEngine module without
// SwiftPM (the editor compiles a project's components that way) would otherwise
// need the module map of that C++ library as well.
.target(
name: "UntoldEngineMeshCook",
dependencies: ["UntoldEngine", "CMeshOptimizer"],
path: "Sources/UntoldEngineMeshCook",
swiftSettings: [.swiftLanguageMode(.v6)]
),

// Vision OS target
.target(
name: "UntoldEngineXR",
Expand Down Expand Up @@ -273,14 +296,14 @@ let package = Package(
),
.testTarget(
name: "UntoldEngineTests",
dependencies: ["UntoldEngine", "UntoldEngineShaderSupport"],
dependencies: ["UntoldEngine", "UntoldEngineMeshCook", "UntoldEngineShaderSupport"],
path: "Tests/UntoldEngineTests",
swiftSettings: [.swiftLanguageMode(.v6)]
),
// Render-specific test target
.testTarget(
name: "UntoldEngineRenderTests",
dependencies: ["UntoldEngine"],
dependencies: ["UntoldEngine", "UntoldEngineMeshCook"],
path: "Tests/UntoldEngineRenderTests",
exclude: ["Resources/compare_psnr.py"],
resources: [
Expand Down
21 changes: 21 additions & 0 deletions Sources/CMeshOptimizer/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016-2026 Arseny Kapoulkine

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions Sources/CMeshOptimizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CMeshOptimizer

Part of [meshoptimizer](https://github.com/zeux/meshoptimizer) 1.3 (tag `v1.3`), by Arseny Kapoulkine, under the MIT License (see `LICENSE.md`). The files are unmodified copies:

- `include/meshoptimizer.h` is `src/meshoptimizer.h`.
- The `.cpp` files are those of `src/` that the engine uses: the simplifier, the index generator, the vertex cache and vertex fetch optimizers, and the allocator they share. The header declares the whole library; a function of a file that is not here does not link.

The `UntoldEngineMeshCook` module calls the C API from Swift (`import CMeshOptimizer`); no C++ interoperability is needed. It is used by the asset cook, not by the renderer: `UntoldMeshLODCooker` builds the automatic LOD chain of a cooked model with the simplifier.

Only `UntoldEngineMeshCook` imports this module. `UntoldEngine` must not: code that is compiled against a built `UntoldEngine` module without SwiftPM (the editor compiles a project's components that way) would then need this library's module map too, and fail with "missing required module 'CMeshOptimizer'".

## Updating

Replace the files with those of the new tag and update the version above. Add a file of `src/` when the engine starts to use it. Do not edit the files here: local changes would be lost on the next update.
21 changes: 21 additions & 0 deletions Sources/CMeshOptimizer/allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This file is part of meshoptimizer library; see meshoptimizer.h for version/license details
#include "meshoptimizer.h"

#include <assert.h>

#ifdef MESHOPTIMIZER_ALLOC_EXPORT
meshopt_Allocator::Storage& meshopt_Allocator::storage()
{
static Storage s = {::operator new, ::operator delete };
return s;
}
#endif

void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*))
{
assert(allocate && deallocate);

meshopt_Allocator::Storage& s = meshopt_Allocator::storage();
s.allocate = allocate;
s.deallocate = deallocate;
}
Loading
Loading