-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New mobject: ImplicitSurface for implicit 3D surface rendering #4429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
OeGiaretta
wants to merge
12
commits into
ManimCommunity:main
Choose a base branch
from
OeGiaretta:feature/implicit-surface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca3f6aa
Example codes
OeGiaretta 9eb1ea5
.
OeGiaretta e2d6a72
Ajustes e testes.
OeGiaretta 19cfe31
Adjustment, testing, and implementation of the Implicit_Surface.
OeGiaretta a0984bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dd6f564
Add scikit-image as dependency for ImplicitSurface
OeGiaretta 8601a2b
Merge branch 'feature/implicit-surface' of https://github.com/OeGiare…
OeGiaretta f5baaed
Add ImplicitSurface Mobject and fix typing issues
OeGiaretta dba6e83
fix(docs): ensure alias_container is always initialized in
OeGiaretta 3d1a999
Delete docs/source/conduct.md
OeGiaretta 8f89152
Update file_ops.py
OeGiaretta 6ead5b1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from __future__ import annotations | ||
|
||
import numpy as np | ||
from skimage import measure | ||
|
||
from manim import * | ||
Check noticeCode scanning / CodeQL 'import *' may pollute namespace Note
Import pollutes the enclosing namespace, as the imported module
manim Error loading related location Loading |
||
|
||
|
||
class ImplicitSurface(ThreeDVMobject): | ||
"""Renderiza uma isosuperfície implícita usando Marching Cubes. | ||
|
||
Parameters | ||
---------- | ||
func : Callable[[float, float, float], float] | ||
Função implícita f(x,y,z). A superfície é definida onde f(x,y,z) = isolevel. | ||
resolution : int, default=25 | ||
Número de divisões por eixo. | ||
isolevel : float, default=0.0 | ||
Nível da isosuperfície. | ||
x_range, y_range, z_range : list[float], default=[-2, 2] | ||
Intervalos de amostragem. | ||
color : Color, default=BLUE | ||
Cor da superfície. | ||
**kwargs | ||
Argumentos adicionais para ThreeDVMobject. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
func, | ||
resolution=25, | ||
isolevel=0.0, | ||
x_range=[-2, 2], | ||
y_range=[-2, 2], | ||
z_range=[-2, 2], | ||
color=BLUE, | ||
**kwargs, | ||
): | ||
super().__init__(**kwargs) | ||
|
||
# Gera a grade 3D: | ||
x = np.linspace(x_range[0], x_range[1], resolution) | ||
y = np.linspace(y_range[0], y_range[1], resolution) | ||
z = np.linspace(z_range[0], z_range[1], resolution) | ||
X, Y, Z = np.meshgrid(x, y, z, indexing="ij") | ||
values = func(X, Y, Z) | ||
|
||
# Extrai a malha: | ||
verts, faces, _, _ = measure.marching_cubes(values, level=isolevel) | ||
|
||
# Normaliza para o domínio real: | ||
scale_x = (x_range[1] - x_range[0]) / resolution | ||
scale_y = (y_range[1] - y_range[0]) / resolution | ||
scale_z = (z_range[1] - z_range[0]) / resolution | ||
verts = np.array( | ||
[ | ||
[ | ||
x_range[0] + v[0] * scale_x, | ||
y_range[0] + v[1] * scale_y, | ||
z_range[0] + v[2] * scale_z, | ||
] | ||
for v in verts | ||
] | ||
) | ||
|
||
# Constrói os polígonos: | ||
for face in faces: | ||
tri = [verts[i] for i in face] | ||
self.add(Polygon(*tri, color=color, fill_opacity=1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from manim import * | ||
from manim.mobject.three_d.implicit_surface import ImplicitSurface | ||
|
||
|
||
class TestSurfaceScene(ThreeDScene): | ||
def construct(self): | ||
self.set_camera_orientation(phi=70 * DEGREES, theta=45 * DEGREES) | ||
surface = ImplicitSurface( | ||
lambda x, y, z, r=0.7: x**2 + y**2 - r**2, resolution=20, color=WHITE | ||
) | ||
self.add(surface) | ||
self.wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from manim import * | ||
from manim.mobject.three_d.implicit_surface import ImplicitSurface | ||
|
||
|
||
class TestSurface360(ThreeDScene): | ||
def construct(self): | ||
self.set_camera_orientation(phi=70 * DEGREES, theta=0) | ||
|
||
surface = ImplicitSurface( | ||
lambda x, y, z: x**2 + y**2 + z**2 - 1, resolution=20, color=BLUE | ||
) | ||
self.add(surface) | ||
|
||
self.begin_ambient_camera_rotation(rate=PI / 4) | ||
self.wait(8) | ||
self.stop_ambient_camera_rotation() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.