-
Notifications
You must be signed in to change notification settings - Fork 172
Description
Hey @brentyi ! I have a couple small things to bring up for discussion:
1. Nonuniform icosphere scaling
I've been working on a project that involves ellipsoidal geometries, and noticed that the current implementation of icosphere generation does not support nonuniform scaling. I wanted to get your thoughts on an approach to supporting this. Below is the first idea that came to mind, which adds a 3-tuple scale argument to add_icosphere() that is multiplicative with the existing radius parameter.
# _scene_api.py
def add_icosphere(
self,
name: str,
radius: float = 1.0,
color: RgbTupleOrArray = (255, 0, 0),
*,
subdivisions: int = 3,
+ scale: tuple[float, float, float] = (1.0, 1.0, 1.0),
# IcosphereMesh.tsx
+ // Calculate scaling values.
+ const scale = message.props.scale.map((s: number) => s * message.props.radius) as [number, number, number];
return (
<group ref={ref}>
<mesh
geometry={geometry}
- scale={message.props.radius}
+ scale={scale}
2. Transparent mesh depth writing
When playing around with transparent geometries, I ran into some scenarios where parts of a transparent mesh would appear opaque from certain angles (see video below). These visual artifacts were further exaggerated when the scene included multiple overlapping meshes. Observing some other material implementations, I added a flag to toggle depthWrite in the createStandardMaterial function when the mesh is transparent, which seems to have fixed the issue. Let me know if this seems right or if it is misguided.
+const isTransparent = props.opacity !== null && props.opacity < 1.0;
const standardArgs = {
color: props.color === undefined ? 0xffffff : rgbToInt(props.color),
wireframe: props.wireframe,
- transparent: props.opacity !== null,
+ transparent: isTransparent,
opacity: props.opacity ?? 1.0,
+ depthWrite: !isTransparent,mesh-depth-writing.webm
3. Argument order in add_box()
Lastly, I noticed the order of the core args in add_box() does not agree with the other add_{geom}() functions.
def add_box(
self,
name: str,
color: RgbTupleOrArray = (255, 0, 0), # color before dimensions
dimensions: tuple[float, float, float] | np.ndarray = (1.0, 1.0, 1.0),
...
def add_icosphere(
self,
name: str,
radius: float = 1.0,
color: RgbTupleOrArray = (255, 0, 0), # color after dimensions
...Basically, just swapping the order of color and dimensions in add_box(). A bit picky, but worth changing?
I would appreciate your thoughts on these three points. I am planning on opening a PR for nonuniform-icosphere-scaling, which could either encapsulate all of these changes, or only be scoped to 1 with 2 and 3 left as separate fixes.
Thanks!