Skip to content

Commit 53a7b32

Browse files
authored
fix: clouds rename conficting attribute (#2080)
1 parent 7974930 commit 53a7b32

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/core/Cloud.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ export const Clouds = /* @__PURE__ */ React.forwardRef<Group, CloudsProps>(
112112
const opaque_fragment = parseInt(REVISION.replace(/\D+/g, '')) >= 154 ? 'opaque_fragment' : 'output_fragment'
113113
this.onBeforeCompile = (shader) => {
114114
shader.vertexShader =
115-
`attribute float opacity;
115+
`attribute float cloudOpacity;
116116
varying float vOpacity;
117117
` +
118118
shader.vertexShader.replace(
119119
'#include <fog_vertex>',
120120
`#include <fog_vertex>
121-
vOpacity = opacity;
121+
vOpacity = cloudOpacity;
122122
`
123123
)
124124
shader.fragmentShader =
@@ -175,7 +175,7 @@ export const Clouds = /* @__PURE__ */ React.forwardRef<Group, CloudsProps>(
175175
}
176176

177177
// Update instance
178-
instance.current.geometry.attributes.opacity.needsUpdate = true
178+
instance.current.geometry.attributes.cloudOpacity.needsUpdate = true
179179
instance.current.instanceMatrix.needsUpdate = true
180180
if (instance.current.instanceColor) instance.current.instanceColor.needsUpdate = true
181181
})
@@ -187,11 +187,11 @@ export const Clouds = /* @__PURE__ */ React.forwardRef<Group, CloudsProps>(
187187
if (instance.current.instanceColor) {
188188
setUpdateRange(instance.current.instanceColor, { offset: 0, count: count * 3 })
189189
}
190-
setUpdateRange(instance.current.geometry.attributes.opacity as BufferAttribute, { offset: 0, count: count })
190+
setUpdateRange(instance.current.geometry.attributes.cloudOpacity as BufferAttribute, { offset: 0, count: count })
191191
})
192192

193193
let imageBounds = [cloudTexture!.image.width ?? 1, cloudTexture!.image.height ?? 1]
194-
let max = Math.max(imageBounds[0], imageBounds[1])
194+
const max = Math.max(imageBounds[0], imageBounds[1])
195195
imageBounds = [imageBounds[0] / max, imageBounds[1] / max]
196196

197197
return (
@@ -206,7 +206,11 @@ export const Clouds = /* @__PURE__ */ React.forwardRef<Group, CloudsProps>(
206206
>
207207
<instancedBufferAttribute usage={DynamicDrawUsage} attach="instanceColor" args={[colors, 3]} />
208208
<planeGeometry args={[...imageBounds] as any}>
209-
<instancedBufferAttribute usage={DynamicDrawUsage} attach="attributes-opacity" args={[opacities, 1]} />
209+
<instancedBufferAttribute
210+
usage={DynamicDrawUsage}
211+
attach="attributes-cloudOpacity"
212+
args={[opacities, 1]}
213+
/>
210214
</planeGeometry>
211215
<cloudMaterial key={material.name} map={cloudTexture} transparent depthWrite={false} />
212216
</instancedMesh>
@@ -278,7 +282,7 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef<Group, CloudProps>
278282

279283
const distributed = distribute?.(cloud, index)
280284

281-
if (distributed || segments > 1)
285+
if (distributed || segments > 1) {
282286
cloud.position.copy(cloud.bounds).multiply(
283287
distributed?.point ??
284288
({
@@ -287,6 +291,7 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef<Group, CloudProps>
287291
z: random() * 2 - 1,
288292
} as Vector3)
289293
)
294+
}
290295
const xDiff = Math.abs(cloud.position.x)
291296
const yDiff = Math.abs(cloud.position.y)
292297
const zDiff = Math.abs(cloud.position.z)
@@ -321,10 +326,9 @@ export const CloudInstance = /* @__PURE__ */ React.forwardRef<Group, CloudProps>
321326
export const Cloud = /* @__PURE__ */ React.forwardRef<Group, CloudProps>((props, fref) => {
322327
const parent = React.useContext(context)
323328
if (parent) return <CloudInstance ref={fref} {...props} />
324-
else
325-
return (
326-
<Clouds>
327-
<CloudInstance ref={fref} {...props} />
328-
</Clouds>
329-
)
329+
return (
330+
<Clouds>
331+
<CloudInstance ref={fref} {...props} />
332+
</Clouds>
333+
)
330334
})

0 commit comments

Comments
 (0)