@lijuhong1981/three.instancedsprite 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +2 -0
- package/API.md +61 -3
- package/README.md +125 -55
- package/index.js +5 -5
- package/package.json +1 -1
- package/src/InstancedSprite.js +25 -2
- package/src/InstancedSpriteCollection.js +16 -0
- package/src/InstancedSpriteMaterial.js +146 -133
- package/src/InstancedSpriteMesh.js +425 -406
- package/src/InstancedSpriteNodeMaterial.js +21 -6
- package/.claude/settings.local.json +0 -7
|
@@ -42,6 +42,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
|
|
|
42
42
|
const aCenterAndSize = attribute('aCenterAndSize', 'vec4');
|
|
43
43
|
const aScaleAndRotationAndSizeAttenuation = attribute('aScaleAndRotationAndSizeAttenuation', 'vec3');
|
|
44
44
|
const aColorAndOpacity = attribute('aColorAndOpacity', 'vec4');
|
|
45
|
+
const aPickColorAndEnabled = attribute('aPickColorAndEnabled', 'vec4');
|
|
45
46
|
|
|
46
47
|
// ============================================================
|
|
47
48
|
// Varying 变量 — 从顶点着色器传递到片元着色器
|
|
@@ -49,6 +50,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
|
|
|
49
50
|
const vShow = varying(float(1));
|
|
50
51
|
const vColorAndOpacity = varying(vec4(1));
|
|
51
52
|
const vUv = varying(vec2(1));
|
|
53
|
+
const vPickColorAndEnabled = varying(vec4(1));
|
|
52
54
|
|
|
53
55
|
// ============================================================
|
|
54
56
|
// 顶点着色器 (vertexNode)
|
|
@@ -66,6 +68,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
|
|
|
66
68
|
vShow.assign(show);
|
|
67
69
|
vColorAndOpacity.assign(aColorAndOpacity);
|
|
68
70
|
vUv.assign(uv());
|
|
71
|
+
vPickColorAndEnabled.assign(aPickColorAndEnabled);
|
|
69
72
|
|
|
70
73
|
// --- 3. 计算模型视图位置 ---
|
|
71
74
|
const mvPosition = modelViewMatrix.mul(vec4(aPositionAndShow.xyz, 1));
|
|
@@ -122,12 +125,24 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
|
|
|
122
125
|
// 片元着色器 (fragmentNode)
|
|
123
126
|
// ============================================================
|
|
124
127
|
this.fragmentNode = Fn(() => {
|
|
125
|
-
|
|
126
|
-
const texColor = texture(this._textureNode, vUv);
|
|
127
|
-
const diffuseColor = texColor.mul(vColorAndOpacity);
|
|
128
|
+
Discard(vShow.lessThan(0.5));
|
|
128
129
|
|
|
129
|
-
|
|
130
|
-
|
|
130
|
+
const enablePickColor = vPickColorAndEnabled.w.greaterThan(0.5);
|
|
131
|
+
const diffuseColor = vec4(0, 0, 0, 1).toVar('diffuseColor');
|
|
132
|
+
|
|
133
|
+
If(enablePickColor, () => {
|
|
134
|
+
// 拾取模式:直接输出拾取颜色,不受纹理/透明度影响
|
|
135
|
+
diffuseColor.assign(vec4(vPickColorAndEnabled.xyz, 1));
|
|
136
|
+
}).Else(() => {
|
|
137
|
+
// 采样纹理
|
|
138
|
+
const texColor = texture(this._textureNode, vUv);
|
|
139
|
+
const color = texColor.mul(vColorAndOpacity);
|
|
140
|
+
|
|
141
|
+
// 丢弃完全透明的像素
|
|
142
|
+
Discard(color.a.lessThan(0.005));
|
|
143
|
+
|
|
144
|
+
diffuseColor.assign(color);
|
|
145
|
+
});
|
|
131
146
|
|
|
132
147
|
return diffuseColor;
|
|
133
148
|
}).once();
|
|
@@ -142,7 +157,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
|
|
|
142
157
|
set texture(value) {
|
|
143
158
|
this._textureNode.value = value;
|
|
144
159
|
}
|
|
145
|
-
}
|
|
160
|
+
};
|
|
146
161
|
|
|
147
162
|
export default InstancedSpriteNodeMaterial;
|
|
148
163
|
export { InstancedSpriteNodeMaterial };
|