@rezless/vm 0.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/LICENSE +202 -0
- package/NOTICE +32 -0
- package/dist/builtins/base64.d.ts +25 -0
- package/dist/builtins/base64.d.ts.map +1 -0
- package/dist/builtins/base64.js +43 -0
- package/dist/builtins/base64.js.map +1 -0
- package/dist/builtins/chat.d.ts +10 -0
- package/dist/builtins/chat.d.ts.map +1 -0
- package/dist/builtins/chat.js +36 -0
- package/dist/builtins/chat.js.map +1 -0
- package/dist/builtins/dataserver.d.ts +26 -0
- package/dist/builtins/dataserver.d.ts.map +1 -0
- package/dist/builtins/dataserver.js +20 -0
- package/dist/builtins/dataserver.js.map +1 -0
- package/dist/builtins/detected.d.ts +40 -0
- package/dist/builtins/detected.d.ts.map +1 -0
- package/dist/builtins/detected.js +23 -0
- package/dist/builtins/detected.js.map +1 -0
- package/dist/builtins/hash.d.ts +6 -0
- package/dist/builtins/hash.d.ts.map +1 -0
- package/dist/builtins/hash.js +34 -0
- package/dist/builtins/hash.js.map +1 -0
- package/dist/builtins/http.d.ts +40 -0
- package/dist/builtins/http.d.ts.map +1 -0
- package/dist/builtins/http.js +87 -0
- package/dist/builtins/http.js.map +1 -0
- package/dist/builtins/identity.d.ts +14 -0
- package/dist/builtins/identity.d.ts.map +1 -0
- package/dist/builtins/identity.js +17 -0
- package/dist/builtins/identity.js.map +1 -0
- package/dist/builtins/index.d.ts +8 -0
- package/dist/builtins/index.d.ts.map +1 -0
- package/dist/builtins/index.js +232 -0
- package/dist/builtins/index.js.map +1 -0
- package/dist/builtins/inventory.d.ts +33 -0
- package/dist/builtins/inventory.d.ts.map +1 -0
- package/dist/builtins/inventory.js +134 -0
- package/dist/builtins/inventory.js.map +1 -0
- package/dist/builtins/json.d.ts +7 -0
- package/dist/builtins/json.d.ts.map +1 -0
- package/dist/builtins/json.js +690 -0
- package/dist/builtins/json.js.map +1 -0
- package/dist/builtins/link-info.d.ts +10 -0
- package/dist/builtins/link-info.d.ts.map +1 -0
- package/dist/builtins/link-info.js +26 -0
- package/dist/builtins/link-info.js.map +1 -0
- package/dist/builtins/linked.d.ts +23 -0
- package/dist/builtins/linked.d.ts.map +1 -0
- package/dist/builtins/linked.js +20 -0
- package/dist/builtins/linked.js.map +1 -0
- package/dist/builtins/linksetdata.d.ts +20 -0
- package/dist/builtins/linksetdata.d.ts.map +1 -0
- package/dist/builtins/linksetdata.js +196 -0
- package/dist/builtins/linksetdata.js.map +1 -0
- package/dist/builtins/listen.d.ts +33 -0
- package/dist/builtins/listen.d.ts.map +1 -0
- package/dist/builtins/listen.js +45 -0
- package/dist/builtins/listen.js.map +1 -0
- package/dist/builtins/lists.d.ts +37 -0
- package/dist/builtins/lists.d.ts.map +1 -0
- package/dist/builtins/lists.js +275 -0
- package/dist/builtins/lists.js.map +1 -0
- package/dist/builtins/math.d.ts +32 -0
- package/dist/builtins/math.d.ts.map +1 -0
- package/dist/builtins/math.js +104 -0
- package/dist/builtins/math.js.map +1 -0
- package/dist/builtins/object.d.ts +29 -0
- package/dist/builtins/object.d.ts.map +1 -0
- package/dist/builtins/object.js +50 -0
- package/dist/builtins/object.js.map +1 -0
- package/dist/builtins/prim-accessors.d.ts +56 -0
- package/dist/builtins/prim-accessors.d.ts.map +1 -0
- package/dist/builtins/prim-accessors.js +353 -0
- package/dist/builtins/prim-accessors.js.map +1 -0
- package/dist/builtins/prim-params.d.ts +12 -0
- package/dist/builtins/prim-params.d.ts.map +1 -0
- package/dist/builtins/prim-params.js +124 -0
- package/dist/builtins/prim-params.js.map +1 -0
- package/dist/builtins/script-control.d.ts +13 -0
- package/dist/builtins/script-control.d.ts.map +1 -0
- package/dist/builtins/script-control.js +41 -0
- package/dist/builtins/script-control.js.map +1 -0
- package/dist/builtins/strings.d.ts +23 -0
- package/dist/builtins/strings.d.ts.map +1 -0
- package/dist/builtins/strings.js +130 -0
- package/dist/builtins/strings.js.map +1 -0
- package/dist/builtins/time.d.ts +28 -0
- package/dist/builtins/time.d.ts.map +1 -0
- package/dist/builtins/time.js +54 -0
- package/dist/builtins/time.js.map +1 -0
- package/dist/clock.d.ts +75 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +125 -0
- package/dist/clock.js.map +1 -0
- package/dist/coverage.d.ts +110 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +221 -0
- package/dist/coverage.js.map +1 -0
- package/dist/dispatch.d.ts +19 -0
- package/dist/dispatch.d.ts.map +1 -0
- package/dist/dispatch.js +42 -0
- package/dist/dispatch.js.map +1 -0
- package/dist/env.d.ts +33 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +76 -0
- package/dist/env.js.map +1 -0
- package/dist/generated/constants.d.ts +967 -0
- package/dist/generated/constants.d.ts.map +1 -0
- package/dist/generated/constants.js +969 -0
- package/dist/generated/constants.js.map +1 -0
- package/dist/generated/constants_table.d.ts +11 -0
- package/dist/generated/constants_table.d.ts.map +1 -0
- package/dist/generated/constants_table.js +978 -0
- package/dist/generated/constants_table.js.map +1 -0
- package/dist/generated/events.d.ts +545 -0
- package/dist/generated/events.d.ts.map +1 -0
- package/dist/generated/events.js +49 -0
- package/dist/generated/events.js.map +1 -0
- package/dist/generated/functions.d.ts +6051 -0
- package/dist/generated/functions.d.ts.map +1 -0
- package/dist/generated/functions.js +526 -0
- package/dist/generated/functions.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/interpreter.d.ts +39 -0
- package/dist/interpreter.d.ts.map +1 -0
- package/dist/interpreter.js +381 -0
- package/dist/interpreter.js.map +1 -0
- package/dist/inventory.d.ts +52 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +45 -0
- package/dist/inventory.js.map +1 -0
- package/dist/linkset.d.ts +89 -0
- package/dist/linkset.d.ts.map +1 -0
- package/dist/linkset.js +179 -0
- package/dist/linkset.js.map +1 -0
- package/dist/prim-params.d.ts +221 -0
- package/dist/prim-params.d.ts.map +1 -0
- package/dist/prim-params.js +852 -0
- package/dist/prim-params.js.map +1 -0
- package/dist/prim.d.ts +79 -0
- package/dist/prim.d.ts.map +1 -0
- package/dist/prim.js +96 -0
- package/dist/prim.js.map +1 -0
- package/dist/random.d.ts +16 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +29 -0
- package/dist/random.js.map +1 -0
- package/dist/runtime.d.ts +108 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -0
- package/dist/script.d.ts +248 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +667 -0
- package/dist/script.js.map +1 -0
- package/dist/values/coerce.d.ts +22 -0
- package/dist/values/coerce.d.ts.map +1 -0
- package/dist/values/coerce.js +184 -0
- package/dist/values/coerce.js.map +1 -0
- package/dist/values/format.d.ts +20 -0
- package/dist/values/format.d.ts.map +1 -0
- package/dist/values/format.js +47 -0
- package/dist/values/format.js.map +1 -0
- package/dist/values/ops.d.ts +19 -0
- package/dist/values/ops.d.ts.map +1 -0
- package/dist/values/ops.js +345 -0
- package/dist/values/ops.js.map +1 -0
- package/dist/values/types.d.ts +39 -0
- package/dist/values/types.d.ts.map +1 -0
- package/dist/values/types.js +68 -0
- package/dist/values/types.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import { ALL_SIDES, CLICK_ACTION_TOUCH, PRIM_ALPHA_MODE, PRIM_ALPHA_MODE_NONE, PRIM_ALLOW_UNSIT, PRIM_BUMP_NONE, PRIM_BUMP_SHINY, PRIM_CAST_SHADOWS, PRIM_CLICK_ACTION, PRIM_COLOR, PRIM_DAMAGE, PRIM_DESC, PRIM_FLEXIBLE, PRIM_FULLBRIGHT, PRIM_GLOW, PRIM_GLTF_ALPHA_MODE_OPAQUE, PRIM_GLTF_BASE_COLOR, PRIM_GLTF_EMISSIVE, PRIM_GLTF_METALLIC_ROUGHNESS, PRIM_GLTF_NORMAL, PRIM_HEALTH, PRIM_HOLE_DEFAULT, PRIM_LINK_TARGET, PRIM_MATERIAL, PRIM_MATERIAL_STONE, PRIM_NAME, PRIM_NORMAL, PRIM_OMEGA, PRIM_PHANTOM, PRIM_PHYSICS, PRIM_PHYSICS_SHAPE_PRIM, PRIM_PHYSICS_SHAPE_TYPE, PRIM_POINT_LIGHT, PRIM_POSITION, PRIM_POS_LOCAL, PRIM_PROJECTOR, PRIM_REFLECTION_PROBE, PRIM_RENDER_MATERIAL, PRIM_ROTATION, PRIM_ROT_LOCAL, PRIM_SCRIPTED_SIT_ONLY, PRIM_SCULPT_TYPE_SPHERE, PRIM_SHINY_NONE, PRIM_SIT_FLAGS, PRIM_SIT_TARGET, PRIM_SIZE, PRIM_SLICE, PRIM_SPECULAR, PRIM_TEMP_ON_REZ, PRIM_TEXGEN, PRIM_TEXGEN_DEFAULT, PRIM_TEXT, PRIM_TEXTURE, PRIM_TYPE, PRIM_TYPE_BOX, PRIM_TYPE_CYLINDER, PRIM_TYPE_PRISM, PRIM_TYPE_RING, PRIM_TYPE_SCULPT, PRIM_TYPE_SPHERE, PRIM_TYPE_TORUS, PRIM_TYPE_TUBE, STATUS_PHANTOM, STATUS_PHYSICS, TEXTURE_DEFAULT, } from './generated/constants.js';
|
|
2
|
+
import { NULL_KEY } from './values/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Typed-literal aliases for the kwdb PRIM_TYPE_* constants. The
|
|
5
|
+
* generated module exports them as `: number` so TS can't narrow on
|
|
6
|
+
* them; we re-pin them to their literal values here. The `as` assertions
|
|
7
|
+
* are runtime-asserted below so a future kwdb renumber would surface as
|
|
8
|
+
* a load-time failure rather than silent corruption.
|
|
9
|
+
*/
|
|
10
|
+
const SHAPE_BOX = PRIM_TYPE_BOX;
|
|
11
|
+
const SHAPE_CYLINDER = PRIM_TYPE_CYLINDER;
|
|
12
|
+
const SHAPE_PRISM = PRIM_TYPE_PRISM;
|
|
13
|
+
const SHAPE_SPHERE = PRIM_TYPE_SPHERE;
|
|
14
|
+
const SHAPE_TORUS = PRIM_TYPE_TORUS;
|
|
15
|
+
const SHAPE_TUBE = PRIM_TYPE_TUBE;
|
|
16
|
+
const SHAPE_RING = PRIM_TYPE_RING;
|
|
17
|
+
const SHAPE_SCULPT = PRIM_TYPE_SCULPT;
|
|
18
|
+
if (SHAPE_BOX !== 0 || SHAPE_CYLINDER !== 1 || SHAPE_PRISM !== 2 ||
|
|
19
|
+
SHAPE_SPHERE !== 3 || SHAPE_TORUS !== 4 || SHAPE_TUBE !== 5 ||
|
|
20
|
+
SHAPE_RING !== 6 || SHAPE_SCULPT !== 7) {
|
|
21
|
+
throw new Error('kwdb PRIM_TYPE_* constants disagree with PrimShape literal aliases');
|
|
22
|
+
}
|
|
23
|
+
const zero = () => ({ x: 0, y: 0, z: 0 });
|
|
24
|
+
const one = () => ({ x: 1, y: 1, z: 1 });
|
|
25
|
+
const identityRot = () => ({ x: 0, y: 0, z: 0, s: 1 });
|
|
26
|
+
function defaultFaceMaterial() {
|
|
27
|
+
return { texture: '', textureRepeats: { x: 1, y: 1, z: 0 }, textureOffsets: zero(), textureRotation: 0 };
|
|
28
|
+
}
|
|
29
|
+
export function defaultFace() {
|
|
30
|
+
return {
|
|
31
|
+
texture: TEXTURE_DEFAULT,
|
|
32
|
+
textureRepeats: { x: 1, y: 1, z: 0 },
|
|
33
|
+
textureOffsets: zero(),
|
|
34
|
+
textureRotation: 0,
|
|
35
|
+
color: one(),
|
|
36
|
+
alpha: 1,
|
|
37
|
+
bumpShiny: { shiny: PRIM_SHINY_NONE, bump: PRIM_BUMP_NONE },
|
|
38
|
+
fullBright: false,
|
|
39
|
+
glow: 0,
|
|
40
|
+
texgen: PRIM_TEXGEN_DEFAULT,
|
|
41
|
+
renderMaterial: '',
|
|
42
|
+
normal: defaultFaceMaterial(),
|
|
43
|
+
specular: { ...defaultFaceMaterial(), color: one(), glossiness: 51, environment: 0 },
|
|
44
|
+
alphaMode: { mode: PRIM_ALPHA_MODE_NONE, cutoff: 0 },
|
|
45
|
+
gltf: {
|
|
46
|
+
baseColor: { ...defaultFaceMaterial(), color: one(), alpha: 1, alphaMode: PRIM_GLTF_ALPHA_MODE_OPAQUE, alphaCutoff: 0.5, doubleSided: 0 },
|
|
47
|
+
normal: defaultFaceMaterial(),
|
|
48
|
+
metallicRoughness: { ...defaultFaceMaterial(), metallic: 1, roughness: 1 },
|
|
49
|
+
emissive: { ...defaultFaceMaterial(), tint: zero() },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function defaultShape() {
|
|
54
|
+
return {
|
|
55
|
+
kind: SHAPE_BOX,
|
|
56
|
+
hole: PRIM_HOLE_DEFAULT,
|
|
57
|
+
cut: { x: 0, y: 1, z: 0 },
|
|
58
|
+
hollow: 0,
|
|
59
|
+
twist: zero(),
|
|
60
|
+
topSize: { x: 1, y: 1, z: 0 },
|
|
61
|
+
topShear: zero(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function defaultPrimParams() {
|
|
65
|
+
return {
|
|
66
|
+
position: zero(),
|
|
67
|
+
rotation: identityRot(),
|
|
68
|
+
size: { x: 0.5, y: 0.5, z: 0.5 },
|
|
69
|
+
faces: Array.from({ length: 6 }, () => defaultFace()),
|
|
70
|
+
pointLight: { enabled: false, color: one(), intensity: 1, radius: 10, falloff: 0.75 },
|
|
71
|
+
glow: [0, 0, 0, 0, 0, 0],
|
|
72
|
+
omega: { axis: zero(), spinrate: 0, gain: 0 },
|
|
73
|
+
physicsShapeType: PRIM_PHYSICS_SHAPE_PRIM,
|
|
74
|
+
flexible: { enabled: false, softness: 0, gravity: 0, friction: 0, wind: 0, tension: 0, force: zero() },
|
|
75
|
+
sculpt: { textureKey: '', type: PRIM_SCULPT_TYPE_SPHERE },
|
|
76
|
+
slice: { x: 0, y: 1, z: 0 },
|
|
77
|
+
shape: defaultShape(),
|
|
78
|
+
material: PRIM_MATERIAL_STONE,
|
|
79
|
+
tempOnRez: false,
|
|
80
|
+
castShadows: false,
|
|
81
|
+
allowUnsit: true,
|
|
82
|
+
scriptedSitOnly: false,
|
|
83
|
+
sitTarget: { enabled: false, offset: zero(), rotation: identityRot() },
|
|
84
|
+
sitFlags: 0,
|
|
85
|
+
projector: { texture: NULL_KEY, fov: 0, focus: 0, ambiance: 0 },
|
|
86
|
+
clickAction: CLICK_ACTION_TOUCH,
|
|
87
|
+
damage: { amount: 0, type: 0 },
|
|
88
|
+
health: 1,
|
|
89
|
+
reflectionProbe: { enabled: false, ambiance: 0, clipDistance: 0, flags: 0 },
|
|
90
|
+
physicsMaterial: { gravityMultiplier: 1, restitution: 0, friction: 0, density: 1000 },
|
|
91
|
+
textureAnim: { mode: 0, face: 0, sizex: 0, sizey: 0, start: 0, length: 0, rate: 0 },
|
|
92
|
+
passCollisions: 0,
|
|
93
|
+
passTouches: 0,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/* ------------------------------------------------------------------ */
|
|
97
|
+
/* Helpers used by Prim.getPrimParam / setPrimParam */
|
|
98
|
+
/* ------------------------------------------------------------------ */
|
|
99
|
+
const num = (v, d = 0) => (typeof v === 'number' ? v : d);
|
|
100
|
+
const str = (v, d = '') => (typeof v === 'string' ? v : d);
|
|
101
|
+
const asVec = (v) => {
|
|
102
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && 'x' in v && 'y' in v && 'z' in v && !('s' in v)) {
|
|
103
|
+
const w = v;
|
|
104
|
+
return { x: w.x, y: w.y, z: w.z };
|
|
105
|
+
}
|
|
106
|
+
return zero();
|
|
107
|
+
};
|
|
108
|
+
const asRot = (v) => {
|
|
109
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && 's' in v) {
|
|
110
|
+
const r = v;
|
|
111
|
+
return { x: r.x, y: r.y, z: r.z, s: r.s };
|
|
112
|
+
}
|
|
113
|
+
return identityRot();
|
|
114
|
+
};
|
|
115
|
+
function facesOf(faceArg) {
|
|
116
|
+
const f = num(faceArg, 0) | 0;
|
|
117
|
+
if (f === ALL_SIDES)
|
|
118
|
+
return [0, 1, 2, 3, 4, 5];
|
|
119
|
+
return [f];
|
|
120
|
+
}
|
|
121
|
+
function inRange(face) {
|
|
122
|
+
return face >= 0 && face <= 5;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Slot count for a PRIM_* rule's *write* form, given the rule constant
|
|
126
|
+
* and (for variable-shape rules like PRIM_TYPE) the rules list + cursor
|
|
127
|
+
* to peek at the discriminator. Does NOT mutate the prim. Returns null
|
|
128
|
+
* for unsupported / unknown rule constants. Used by the walker to skip
|
|
129
|
+
* past rules that can't be applied (e.g. PRIM_LINK_TARGET resolved to
|
|
130
|
+
* an empty target set) without losing track of cursor position.
|
|
131
|
+
*/
|
|
132
|
+
export function writePrimParamSlots(param, rules, cursor) {
|
|
133
|
+
switch (param) {
|
|
134
|
+
case PRIM_NAME:
|
|
135
|
+
case PRIM_DESC:
|
|
136
|
+
case PRIM_POSITION:
|
|
137
|
+
case PRIM_POS_LOCAL:
|
|
138
|
+
case PRIM_ROTATION:
|
|
139
|
+
case PRIM_ROT_LOCAL:
|
|
140
|
+
case PRIM_SIZE:
|
|
141
|
+
case PRIM_SLICE:
|
|
142
|
+
case PRIM_MATERIAL:
|
|
143
|
+
case PRIM_PHYSICS:
|
|
144
|
+
case PRIM_PHANTOM:
|
|
145
|
+
case PRIM_TEMP_ON_REZ:
|
|
146
|
+
case PRIM_PHYSICS_SHAPE_TYPE:
|
|
147
|
+
case PRIM_CAST_SHADOWS:
|
|
148
|
+
case PRIM_ALLOW_UNSIT:
|
|
149
|
+
case PRIM_SCRIPTED_SIT_ONLY:
|
|
150
|
+
case PRIM_SIT_FLAGS:
|
|
151
|
+
case PRIM_CLICK_ACTION:
|
|
152
|
+
case PRIM_HEALTH:
|
|
153
|
+
return 1;
|
|
154
|
+
case PRIM_DAMAGE:
|
|
155
|
+
return 2;
|
|
156
|
+
case PRIM_TEXT:
|
|
157
|
+
case PRIM_OMEGA:
|
|
158
|
+
case PRIM_SIT_TARGET:
|
|
159
|
+
return 3;
|
|
160
|
+
case PRIM_REFLECTION_PROBE:
|
|
161
|
+
case PRIM_PROJECTOR:
|
|
162
|
+
return 4;
|
|
163
|
+
case PRIM_POINT_LIGHT:
|
|
164
|
+
return 5;
|
|
165
|
+
case PRIM_FLEXIBLE:
|
|
166
|
+
return 7;
|
|
167
|
+
case PRIM_TYPE: {
|
|
168
|
+
const kind = num(rules[cursor]) | 0;
|
|
169
|
+
if (kind === SHAPE_BOX || kind === SHAPE_CYLINDER || kind === SHAPE_PRISM)
|
|
170
|
+
return 7;
|
|
171
|
+
if (kind === SHAPE_SPHERE)
|
|
172
|
+
return 6;
|
|
173
|
+
if (kind === SHAPE_TORUS || kind === SHAPE_TUBE || kind === SHAPE_RING)
|
|
174
|
+
return 12;
|
|
175
|
+
if (kind === SHAPE_SCULPT)
|
|
176
|
+
return 3;
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
case PRIM_COLOR: return 3;
|
|
180
|
+
case PRIM_TEXTURE:
|
|
181
|
+
case PRIM_NORMAL:
|
|
182
|
+
case PRIM_GLTF_NORMAL: return 5;
|
|
183
|
+
case PRIM_RENDER_MATERIAL:
|
|
184
|
+
case PRIM_FULLBRIGHT:
|
|
185
|
+
case PRIM_GLOW:
|
|
186
|
+
case PRIM_TEXGEN: return 2;
|
|
187
|
+
case PRIM_BUMP_SHINY:
|
|
188
|
+
case PRIM_ALPHA_MODE: return 3;
|
|
189
|
+
case PRIM_SPECULAR: return 8;
|
|
190
|
+
case PRIM_GLTF_BASE_COLOR: return 10;
|
|
191
|
+
case PRIM_GLTF_METALLIC_ROUGHNESS: return 7;
|
|
192
|
+
case PRIM_GLTF_EMISSIVE: return 6;
|
|
193
|
+
case PRIM_LINK_TARGET: return null; // walker handles
|
|
194
|
+
default: return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Apply one PRIM_* rule starting at `cursor` in `rules`. Returns the
|
|
199
|
+
* number of slots after `param` consumed by the rule (so the walker
|
|
200
|
+
* advances by `1 + consumed`). Returns `null` for unsupported / unknown
|
|
201
|
+
* rule constants — the walker stops parsing the list, matching LSL.
|
|
202
|
+
*/
|
|
203
|
+
export function writePrimParam(prim, param, rules, cursor) {
|
|
204
|
+
const p = prim.params;
|
|
205
|
+
switch (param) {
|
|
206
|
+
case PRIM_NAME:
|
|
207
|
+
prim.name = str(rules[cursor]);
|
|
208
|
+
return 1;
|
|
209
|
+
case PRIM_DESC:
|
|
210
|
+
prim.description = str(rules[cursor]);
|
|
211
|
+
prim.appearance.description = prim.description;
|
|
212
|
+
return 1;
|
|
213
|
+
case PRIM_TEXT: {
|
|
214
|
+
const text = str(rules[cursor]);
|
|
215
|
+
const color = asVec(rules[cursor + 1]);
|
|
216
|
+
const alpha = num(rules[cursor + 2], 1);
|
|
217
|
+
prim.appearance.text = { text, color, alpha };
|
|
218
|
+
return 3;
|
|
219
|
+
}
|
|
220
|
+
case PRIM_POSITION:
|
|
221
|
+
case PRIM_POS_LOCAL:
|
|
222
|
+
p.position = asVec(rules[cursor]);
|
|
223
|
+
return 1;
|
|
224
|
+
case PRIM_ROTATION:
|
|
225
|
+
case PRIM_ROT_LOCAL:
|
|
226
|
+
p.rotation = asRot(rules[cursor]);
|
|
227
|
+
return 1;
|
|
228
|
+
case PRIM_SIZE:
|
|
229
|
+
p.size = asVec(rules[cursor]);
|
|
230
|
+
return 1;
|
|
231
|
+
case PRIM_SLICE:
|
|
232
|
+
p.slice = asVec(rules[cursor]);
|
|
233
|
+
return 1;
|
|
234
|
+
case PRIM_MATERIAL:
|
|
235
|
+
p.material = num(rules[cursor]) | 0;
|
|
236
|
+
return 1;
|
|
237
|
+
case PRIM_PHYSICS:
|
|
238
|
+
prim.setStatus(STATUS_PHYSICS, num(rules[cursor]) !== 0);
|
|
239
|
+
return 1;
|
|
240
|
+
case PRIM_PHANTOM:
|
|
241
|
+
prim.setStatus(STATUS_PHANTOM, num(rules[cursor]) !== 0);
|
|
242
|
+
return 1;
|
|
243
|
+
case PRIM_TEMP_ON_REZ:
|
|
244
|
+
p.tempOnRez = num(rules[cursor]) !== 0;
|
|
245
|
+
return 1;
|
|
246
|
+
case PRIM_PHYSICS_SHAPE_TYPE:
|
|
247
|
+
p.physicsShapeType = num(rules[cursor]) | 0;
|
|
248
|
+
return 1;
|
|
249
|
+
case PRIM_CAST_SHADOWS:
|
|
250
|
+
p.castShadows = num(rules[cursor]) !== 0;
|
|
251
|
+
return 1;
|
|
252
|
+
case PRIM_ALLOW_UNSIT:
|
|
253
|
+
p.allowUnsit = num(rules[cursor]) !== 0;
|
|
254
|
+
return 1;
|
|
255
|
+
case PRIM_SCRIPTED_SIT_ONLY:
|
|
256
|
+
p.scriptedSitOnly = num(rules[cursor]) !== 0;
|
|
257
|
+
return 1;
|
|
258
|
+
case PRIM_SIT_FLAGS:
|
|
259
|
+
p.sitFlags = num(rules[cursor]) | 0;
|
|
260
|
+
return 1;
|
|
261
|
+
case PRIM_CLICK_ACTION:
|
|
262
|
+
p.clickAction = num(rules[cursor]) | 0;
|
|
263
|
+
return 1;
|
|
264
|
+
case PRIM_HEALTH:
|
|
265
|
+
p.health = num(rules[cursor]);
|
|
266
|
+
return 1;
|
|
267
|
+
case PRIM_DAMAGE:
|
|
268
|
+
p.damage = { amount: num(rules[cursor]), type: num(rules[cursor + 1]) | 0 };
|
|
269
|
+
return 2;
|
|
270
|
+
case PRIM_OMEGA:
|
|
271
|
+
p.omega = { axis: asVec(rules[cursor]), spinrate: num(rules[cursor + 1]), gain: num(rules[cursor + 2]) };
|
|
272
|
+
return 3;
|
|
273
|
+
case PRIM_POINT_LIGHT:
|
|
274
|
+
p.pointLight = {
|
|
275
|
+
enabled: num(rules[cursor]) !== 0,
|
|
276
|
+
color: asVec(rules[cursor + 1]),
|
|
277
|
+
intensity: num(rules[cursor + 2]),
|
|
278
|
+
radius: num(rules[cursor + 3]),
|
|
279
|
+
falloff: num(rules[cursor + 4]),
|
|
280
|
+
};
|
|
281
|
+
return 5;
|
|
282
|
+
case PRIM_REFLECTION_PROBE:
|
|
283
|
+
p.reflectionProbe = {
|
|
284
|
+
enabled: num(rules[cursor]) !== 0,
|
|
285
|
+
ambiance: num(rules[cursor + 1]),
|
|
286
|
+
clipDistance: num(rules[cursor + 2]),
|
|
287
|
+
flags: num(rules[cursor + 3]) | 0,
|
|
288
|
+
};
|
|
289
|
+
return 4;
|
|
290
|
+
case PRIM_PROJECTOR:
|
|
291
|
+
p.projector = {
|
|
292
|
+
texture: str(rules[cursor]),
|
|
293
|
+
fov: num(rules[cursor + 1]),
|
|
294
|
+
focus: num(rules[cursor + 2]),
|
|
295
|
+
ambiance: num(rules[cursor + 3]),
|
|
296
|
+
};
|
|
297
|
+
return 4;
|
|
298
|
+
case PRIM_FLEXIBLE:
|
|
299
|
+
p.flexible = {
|
|
300
|
+
enabled: num(rules[cursor]) !== 0,
|
|
301
|
+
softness: num(rules[cursor + 1]) | 0,
|
|
302
|
+
gravity: num(rules[cursor + 2]),
|
|
303
|
+
friction: num(rules[cursor + 3]),
|
|
304
|
+
wind: num(rules[cursor + 4]),
|
|
305
|
+
tension: num(rules[cursor + 5]),
|
|
306
|
+
force: asVec(rules[cursor + 6]),
|
|
307
|
+
};
|
|
308
|
+
return 7;
|
|
309
|
+
case PRIM_SIT_TARGET:
|
|
310
|
+
p.sitTarget = {
|
|
311
|
+
enabled: num(rules[cursor]) !== 0,
|
|
312
|
+
offset: asVec(rules[cursor + 1]),
|
|
313
|
+
rotation: asRot(rules[cursor + 2]),
|
|
314
|
+
};
|
|
315
|
+
return 3;
|
|
316
|
+
case PRIM_TYPE:
|
|
317
|
+
return writePrimType(p, rules, cursor);
|
|
318
|
+
case PRIM_COLOR: {
|
|
319
|
+
const faces = facesOf(rules[cursor]);
|
|
320
|
+
const color = asVec(rules[cursor + 1]);
|
|
321
|
+
const alpha = num(rules[cursor + 2], 1);
|
|
322
|
+
for (const f of faces) {
|
|
323
|
+
if (!inRange(f))
|
|
324
|
+
continue;
|
|
325
|
+
// Clone so faces don't alias the same vector instance.
|
|
326
|
+
p.faces[f].color = { x: color.x, y: color.y, z: color.z };
|
|
327
|
+
p.faces[f].alpha = alpha;
|
|
328
|
+
}
|
|
329
|
+
return 3;
|
|
330
|
+
}
|
|
331
|
+
case PRIM_TEXTURE: {
|
|
332
|
+
const faces = facesOf(rules[cursor]);
|
|
333
|
+
const tex = str(rules[cursor + 1]);
|
|
334
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
335
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
336
|
+
const rot = num(rules[cursor + 4]);
|
|
337
|
+
for (const f of faces) {
|
|
338
|
+
if (!inRange(f))
|
|
339
|
+
continue;
|
|
340
|
+
p.faces[f].texture = tex;
|
|
341
|
+
p.faces[f].textureRepeats = { x: repeats.x, y: repeats.y, z: repeats.z };
|
|
342
|
+
p.faces[f].textureOffsets = { x: offsets.x, y: offsets.y, z: offsets.z };
|
|
343
|
+
p.faces[f].textureRotation = rot;
|
|
344
|
+
}
|
|
345
|
+
return 5;
|
|
346
|
+
}
|
|
347
|
+
case PRIM_RENDER_MATERIAL: {
|
|
348
|
+
const faces = facesOf(rules[cursor]);
|
|
349
|
+
const m = str(rules[cursor + 1]);
|
|
350
|
+
for (const f of faces) {
|
|
351
|
+
if (!inRange(f))
|
|
352
|
+
continue;
|
|
353
|
+
p.faces[f].renderMaterial = m;
|
|
354
|
+
}
|
|
355
|
+
return 2;
|
|
356
|
+
}
|
|
357
|
+
case PRIM_FULLBRIGHT: {
|
|
358
|
+
const faces = facesOf(rules[cursor]);
|
|
359
|
+
const v = num(rules[cursor + 1]) !== 0;
|
|
360
|
+
for (const f of faces) {
|
|
361
|
+
if (!inRange(f))
|
|
362
|
+
continue;
|
|
363
|
+
p.faces[f].fullBright = v;
|
|
364
|
+
}
|
|
365
|
+
return 2;
|
|
366
|
+
}
|
|
367
|
+
case PRIM_GLOW: {
|
|
368
|
+
const faces = facesOf(rules[cursor]);
|
|
369
|
+
const v = num(rules[cursor + 1]);
|
|
370
|
+
for (const f of faces) {
|
|
371
|
+
if (!inRange(f))
|
|
372
|
+
continue;
|
|
373
|
+
p.faces[f].glow = v;
|
|
374
|
+
p.glow[f] = v;
|
|
375
|
+
}
|
|
376
|
+
return 2;
|
|
377
|
+
}
|
|
378
|
+
case PRIM_BUMP_SHINY: {
|
|
379
|
+
const faces = facesOf(rules[cursor]);
|
|
380
|
+
const shiny = num(rules[cursor + 1]) | 0;
|
|
381
|
+
const bump = num(rules[cursor + 2]) | 0;
|
|
382
|
+
for (const f of faces) {
|
|
383
|
+
if (!inRange(f))
|
|
384
|
+
continue;
|
|
385
|
+
p.faces[f].bumpShiny = { shiny, bump };
|
|
386
|
+
}
|
|
387
|
+
return 3;
|
|
388
|
+
}
|
|
389
|
+
case PRIM_TEXGEN: {
|
|
390
|
+
const faces = facesOf(rules[cursor]);
|
|
391
|
+
const mode = num(rules[cursor + 1]) | 0;
|
|
392
|
+
for (const f of faces) {
|
|
393
|
+
if (!inRange(f))
|
|
394
|
+
continue;
|
|
395
|
+
p.faces[f].texgen = mode;
|
|
396
|
+
}
|
|
397
|
+
return 2;
|
|
398
|
+
}
|
|
399
|
+
case PRIM_NORMAL: {
|
|
400
|
+
const faces = facesOf(rules[cursor]);
|
|
401
|
+
const tex = str(rules[cursor + 1]);
|
|
402
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
403
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
404
|
+
const rot = num(rules[cursor + 4]);
|
|
405
|
+
for (const f of faces) {
|
|
406
|
+
if (!inRange(f))
|
|
407
|
+
continue;
|
|
408
|
+
p.faces[f].normal = {
|
|
409
|
+
texture: tex,
|
|
410
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
411
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
412
|
+
textureRotation: rot,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
return 5;
|
|
416
|
+
}
|
|
417
|
+
case PRIM_SPECULAR: {
|
|
418
|
+
const faces = facesOf(rules[cursor]);
|
|
419
|
+
const tex = str(rules[cursor + 1]);
|
|
420
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
421
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
422
|
+
const rot = num(rules[cursor + 4]);
|
|
423
|
+
const color = asVec(rules[cursor + 5]);
|
|
424
|
+
const gloss = num(rules[cursor + 6]) | 0;
|
|
425
|
+
const env = num(rules[cursor + 7]) | 0;
|
|
426
|
+
for (const f of faces) {
|
|
427
|
+
if (!inRange(f))
|
|
428
|
+
continue;
|
|
429
|
+
p.faces[f].specular = {
|
|
430
|
+
texture: tex,
|
|
431
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
432
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
433
|
+
textureRotation: rot,
|
|
434
|
+
color: { x: color.x, y: color.y, z: color.z },
|
|
435
|
+
glossiness: gloss,
|
|
436
|
+
environment: env,
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
return 8;
|
|
440
|
+
}
|
|
441
|
+
case PRIM_ALPHA_MODE: {
|
|
442
|
+
const faces = facesOf(rules[cursor]);
|
|
443
|
+
const mode = num(rules[cursor + 1]) | 0;
|
|
444
|
+
const cutoff = num(rules[cursor + 2]) | 0;
|
|
445
|
+
for (const f of faces) {
|
|
446
|
+
if (!inRange(f))
|
|
447
|
+
continue;
|
|
448
|
+
p.faces[f].alphaMode = { mode, cutoff };
|
|
449
|
+
}
|
|
450
|
+
return 3;
|
|
451
|
+
}
|
|
452
|
+
case PRIM_GLTF_BASE_COLOR: {
|
|
453
|
+
const faces = facesOf(rules[cursor]);
|
|
454
|
+
const tex = str(rules[cursor + 1]);
|
|
455
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
456
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
457
|
+
const rot = num(rules[cursor + 4]);
|
|
458
|
+
const color = asVec(rules[cursor + 5]);
|
|
459
|
+
const alpha = num(rules[cursor + 6], 1);
|
|
460
|
+
const aMode = num(rules[cursor + 7]) | 0;
|
|
461
|
+
const aCut = num(rules[cursor + 8]);
|
|
462
|
+
const dbl = num(rules[cursor + 9]) | 0;
|
|
463
|
+
for (const f of faces) {
|
|
464
|
+
if (!inRange(f))
|
|
465
|
+
continue;
|
|
466
|
+
p.faces[f].gltf.baseColor = {
|
|
467
|
+
texture: tex,
|
|
468
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
469
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
470
|
+
textureRotation: rot,
|
|
471
|
+
color: { x: color.x, y: color.y, z: color.z },
|
|
472
|
+
alpha,
|
|
473
|
+
alphaMode: aMode,
|
|
474
|
+
alphaCutoff: aCut,
|
|
475
|
+
doubleSided: dbl,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return 10;
|
|
479
|
+
}
|
|
480
|
+
case PRIM_GLTF_NORMAL: {
|
|
481
|
+
const faces = facesOf(rules[cursor]);
|
|
482
|
+
const tex = str(rules[cursor + 1]);
|
|
483
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
484
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
485
|
+
const rot = num(rules[cursor + 4]);
|
|
486
|
+
for (const f of faces) {
|
|
487
|
+
if (!inRange(f))
|
|
488
|
+
continue;
|
|
489
|
+
p.faces[f].gltf.normal = {
|
|
490
|
+
texture: tex,
|
|
491
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
492
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
493
|
+
textureRotation: rot,
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
return 5;
|
|
497
|
+
}
|
|
498
|
+
case PRIM_GLTF_METALLIC_ROUGHNESS: {
|
|
499
|
+
const faces = facesOf(rules[cursor]);
|
|
500
|
+
const tex = str(rules[cursor + 1]);
|
|
501
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
502
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
503
|
+
const rot = num(rules[cursor + 4]);
|
|
504
|
+
const metallic = num(rules[cursor + 5]);
|
|
505
|
+
const rough = num(rules[cursor + 6]);
|
|
506
|
+
for (const f of faces) {
|
|
507
|
+
if (!inRange(f))
|
|
508
|
+
continue;
|
|
509
|
+
p.faces[f].gltf.metallicRoughness = {
|
|
510
|
+
texture: tex,
|
|
511
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
512
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
513
|
+
textureRotation: rot,
|
|
514
|
+
metallic,
|
|
515
|
+
roughness: rough,
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
return 7;
|
|
519
|
+
}
|
|
520
|
+
case PRIM_GLTF_EMISSIVE: {
|
|
521
|
+
const faces = facesOf(rules[cursor]);
|
|
522
|
+
const tex = str(rules[cursor + 1]);
|
|
523
|
+
const repeats = asVec(rules[cursor + 2]);
|
|
524
|
+
const offsets = asVec(rules[cursor + 3]);
|
|
525
|
+
const rot = num(rules[cursor + 4]);
|
|
526
|
+
const tint = asVec(rules[cursor + 5]);
|
|
527
|
+
for (const f of faces) {
|
|
528
|
+
if (!inRange(f))
|
|
529
|
+
continue;
|
|
530
|
+
p.faces[f].gltf.emissive = {
|
|
531
|
+
texture: tex,
|
|
532
|
+
textureRepeats: { x: repeats.x, y: repeats.y, z: repeats.z },
|
|
533
|
+
textureOffsets: { x: offsets.x, y: offsets.y, z: offsets.z },
|
|
534
|
+
textureRotation: rot,
|
|
535
|
+
tint: { x: tint.x, y: tint.y, z: tint.z },
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
return 6;
|
|
539
|
+
}
|
|
540
|
+
case PRIM_LINK_TARGET:
|
|
541
|
+
return null;
|
|
542
|
+
default:
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function writePrimType(p, rules, cursor) {
|
|
547
|
+
const kind = (num(rules[cursor]) | 0);
|
|
548
|
+
switch (kind) {
|
|
549
|
+
case SHAPE_BOX:
|
|
550
|
+
case SHAPE_CYLINDER:
|
|
551
|
+
case SHAPE_PRISM:
|
|
552
|
+
p.shape = {
|
|
553
|
+
kind: kind,
|
|
554
|
+
hole: num(rules[cursor + 1]) | 0,
|
|
555
|
+
cut: asVec(rules[cursor + 2]),
|
|
556
|
+
hollow: num(rules[cursor + 3]),
|
|
557
|
+
twist: asVec(rules[cursor + 4]),
|
|
558
|
+
topSize: asVec(rules[cursor + 5]),
|
|
559
|
+
topShear: asVec(rules[cursor + 6]),
|
|
560
|
+
};
|
|
561
|
+
return 7;
|
|
562
|
+
case SHAPE_SPHERE:
|
|
563
|
+
p.shape = {
|
|
564
|
+
kind: SHAPE_SPHERE,
|
|
565
|
+
hole: num(rules[cursor + 1]) | 0,
|
|
566
|
+
cut: asVec(rules[cursor + 2]),
|
|
567
|
+
hollow: num(rules[cursor + 3]),
|
|
568
|
+
twist: asVec(rules[cursor + 4]),
|
|
569
|
+
dimple: asVec(rules[cursor + 5]),
|
|
570
|
+
};
|
|
571
|
+
return 6;
|
|
572
|
+
case SHAPE_TORUS:
|
|
573
|
+
case SHAPE_TUBE:
|
|
574
|
+
case SHAPE_RING:
|
|
575
|
+
p.shape = {
|
|
576
|
+
kind: kind,
|
|
577
|
+
hole: num(rules[cursor + 1]) | 0,
|
|
578
|
+
cut: asVec(rules[cursor + 2]),
|
|
579
|
+
hollow: num(rules[cursor + 3]),
|
|
580
|
+
twist: asVec(rules[cursor + 4]),
|
|
581
|
+
holeSize: asVec(rules[cursor + 5]),
|
|
582
|
+
topShear: asVec(rules[cursor + 6]),
|
|
583
|
+
advancedCut: asVec(rules[cursor + 7]),
|
|
584
|
+
taper: asVec(rules[cursor + 8]),
|
|
585
|
+
revolutions: num(rules[cursor + 9]),
|
|
586
|
+
radiusOffset: num(rules[cursor + 10]),
|
|
587
|
+
skew: num(rules[cursor + 11]),
|
|
588
|
+
};
|
|
589
|
+
return 12;
|
|
590
|
+
case SHAPE_SCULPT:
|
|
591
|
+
p.shape = {
|
|
592
|
+
kind: SHAPE_SCULPT,
|
|
593
|
+
map: str(rules[cursor + 1]),
|
|
594
|
+
type: num(rules[cursor + 2]) | 0,
|
|
595
|
+
};
|
|
596
|
+
return 3;
|
|
597
|
+
default:
|
|
598
|
+
// Unknown PRIM_TYPE_* kind: terminate the walk rather than guessing
|
|
599
|
+
// a slot count. Matches writePrimParamSlots' default behavior so
|
|
600
|
+
// walkSet handles both target-bearing and empty-target cases the
|
|
601
|
+
// same way.
|
|
602
|
+
return null;
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Read a single PRIM_* rule, returning the flat values it expands to and
|
|
607
|
+
* the number of slots after `param` consumed (face index, etc.). Returns
|
|
608
|
+
* `null` for unsupported constants — caller stops parsing and returns
|
|
609
|
+
* the prefix accumulated so far.
|
|
610
|
+
*/
|
|
611
|
+
export function readPrimParam(prim, param, rules, cursor) {
|
|
612
|
+
const p = prim.params;
|
|
613
|
+
switch (param) {
|
|
614
|
+
case PRIM_NAME:
|
|
615
|
+
return { values: [prim.name], consumed: 0 };
|
|
616
|
+
case PRIM_DESC:
|
|
617
|
+
return { values: [prim.description], consumed: 0 };
|
|
618
|
+
case PRIM_TEXT: {
|
|
619
|
+
const t = prim.appearance.text;
|
|
620
|
+
return { values: t ? [t.text, t.color, t.alpha] : ['', zero(), 0], consumed: 0 };
|
|
621
|
+
}
|
|
622
|
+
case PRIM_POSITION:
|
|
623
|
+
case PRIM_POS_LOCAL:
|
|
624
|
+
return { values: [p.position], consumed: 0 };
|
|
625
|
+
case PRIM_ROTATION:
|
|
626
|
+
case PRIM_ROT_LOCAL:
|
|
627
|
+
return { values: [p.rotation], consumed: 0 };
|
|
628
|
+
case PRIM_SIZE:
|
|
629
|
+
return { values: [p.size], consumed: 0 };
|
|
630
|
+
case PRIM_SLICE:
|
|
631
|
+
return { values: [p.slice], consumed: 0 };
|
|
632
|
+
case PRIM_MATERIAL:
|
|
633
|
+
return { values: [p.material], consumed: 0 };
|
|
634
|
+
case PRIM_PHYSICS:
|
|
635
|
+
return { values: [(prim.statusFlags & STATUS_PHYSICS) !== 0 ? 1 : 0], consumed: 0 };
|
|
636
|
+
case PRIM_PHANTOM:
|
|
637
|
+
return { values: [(prim.statusFlags & STATUS_PHANTOM) !== 0 ? 1 : 0], consumed: 0 };
|
|
638
|
+
case PRIM_TEMP_ON_REZ:
|
|
639
|
+
return { values: [p.tempOnRez ? 1 : 0], consumed: 0 };
|
|
640
|
+
case PRIM_PHYSICS_SHAPE_TYPE:
|
|
641
|
+
return { values: [p.physicsShapeType], consumed: 0 };
|
|
642
|
+
case PRIM_CAST_SHADOWS:
|
|
643
|
+
return { values: [p.castShadows ? 1 : 0], consumed: 0 };
|
|
644
|
+
case PRIM_ALLOW_UNSIT:
|
|
645
|
+
return { values: [p.allowUnsit ? 1 : 0], consumed: 0 };
|
|
646
|
+
case PRIM_SCRIPTED_SIT_ONLY:
|
|
647
|
+
return { values: [p.scriptedSitOnly ? 1 : 0], consumed: 0 };
|
|
648
|
+
case PRIM_SIT_FLAGS:
|
|
649
|
+
return { values: [p.sitFlags], consumed: 0 };
|
|
650
|
+
case PRIM_CLICK_ACTION:
|
|
651
|
+
return { values: [p.clickAction], consumed: 0 };
|
|
652
|
+
case PRIM_HEALTH:
|
|
653
|
+
return { values: [p.health], consumed: 0 };
|
|
654
|
+
case PRIM_DAMAGE:
|
|
655
|
+
return { values: [p.damage.amount, p.damage.type], consumed: 0 };
|
|
656
|
+
case PRIM_OMEGA:
|
|
657
|
+
return { values: [p.omega.axis, p.omega.spinrate, p.omega.gain], consumed: 0 };
|
|
658
|
+
case PRIM_POINT_LIGHT: {
|
|
659
|
+
const l = p.pointLight;
|
|
660
|
+
return { values: [l.enabled ? 1 : 0, l.color, l.intensity, l.radius, l.falloff], consumed: 0 };
|
|
661
|
+
}
|
|
662
|
+
case PRIM_REFLECTION_PROBE: {
|
|
663
|
+
const r = p.reflectionProbe;
|
|
664
|
+
return { values: [r.enabled ? 1 : 0, r.ambiance, r.clipDistance, r.flags], consumed: 0 };
|
|
665
|
+
}
|
|
666
|
+
case PRIM_PROJECTOR: {
|
|
667
|
+
const j = p.projector;
|
|
668
|
+
return { values: [j.texture, j.fov, j.focus, j.ambiance], consumed: 0 };
|
|
669
|
+
}
|
|
670
|
+
case PRIM_FLEXIBLE: {
|
|
671
|
+
const f = p.flexible;
|
|
672
|
+
return {
|
|
673
|
+
values: [f.enabled ? 1 : 0, f.softness, f.gravity, f.friction, f.wind, f.tension, f.force],
|
|
674
|
+
consumed: 0,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
case PRIM_SIT_TARGET: {
|
|
678
|
+
const s = p.sitTarget;
|
|
679
|
+
return { values: [s.enabled ? 1 : 0, s.offset, s.rotation], consumed: 0 };
|
|
680
|
+
}
|
|
681
|
+
case PRIM_TYPE:
|
|
682
|
+
return { values: readPrimType(p), consumed: 0 };
|
|
683
|
+
case PRIM_COLOR: {
|
|
684
|
+
const faces = facesOf(rules[cursor]);
|
|
685
|
+
const out = [];
|
|
686
|
+
for (const f of faces) {
|
|
687
|
+
if (!inRange(f))
|
|
688
|
+
continue;
|
|
689
|
+
out.push(p.faces[f].color, p.faces[f].alpha);
|
|
690
|
+
}
|
|
691
|
+
return { values: out, consumed: 1 };
|
|
692
|
+
}
|
|
693
|
+
case PRIM_TEXTURE: {
|
|
694
|
+
const faces = facesOf(rules[cursor]);
|
|
695
|
+
const out = [];
|
|
696
|
+
for (const f of faces) {
|
|
697
|
+
if (!inRange(f))
|
|
698
|
+
continue;
|
|
699
|
+
const fa = p.faces[f];
|
|
700
|
+
out.push(fa.texture, fa.textureRepeats, fa.textureOffsets, fa.textureRotation);
|
|
701
|
+
}
|
|
702
|
+
return { values: out, consumed: 1 };
|
|
703
|
+
}
|
|
704
|
+
case PRIM_RENDER_MATERIAL: {
|
|
705
|
+
const faces = facesOf(rules[cursor]);
|
|
706
|
+
const out = [];
|
|
707
|
+
for (const f of faces) {
|
|
708
|
+
if (!inRange(f))
|
|
709
|
+
continue;
|
|
710
|
+
out.push(p.faces[f].renderMaterial);
|
|
711
|
+
}
|
|
712
|
+
return { values: out, consumed: 1 };
|
|
713
|
+
}
|
|
714
|
+
case PRIM_FULLBRIGHT: {
|
|
715
|
+
const faces = facesOf(rules[cursor]);
|
|
716
|
+
const out = [];
|
|
717
|
+
for (const f of faces) {
|
|
718
|
+
if (!inRange(f))
|
|
719
|
+
continue;
|
|
720
|
+
out.push(p.faces[f].fullBright ? 1 : 0);
|
|
721
|
+
}
|
|
722
|
+
return { values: out, consumed: 1 };
|
|
723
|
+
}
|
|
724
|
+
case PRIM_GLOW: {
|
|
725
|
+
const faces = facesOf(rules[cursor]);
|
|
726
|
+
const out = [];
|
|
727
|
+
for (const f of faces) {
|
|
728
|
+
if (!inRange(f))
|
|
729
|
+
continue;
|
|
730
|
+
out.push(p.faces[f].glow);
|
|
731
|
+
}
|
|
732
|
+
return { values: out, consumed: 1 };
|
|
733
|
+
}
|
|
734
|
+
case PRIM_BUMP_SHINY: {
|
|
735
|
+
const faces = facesOf(rules[cursor]);
|
|
736
|
+
const out = [];
|
|
737
|
+
for (const f of faces) {
|
|
738
|
+
if (!inRange(f))
|
|
739
|
+
continue;
|
|
740
|
+
out.push(p.faces[f].bumpShiny.shiny, p.faces[f].bumpShiny.bump);
|
|
741
|
+
}
|
|
742
|
+
return { values: out, consumed: 1 };
|
|
743
|
+
}
|
|
744
|
+
case PRIM_TEXGEN: {
|
|
745
|
+
const faces = facesOf(rules[cursor]);
|
|
746
|
+
const out = [];
|
|
747
|
+
for (const f of faces) {
|
|
748
|
+
if (!inRange(f))
|
|
749
|
+
continue;
|
|
750
|
+
out.push(p.faces[f].texgen);
|
|
751
|
+
}
|
|
752
|
+
return { values: out, consumed: 1 };
|
|
753
|
+
}
|
|
754
|
+
case PRIM_NORMAL: {
|
|
755
|
+
const faces = facesOf(rules[cursor]);
|
|
756
|
+
const out = [];
|
|
757
|
+
for (const f of faces) {
|
|
758
|
+
if (!inRange(f))
|
|
759
|
+
continue;
|
|
760
|
+
const n = p.faces[f].normal;
|
|
761
|
+
out.push(n.texture, n.textureRepeats, n.textureOffsets, n.textureRotation);
|
|
762
|
+
}
|
|
763
|
+
return { values: out, consumed: 1 };
|
|
764
|
+
}
|
|
765
|
+
case PRIM_SPECULAR: {
|
|
766
|
+
const faces = facesOf(rules[cursor]);
|
|
767
|
+
const out = [];
|
|
768
|
+
for (const f of faces) {
|
|
769
|
+
if (!inRange(f))
|
|
770
|
+
continue;
|
|
771
|
+
const s = p.faces[f].specular;
|
|
772
|
+
out.push(s.texture, s.textureRepeats, s.textureOffsets, s.textureRotation, s.color, s.glossiness, s.environment);
|
|
773
|
+
}
|
|
774
|
+
return { values: out, consumed: 1 };
|
|
775
|
+
}
|
|
776
|
+
case PRIM_ALPHA_MODE: {
|
|
777
|
+
const faces = facesOf(rules[cursor]);
|
|
778
|
+
const out = [];
|
|
779
|
+
for (const f of faces) {
|
|
780
|
+
if (!inRange(f))
|
|
781
|
+
continue;
|
|
782
|
+
out.push(p.faces[f].alphaMode.mode, p.faces[f].alphaMode.cutoff);
|
|
783
|
+
}
|
|
784
|
+
return { values: out, consumed: 1 };
|
|
785
|
+
}
|
|
786
|
+
case PRIM_GLTF_BASE_COLOR: {
|
|
787
|
+
const faces = facesOf(rules[cursor]);
|
|
788
|
+
const out = [];
|
|
789
|
+
for (const f of faces) {
|
|
790
|
+
if (!inRange(f))
|
|
791
|
+
continue;
|
|
792
|
+
const g = p.faces[f].gltf.baseColor;
|
|
793
|
+
out.push(g.texture, g.textureRepeats, g.textureOffsets, g.textureRotation, g.color, g.alpha, g.alphaMode, g.alphaCutoff, g.doubleSided);
|
|
794
|
+
}
|
|
795
|
+
return { values: out, consumed: 1 };
|
|
796
|
+
}
|
|
797
|
+
case PRIM_GLTF_NORMAL: {
|
|
798
|
+
const faces = facesOf(rules[cursor]);
|
|
799
|
+
const out = [];
|
|
800
|
+
for (const f of faces) {
|
|
801
|
+
if (!inRange(f))
|
|
802
|
+
continue;
|
|
803
|
+
const g = p.faces[f].gltf.normal;
|
|
804
|
+
out.push(g.texture, g.textureRepeats, g.textureOffsets, g.textureRotation);
|
|
805
|
+
}
|
|
806
|
+
return { values: out, consumed: 1 };
|
|
807
|
+
}
|
|
808
|
+
case PRIM_GLTF_METALLIC_ROUGHNESS: {
|
|
809
|
+
const faces = facesOf(rules[cursor]);
|
|
810
|
+
const out = [];
|
|
811
|
+
for (const f of faces) {
|
|
812
|
+
if (!inRange(f))
|
|
813
|
+
continue;
|
|
814
|
+
const g = p.faces[f].gltf.metallicRoughness;
|
|
815
|
+
out.push(g.texture, g.textureRepeats, g.textureOffsets, g.textureRotation, g.metallic, g.roughness);
|
|
816
|
+
}
|
|
817
|
+
return { values: out, consumed: 1 };
|
|
818
|
+
}
|
|
819
|
+
case PRIM_GLTF_EMISSIVE: {
|
|
820
|
+
const faces = facesOf(rules[cursor]);
|
|
821
|
+
const out = [];
|
|
822
|
+
for (const f of faces) {
|
|
823
|
+
if (!inRange(f))
|
|
824
|
+
continue;
|
|
825
|
+
const g = p.faces[f].gltf.emissive;
|
|
826
|
+
out.push(g.texture, g.textureRepeats, g.textureOffsets, g.textureRotation, g.tint);
|
|
827
|
+
}
|
|
828
|
+
return { values: out, consumed: 1 };
|
|
829
|
+
}
|
|
830
|
+
case PRIM_LINK_TARGET:
|
|
831
|
+
return null;
|
|
832
|
+
default:
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function readPrimType(p) {
|
|
837
|
+
const s = p.shape;
|
|
838
|
+
if (s.kind === SHAPE_SPHERE) {
|
|
839
|
+
return [s.kind, s.hole, s.cut, s.hollow, s.twist, s.dimple];
|
|
840
|
+
}
|
|
841
|
+
if (s.kind === SHAPE_TORUS || s.kind === SHAPE_TUBE || s.kind === SHAPE_RING) {
|
|
842
|
+
return [s.kind, s.hole, s.cut, s.hollow, s.twist, s.holeSize, s.topShear, s.advancedCut, s.taper, s.revolutions, s.radiusOffset, s.skew];
|
|
843
|
+
}
|
|
844
|
+
if (s.kind === SHAPE_SCULPT) {
|
|
845
|
+
return [s.kind, s.map, s.type];
|
|
846
|
+
}
|
|
847
|
+
if (s.kind === SHAPE_BOX || s.kind === SHAPE_CYLINDER || s.kind === SHAPE_PRISM) {
|
|
848
|
+
return [s.kind, s.hole, s.cut, s.hollow, s.twist, s.topSize, s.topShear];
|
|
849
|
+
}
|
|
850
|
+
return [];
|
|
851
|
+
}
|
|
852
|
+
//# sourceMappingURL=prim-params.js.map
|