alex566/Creamy3D
Integrate 3D objects effortlessly into SwiftUI
π Intro
Creamy 3D is a library that allows seamless integration of simple 3D objects into your SwiftUI projects. Spice up your app's UI with interactive icons and 3D visuals. Its material system draws inspiration from Spline.design.
π₯οΈ Code Example
CreamyView {
Mesh(source: .stl("order")) {
MatcapMaterial(name: "matcap")
}
.resizable()
.scaledToFit()
}π Video example
[ezgif com-video-to-gif]
π οΈ How to Use
To infuse a model into your scene, simply start with CreamyView. This view adopts the size of its parent container and expects a model builder as an input argument. With a design principle that mirrors SwiftUI's Image modifiers, interacting with your model feels natural and intuitive. For instance, the .resizable() modifier scales your model to occupy the entire container space.
π Technical Details
- File Support: Currently, only the STL and OBJ file formats are supported.
- Camera Details: An orthographic camera is calibrated to the view size and coordinated like its SwiftUI counterpart.
- Mesh Information: The library leans on ModelIO for both model loading and generation.
- Rendering: Rendering is based on Metal with MetalKit.
π Planned features
The material system is inspired by spline.design, so the goal is to make any visual appearance reproducible by the library.
| Materials | Status | Comment | |------------|-------------------|----------------------------------------------------------------------------| | Color | β
done | | | Matcap | β
done | | | Fresnel | π‘ partially done | Factor is missing. The result doesn't match precisely with spline.design | | Texture | π‘ partially done | Currently only samples based on UV | | Light | β in progress | | | Normal | todo | | | Depth | todo | | | Gradient | todo | | | Noise | todo | | | Rainbow | todo | | | Outline | todo | | | Glass | todo | | | Pattern | todo | |
The library provides some basic primitive shapes, but making the shape generation more advanced is not planned so far. The main focus will be on rendering models from files.
| Meshes | Status | |------------|-------------------| | Sphere | β done | | Cube | β done | | Model | π‘ partially done | | Plane | todo | | Cylinder | todo | | Cone | todo | | ... | todo |
The most common post-processing effects are planned. The list is not full yet.
| Post processing | Status | |-----------------|--------------| | Bloom | todo | | Aberration | todo | | ... | todo |
π§ Plans for v0.3 - Provide convenient way to combine materials
- [ ] ~Scene background customization.~ (Just use
.backgroundof the View) - [X] Modifiers:
offset,rotation. - [X] Modifiers:
frameandpadding. - [X] Materials composition
- [X] Add materials:
fresnel,texture - [X] Blend modes:
multiply,screen,overlay - [ ] Add
lightmaterial - [ ] Animations support out of the box (Currently supported using Animatable modifier on the parent View)
- [ ] Multiple Meshes support
- [ ] Bloom effect support
π§ Plans for v0.4 - Rework objects management
- [ ] Split Mesh into separate types, like "Sphere(), Cube(), Model()"
- [ ] Add ability to apply separate materials to submeshes
- [ ] Add Scene type which can handle adding USD
CreamyView {
Scene(name: "my_scene.usdz") {
Object(name: "my object") { // Define materials for the object named "my object"
ColorMaterial(color: .white)
LightMaterial(type: .physical) {
DirectionalLight(direction: .init(x: 1.0, y: 1.0, z: 0.0))
}
}
}
}π§ Plans for v0.5 - Advanced animations
- [ ] Material transition animations
π€ Features under Consideration
- Clonner, which repeats Meshes. Example:
Clonner(.grid(.init(x: 10, y: 10, z: 10)), spacing: 16.0) {
Mesh(source: .sphere)
.resizable()
.frame(width: 50.0, height: 50.0)
}- Animated material transitions. The interface is under consideration. One option is:
Mesh(source: .sphere) {
Transition(.fade, value: isSwitched) { value in
if value {
ColorMaterial(color: .red)
} else {
ColorMaterial(black: .black)
}
}
}Package Metadata
Repository: alex566/Creamy3D
Stars: 39
Forks: 1
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: 3d, swiftui
README: README.md