@luma.gl/graph 10.0.0-beta.3 → 10.0.0-beta.4
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/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +66 -30
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +7 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +78 -32
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.cjs +7 -0
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts +2 -0
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js +14 -0
- package/dist/arrow/gpu/arrow-gpu-vector-conversion.js.map +1 -1
- package/dist/arrow/index.cjs.map +2 -2
- package/dist/arrow/vectors/arrow-temporal-gpu-vector.cjs +1 -2
- package/dist/arrow/vectors/arrow-temporal-gpu-vector.js +2 -2
- package/dist/arrow/vectors/arrow-temporal-gpu-vector.js.map +1 -1
- package/dist/dist.dev.js +62 -27
- package/dist/dist.min.js +48 -47
- package/dist/gpu-core/gpu-command-graph-budget-controller.cjs +10 -2
- package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts +4 -0
- package/dist/gpu-core/gpu-command-graph-budget-controller.d.ts.map +1 -1
- package/dist/gpu-core/gpu-command-graph-budget-controller.js +10 -2
- package/dist/gpu-core/gpu-command-graph-budget-controller.js.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.cjs +45 -21
- package/dist/gpu-core/gpu-group-aggregation.d.ts +4 -0
- package/dist/gpu-core/gpu-group-aggregation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-group-aggregation.js +58 -24
- package/dist/gpu-core/gpu-group-aggregation.js.map +1 -1
- package/dist/gpu-core/index.cjs.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts +2 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +61 -54
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +61 -55
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +88 -13
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +11 -4
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +96 -16
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +12 -3
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts +8 -1
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.js +13 -3
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +53 -2
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts +9 -1
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +51 -0
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +24 -0
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +25 -0
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-graph/index.cjs.map +1 -1
- package/dist/gpu-graph-algorithms/benchmarks.cjs.map +2 -2
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.cjs +182 -62
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts +29 -2
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.d.ts.map +1 -1
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js +200 -64
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.js.map +1 -1
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.cjs +135 -9
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts +55 -8
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.d.ts.map +1 -1
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js +145 -14
- package/dist/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.js.map +1 -1
- package/dist/gpu-graph-algorithms/index.cjs.map +3 -3
- package/dist/gpu-physics/articulation-tree-shader.cjs +177 -0
- package/dist/gpu-physics/articulation-tree-shader.d.ts +3 -0
- package/dist/gpu-physics/articulation-tree-shader.d.ts.map +1 -0
- package/dist/gpu-physics/articulation-tree-shader.js +159 -0
- package/dist/gpu-physics/articulation-tree-shader.js.map +1 -0
- package/dist/gpu-physics/gpu-articulation-tree.cjs +203 -0
- package/dist/gpu-physics/gpu-articulation-tree.d.ts +81 -0
- package/dist/gpu-physics/gpu-articulation-tree.d.ts.map +1 -0
- package/dist/gpu-physics/gpu-articulation-tree.js +205 -0
- package/dist/gpu-physics/gpu-articulation-tree.js.map +1 -0
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +62 -0
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +12 -0
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +76 -0
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs +3 -0
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +1 -0
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js +1 -0
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.d.ts +2 -0
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-project/graph.cjs.map +2 -2
- package/dist/gpu-simple-graph/index.cjs.map +2 -2
- package/dist/gpu-sql/gpu-sql.cjs +167 -47
- package/dist/gpu-sql/gpu-sql.d.ts +6 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +187 -47
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +3 -3
- package/dist/index.cjs.map +1 -1
- package/package.json +8 -8
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +94 -40
- package/src/arrow/gpu/arrow-gpu-vector-conversion.ts +19 -0
- package/src/arrow/vectors/arrow-temporal-gpu-vector.ts +2 -2
- package/src/gpu-core/gpu-command-graph-budget-controller.ts +22 -2
- package/src/gpu-core/gpu-group-aggregation.ts +68 -30
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +9 -2
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +95 -78
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +191 -24
- package/src/gpu-dataframe/gpu-group-by-query.ts +27 -4
- package/src/gpu-dataframe/gpu-join-compiler.ts +75 -0
- package/src/gpu-dataframe/gpu-query-compiler.ts +41 -1
- package/src/gpu-graph-algorithms/README.md +4 -2
- package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path-internals.ts +248 -66
- package/src/gpu-graph-algorithms/gpu-graph-single-source-shortest-path.ts +218 -20
- package/src/gpu-physics/articulation-tree-shader.ts +169 -0
- package/src/gpu-physics/gpu-articulation-tree.ts +279 -0
- package/src/gpu-physics/gpu-rigid-body-world.ts +89 -0
- package/src/gpu-physics/index.ts +7 -0
- package/src/gpu-physics/rigid-body-joints.ts +2 -0
- package/src/gpu-sql/gpu-sql.ts +248 -57
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var articulation_tree_shader_exports = {};
|
|
19
|
+
__export(articulation_tree_shader_exports, {
|
|
20
|
+
getArticulationTreeShader: () => getArticulationTreeShader
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(articulation_tree_shader_exports);
|
|
23
|
+
function getArticulationTreeShader(count, contact = false, publishMatrices = false) {
|
|
24
|
+
return (
|
|
25
|
+
/* wgsl */
|
|
26
|
+
`
|
|
27
|
+
const N = ${count}u;
|
|
28
|
+
struct Link {
|
|
29
|
+
parentAnchor:vec4f, childAnchor:vec4f, axisMass:vec4f, inertia:vec4f, rest:vec4f
|
|
30
|
+
}
|
|
31
|
+
struct Pose { position:vec4f, rotation:vec4f, velocity:vec4f, spin:vec4f }
|
|
32
|
+
struct Settings { base:vec4f, gravityStep:vec4f, boxCenterRadius:vec4f, boxExtentsLink:vec4f }
|
|
33
|
+
@group(0) @binding(0) var<storage,read> links:array<Link>;
|
|
34
|
+
@group(0) @binding(1) var<storage,read> drives:array<vec4f>;
|
|
35
|
+
@group(0) @binding(2) var<storage,read_write> coordinates:array<vec4f>;
|
|
36
|
+
@group(0) @binding(3) var<storage,read_write> poses:array<Pose>;
|
|
37
|
+
@group(0) @binding(4) var<storage,read_write> counters:array<u32>;
|
|
38
|
+
@group(0) @binding(5) var<uniform> settings:Settings;
|
|
39
|
+
|
|
40
|
+
${publishMatrices ? "@group(0) @binding(6) var<storage,read_write> matrices:array<mat4x4f>;" : ""}
|
|
41
|
+
var<private> angle:array<f32,N>;
|
|
42
|
+
var<private> speed:array<f32,N>;
|
|
43
|
+
var<private> solved:array<Pose,N>;
|
|
44
|
+
var<private> axis:array<vec3f,N>;
|
|
45
|
+
var<private> pivot:array<vec3f,N>;
|
|
46
|
+
var<private> acceleration:array<vec3f,N>;
|
|
47
|
+
var<private> angularAcceleration:array<vec3f,N>;
|
|
48
|
+
fn rotate(q:vec4f,v:vec3f)->vec3f{return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}
|
|
49
|
+
fn product(a:vec4f,b:vec4f)->vec4f{return vec4f(a.w*b.xyz+b.w*a.xyz+cross(a.xyz,b.xyz),a.w*b.w-dot(a.xyz,b.xyz));}
|
|
50
|
+
fn inertia(i:u32,v:vec3f)->vec3f{
|
|
51
|
+
let q=solved[i].rotation;
|
|
52
|
+
return rotate(q,links[i].inertia.xyz*rotate(vec4f(-q.xyz,q.w),v));
|
|
53
|
+
}
|
|
54
|
+
// Propagate pose, twist and bias acceleration (joint accelerations held at zero).
|
|
55
|
+
fn kinematics(){
|
|
56
|
+
for(var i=0u;i<N;i++){
|
|
57
|
+
let link=links[i];let parent=i32(link.parentAnchor.w);
|
|
58
|
+
var previous=Pose(vec4f(settings.base.xyz,0),vec4f(0,0,0,1),vec4f(0),vec4f(0));
|
|
59
|
+
var linearBias=vec3f(0);var angularBias=vec3f(0);
|
|
60
|
+
if(parent>=0){previous=solved[parent];linearBias=acceleration[parent];angularBias=angularAcceleration[parent];}
|
|
61
|
+
let offset=rotate(previous.rotation,link.parentAnchor.xyz);
|
|
62
|
+
pivot[i]=previous.position.xyz+offset;
|
|
63
|
+
axis[i]=rotate(previous.rotation,link.axisMass.xyz);
|
|
64
|
+
let halfAngle=0.5*angle[i];
|
|
65
|
+
let rotation=normalize(product(product(previous.rotation,vec4f(link.axisMass.xyz*sin(halfAngle),cos(halfAngle))),link.rest));
|
|
66
|
+
let radius=rotate(rotation,-link.childAnchor.xyz);
|
|
67
|
+
let parentSpin=previous.spin.xyz;
|
|
68
|
+
let spin=parentSpin+axis[i]*speed[i];
|
|
69
|
+
let velocity=previous.velocity.xyz+cross(parentSpin,offset)+cross(spin,radius);
|
|
70
|
+
let pivotBias=linearBias+cross(angularBias,offset)+cross(parentSpin,cross(parentSpin,offset));
|
|
71
|
+
angularAcceleration[i]=angularBias+cross(parentSpin,axis[i]*speed[i]);
|
|
72
|
+
acceleration[i]=pivotBias+cross(angularAcceleration[i],radius)+cross(spin,cross(spin,radius));
|
|
73
|
+
solved[i]=Pose(vec4f(pivot[i]+radius,1),rotation,vec4f(velocity,0),vec4f(spin,0));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
fn finite(v:vec4f)->bool{return all(abs(v)<=vec4f(3.4028234e38));}
|
|
77
|
+
@compute @workgroup_size(1) fn main(){
|
|
78
|
+
if(counters[1]!=0u){return;}
|
|
79
|
+
let dt=settings.gravityStep.w;
|
|
80
|
+
var mass:array<array<f32,N>,N>;var inverse:array<array<f32,N>,N>;
|
|
81
|
+
var force:array<f32,N>;var impulse:array<f32,N>;
|
|
82
|
+
for(var i=0u;i<N;i++){
|
|
83
|
+
angle[i]=coordinates[i].x;speed[i]=coordinates[i].y;inverse[i][i]=1;
|
|
84
|
+
// A fixed link contributes its mass to ancestors and has no generalized motion.
|
|
85
|
+
if(dot(links[i].axisMass.xyz,links[i].axisMass.xyz)==0){mass[i][i]=1;}
|
|
86
|
+
}
|
|
87
|
+
kinematics();
|
|
88
|
+
for(var body=0u;body<N;body++){
|
|
89
|
+
let center=solved[body].position.xyz;let spin=solved[body].spin.xyz;
|
|
90
|
+
let load=links[body].axisMass.w*(settings.gravityStep.xyz-acceleration[body]);
|
|
91
|
+
let moment= -inertia(body,angularAcceleration[body])-cross(spin,inertia(body,spin));
|
|
92
|
+
for(var row=i32(body);row>=0;row=i32(links[row].parentAnchor.w)){
|
|
93
|
+
let linear=cross(axis[row],center-pivot[row]);
|
|
94
|
+
force[row]+=dot(linear,load)+dot(axis[row],moment);
|
|
95
|
+
let angularMass=inertia(body,axis[row]);
|
|
96
|
+
for(var column=i32(body);column>=0;column=i32(links[column].parentAnchor.w)){
|
|
97
|
+
mass[row][column]+=links[body].axisMass.w*dot(linear,cross(axis[column],center-pivot[column]))+dot(angularMass,axis[column]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Positive definite joint inertia admits elimination without pivoting.
|
|
102
|
+
for(var k=0u;k<N;k++){
|
|
103
|
+
let diagonal=mass[k][k];if(!(diagonal>0)){counters[1]=1u;return;}
|
|
104
|
+
for(var j=0u;j<N;j++){mass[k][j]/=diagonal;inverse[k][j]/=diagonal;}
|
|
105
|
+
for(var i=0u;i<N;i++){if(i!=k){
|
|
106
|
+
let factor=mass[i][k];
|
|
107
|
+
for(var j=0u;j<N;j++){mass[i][j]-=factor*mass[k][j];inverse[i][j]-=factor*inverse[k][j];}
|
|
108
|
+
}}
|
|
109
|
+
}
|
|
110
|
+
for(var i=0u;i<N;i++){for(var j=0u;j<N;j++){speed[i]+=dt*inverse[i][j]*force[j];}}
|
|
111
|
+
${contact ? `// Closest point on a finite AABB. Inside, use the nearest exit face.
|
|
112
|
+
let body=u32(settings.boxExtentsLink.w);
|
|
113
|
+
let center=solved[body].position.xyz;
|
|
114
|
+
let local=center-settings.boxCenterRadius.xyz;
|
|
115
|
+
let extent=settings.boxExtentsLink.xyz;
|
|
116
|
+
let outside=local-clamp(local,-extent,extent);
|
|
117
|
+
let distance=length(outside);
|
|
118
|
+
var normal=vec3f(0);
|
|
119
|
+
var gap=distance-settings.boxCenterRadius.w;
|
|
120
|
+
if(distance>0.0){normal=outside/distance;}else{
|
|
121
|
+
let depth=extent-abs(local);var face=0u;
|
|
122
|
+
if(depth.y<depth.x){face=1u;}if(depth.z<depth[face]){face=2u;}
|
|
123
|
+
normal[face]=select(-1.0,1.0,local[face]>=0.0);
|
|
124
|
+
gap= -depth[face]-settings.boxCenterRadius.w;
|
|
125
|
+
}
|
|
126
|
+
var jacobian:array<f32,N>;var response:array<f32,N>;
|
|
127
|
+
for(var joint=i32(body);joint>=0;joint=i32(links[joint].parentAnchor.w)){
|
|
128
|
+
jacobian[joint]=dot(normal,cross(axis[joint],center-pivot[joint]));
|
|
129
|
+
}
|
|
130
|
+
var inverseContactMass=0.0;
|
|
131
|
+
for(var row=0u;row<N;row++){
|
|
132
|
+
for(var column=0u;column<N;column++){response[row]+=inverse[row][column]*jacobian[column];}
|
|
133
|
+
inverseContactMass+=jacobian[row]*response[row];
|
|
134
|
+
}
|
|
135
|
+
// Speculate across the remaining gap; correct existing overlap gradually.
|
|
136
|
+
let separationSpeed=select(-gap/dt,min(2.0,0.2*max(0.0,-gap-0.0001)/dt),gap<0.0);
|
|
137
|
+
var normalImpulse=0.0;` : ""}
|
|
138
|
+
// Implicit spring/damper impulses in coupled joint space. Project each update
|
|
139
|
+
// onto its torque budget and propagate the resulting velocity change to all axes.
|
|
140
|
+
for(var sweep=0u;sweep<64u;sweep++){
|
|
141
|
+
var change=0.0;
|
|
142
|
+
for(var i=0u;i<N;i++){
|
|
143
|
+
let drive=drives[i];let resistance=dt*(drive.z+dt*drive.y);
|
|
144
|
+
let residual=dt*drive.y*(drive.x-angle[i])-resistance*speed[i]-impulse[i];
|
|
145
|
+
let next=clamp(impulse[i]+residual/(1.0+resistance*inverse[i][i]),-dt*drive.w,dt*drive.w);
|
|
146
|
+
let delta=next-impulse[i];impulse[i]=next;change=max(change,abs(delta));
|
|
147
|
+
for(var j=0u;j<N;j++){speed[j]+=inverse[j][i]*delta;}
|
|
148
|
+
}
|
|
149
|
+
${contact ? `if(inverseContactMass>1e-9){
|
|
150
|
+
var normalSpeed=0.0;
|
|
151
|
+
for(var j=0u;j<N;j++){normalSpeed+=jacobian[j]*speed[j];}
|
|
152
|
+
let next=max(0.0,normalImpulse+(separationSpeed-normalSpeed)/inverseContactMass);
|
|
153
|
+
let delta=next-normalImpulse;normalImpulse=next;change=max(change,abs(delta));
|
|
154
|
+
for(var j=0u;j<N;j++){speed[j]+=response[j]*delta;}
|
|
155
|
+
}` : ""}
|
|
156
|
+
if(change<1e-7){break;}
|
|
157
|
+
}
|
|
158
|
+
for(var i=0u;i<N;i++){angle[i]+=dt*speed[i];}
|
|
159
|
+
kinematics();
|
|
160
|
+
for(var i=0u;i<N;i++){let pose=solved[i];
|
|
161
|
+
if(!finite(vec4f(angle[i],speed[i],impulse[i]/dt,0))||!finite(pose.position)||!finite(pose.rotation)||!finite(pose.velocity)||!finite(pose.spin)){counters[1]=1u;return;}
|
|
162
|
+
}
|
|
163
|
+
for(var i=0u;i<N;i++){coordinates[i]=vec4f(angle[i],speed[i],impulse[i]/dt,0);poses[i]=solved[i];}
|
|
164
|
+
${contact ? "counters[2]=bitcast<u32>(normalImpulse/dt);" : ""}
|
|
165
|
+
${publishMatrices ? `for(var i=0u;i<N;i++){
|
|
166
|
+
let pose=solved[i];let q=pose.rotation;
|
|
167
|
+
matrices[i]=mat4x4f(vec4f(rotate(q,vec3f(1,0,0)),0),vec4f(rotate(q,vec3f(0,1,0)),0),vec4f(rotate(q,vec3f(0,0,1)),0),pose.position);
|
|
168
|
+
}` : ""}
|
|
169
|
+
counters[0]++;
|
|
170
|
+
}
|
|
171
|
+
`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
getArticulationTreeShader
|
|
177
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"articulation-tree-shader.d.ts","sourceRoot":"","sources":["../../src/gpu-physics/articulation-tree-shader.ts"],"names":[],"mappings":"AAIA,uFAAuF;AACvF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EACb,OAAO,UAAQ,EACf,eAAe,UAAQ,GACtB,MAAM,CA+JR"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
/** Fixed-base joint-space forward dynamics. One invocation owns a whole small tree. */
|
|
5
|
+
export function getArticulationTreeShader(count, contact = false, publishMatrices = false) {
|
|
6
|
+
return /* wgsl */ `
|
|
7
|
+
const N = ${count}u;
|
|
8
|
+
struct Link {
|
|
9
|
+
parentAnchor:vec4f, childAnchor:vec4f, axisMass:vec4f, inertia:vec4f, rest:vec4f
|
|
10
|
+
}
|
|
11
|
+
struct Pose { position:vec4f, rotation:vec4f, velocity:vec4f, spin:vec4f }
|
|
12
|
+
struct Settings { base:vec4f, gravityStep:vec4f, boxCenterRadius:vec4f, boxExtentsLink:vec4f }
|
|
13
|
+
@group(0) @binding(0) var<storage,read> links:array<Link>;
|
|
14
|
+
@group(0) @binding(1) var<storage,read> drives:array<vec4f>;
|
|
15
|
+
@group(0) @binding(2) var<storage,read_write> coordinates:array<vec4f>;
|
|
16
|
+
@group(0) @binding(3) var<storage,read_write> poses:array<Pose>;
|
|
17
|
+
@group(0) @binding(4) var<storage,read_write> counters:array<u32>;
|
|
18
|
+
@group(0) @binding(5) var<uniform> settings:Settings;
|
|
19
|
+
|
|
20
|
+
${publishMatrices ? '@group(0) @binding(6) var<storage,read_write> matrices:array<mat4x4f>;' : ''}
|
|
21
|
+
var<private> angle:array<f32,N>;
|
|
22
|
+
var<private> speed:array<f32,N>;
|
|
23
|
+
var<private> solved:array<Pose,N>;
|
|
24
|
+
var<private> axis:array<vec3f,N>;
|
|
25
|
+
var<private> pivot:array<vec3f,N>;
|
|
26
|
+
var<private> acceleration:array<vec3f,N>;
|
|
27
|
+
var<private> angularAcceleration:array<vec3f,N>;
|
|
28
|
+
fn rotate(q:vec4f,v:vec3f)->vec3f{return v+2.0*cross(q.xyz,cross(q.xyz,v)+q.w*v);}
|
|
29
|
+
fn product(a:vec4f,b:vec4f)->vec4f{return vec4f(a.w*b.xyz+b.w*a.xyz+cross(a.xyz,b.xyz),a.w*b.w-dot(a.xyz,b.xyz));}
|
|
30
|
+
fn inertia(i:u32,v:vec3f)->vec3f{
|
|
31
|
+
let q=solved[i].rotation;
|
|
32
|
+
return rotate(q,links[i].inertia.xyz*rotate(vec4f(-q.xyz,q.w),v));
|
|
33
|
+
}
|
|
34
|
+
// Propagate pose, twist and bias acceleration (joint accelerations held at zero).
|
|
35
|
+
fn kinematics(){
|
|
36
|
+
for(var i=0u;i<N;i++){
|
|
37
|
+
let link=links[i];let parent=i32(link.parentAnchor.w);
|
|
38
|
+
var previous=Pose(vec4f(settings.base.xyz,0),vec4f(0,0,0,1),vec4f(0),vec4f(0));
|
|
39
|
+
var linearBias=vec3f(0);var angularBias=vec3f(0);
|
|
40
|
+
if(parent>=0){previous=solved[parent];linearBias=acceleration[parent];angularBias=angularAcceleration[parent];}
|
|
41
|
+
let offset=rotate(previous.rotation,link.parentAnchor.xyz);
|
|
42
|
+
pivot[i]=previous.position.xyz+offset;
|
|
43
|
+
axis[i]=rotate(previous.rotation,link.axisMass.xyz);
|
|
44
|
+
let halfAngle=0.5*angle[i];
|
|
45
|
+
let rotation=normalize(product(product(previous.rotation,vec4f(link.axisMass.xyz*sin(halfAngle),cos(halfAngle))),link.rest));
|
|
46
|
+
let radius=rotate(rotation,-link.childAnchor.xyz);
|
|
47
|
+
let parentSpin=previous.spin.xyz;
|
|
48
|
+
let spin=parentSpin+axis[i]*speed[i];
|
|
49
|
+
let velocity=previous.velocity.xyz+cross(parentSpin,offset)+cross(spin,radius);
|
|
50
|
+
let pivotBias=linearBias+cross(angularBias,offset)+cross(parentSpin,cross(parentSpin,offset));
|
|
51
|
+
angularAcceleration[i]=angularBias+cross(parentSpin,axis[i]*speed[i]);
|
|
52
|
+
acceleration[i]=pivotBias+cross(angularAcceleration[i],radius)+cross(spin,cross(spin,radius));
|
|
53
|
+
solved[i]=Pose(vec4f(pivot[i]+radius,1),rotation,vec4f(velocity,0),vec4f(spin,0));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
fn finite(v:vec4f)->bool{return all(abs(v)<=vec4f(3.4028234e38));}
|
|
57
|
+
@compute @workgroup_size(1) fn main(){
|
|
58
|
+
if(counters[1]!=0u){return;}
|
|
59
|
+
let dt=settings.gravityStep.w;
|
|
60
|
+
var mass:array<array<f32,N>,N>;var inverse:array<array<f32,N>,N>;
|
|
61
|
+
var force:array<f32,N>;var impulse:array<f32,N>;
|
|
62
|
+
for(var i=0u;i<N;i++){
|
|
63
|
+
angle[i]=coordinates[i].x;speed[i]=coordinates[i].y;inverse[i][i]=1;
|
|
64
|
+
// A fixed link contributes its mass to ancestors and has no generalized motion.
|
|
65
|
+
if(dot(links[i].axisMass.xyz,links[i].axisMass.xyz)==0){mass[i][i]=1;}
|
|
66
|
+
}
|
|
67
|
+
kinematics();
|
|
68
|
+
for(var body=0u;body<N;body++){
|
|
69
|
+
let center=solved[body].position.xyz;let spin=solved[body].spin.xyz;
|
|
70
|
+
let load=links[body].axisMass.w*(settings.gravityStep.xyz-acceleration[body]);
|
|
71
|
+
let moment= -inertia(body,angularAcceleration[body])-cross(spin,inertia(body,spin));
|
|
72
|
+
for(var row=i32(body);row>=0;row=i32(links[row].parentAnchor.w)){
|
|
73
|
+
let linear=cross(axis[row],center-pivot[row]);
|
|
74
|
+
force[row]+=dot(linear,load)+dot(axis[row],moment);
|
|
75
|
+
let angularMass=inertia(body,axis[row]);
|
|
76
|
+
for(var column=i32(body);column>=0;column=i32(links[column].parentAnchor.w)){
|
|
77
|
+
mass[row][column]+=links[body].axisMass.w*dot(linear,cross(axis[column],center-pivot[column]))+dot(angularMass,axis[column]);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Positive definite joint inertia admits elimination without pivoting.
|
|
82
|
+
for(var k=0u;k<N;k++){
|
|
83
|
+
let diagonal=mass[k][k];if(!(diagonal>0)){counters[1]=1u;return;}
|
|
84
|
+
for(var j=0u;j<N;j++){mass[k][j]/=diagonal;inverse[k][j]/=diagonal;}
|
|
85
|
+
for(var i=0u;i<N;i++){if(i!=k){
|
|
86
|
+
let factor=mass[i][k];
|
|
87
|
+
for(var j=0u;j<N;j++){mass[i][j]-=factor*mass[k][j];inverse[i][j]-=factor*inverse[k][j];}
|
|
88
|
+
}}
|
|
89
|
+
}
|
|
90
|
+
for(var i=0u;i<N;i++){for(var j=0u;j<N;j++){speed[i]+=dt*inverse[i][j]*force[j];}}
|
|
91
|
+
${contact
|
|
92
|
+
? `// Closest point on a finite AABB. Inside, use the nearest exit face.
|
|
93
|
+
let body=u32(settings.boxExtentsLink.w);
|
|
94
|
+
let center=solved[body].position.xyz;
|
|
95
|
+
let local=center-settings.boxCenterRadius.xyz;
|
|
96
|
+
let extent=settings.boxExtentsLink.xyz;
|
|
97
|
+
let outside=local-clamp(local,-extent,extent);
|
|
98
|
+
let distance=length(outside);
|
|
99
|
+
var normal=vec3f(0);
|
|
100
|
+
var gap=distance-settings.boxCenterRadius.w;
|
|
101
|
+
if(distance>0.0){normal=outside/distance;}else{
|
|
102
|
+
let depth=extent-abs(local);var face=0u;
|
|
103
|
+
if(depth.y<depth.x){face=1u;}if(depth.z<depth[face]){face=2u;}
|
|
104
|
+
normal[face]=select(-1.0,1.0,local[face]>=0.0);
|
|
105
|
+
gap= -depth[face]-settings.boxCenterRadius.w;
|
|
106
|
+
}
|
|
107
|
+
var jacobian:array<f32,N>;var response:array<f32,N>;
|
|
108
|
+
for(var joint=i32(body);joint>=0;joint=i32(links[joint].parentAnchor.w)){
|
|
109
|
+
jacobian[joint]=dot(normal,cross(axis[joint],center-pivot[joint]));
|
|
110
|
+
}
|
|
111
|
+
var inverseContactMass=0.0;
|
|
112
|
+
for(var row=0u;row<N;row++){
|
|
113
|
+
for(var column=0u;column<N;column++){response[row]+=inverse[row][column]*jacobian[column];}
|
|
114
|
+
inverseContactMass+=jacobian[row]*response[row];
|
|
115
|
+
}
|
|
116
|
+
// Speculate across the remaining gap; correct existing overlap gradually.
|
|
117
|
+
let separationSpeed=select(-gap/dt,min(2.0,0.2*max(0.0,-gap-0.0001)/dt),gap<0.0);
|
|
118
|
+
var normalImpulse=0.0;`
|
|
119
|
+
: ''}
|
|
120
|
+
// Implicit spring/damper impulses in coupled joint space. Project each update
|
|
121
|
+
// onto its torque budget and propagate the resulting velocity change to all axes.
|
|
122
|
+
for(var sweep=0u;sweep<64u;sweep++){
|
|
123
|
+
var change=0.0;
|
|
124
|
+
for(var i=0u;i<N;i++){
|
|
125
|
+
let drive=drives[i];let resistance=dt*(drive.z+dt*drive.y);
|
|
126
|
+
let residual=dt*drive.y*(drive.x-angle[i])-resistance*speed[i]-impulse[i];
|
|
127
|
+
let next=clamp(impulse[i]+residual/(1.0+resistance*inverse[i][i]),-dt*drive.w,dt*drive.w);
|
|
128
|
+
let delta=next-impulse[i];impulse[i]=next;change=max(change,abs(delta));
|
|
129
|
+
for(var j=0u;j<N;j++){speed[j]+=inverse[j][i]*delta;}
|
|
130
|
+
}
|
|
131
|
+
${contact
|
|
132
|
+
? `if(inverseContactMass>1e-9){
|
|
133
|
+
var normalSpeed=0.0;
|
|
134
|
+
for(var j=0u;j<N;j++){normalSpeed+=jacobian[j]*speed[j];}
|
|
135
|
+
let next=max(0.0,normalImpulse+(separationSpeed-normalSpeed)/inverseContactMass);
|
|
136
|
+
let delta=next-normalImpulse;normalImpulse=next;change=max(change,abs(delta));
|
|
137
|
+
for(var j=0u;j<N;j++){speed[j]+=response[j]*delta;}
|
|
138
|
+
}`
|
|
139
|
+
: ''}
|
|
140
|
+
if(change<1e-7){break;}
|
|
141
|
+
}
|
|
142
|
+
for(var i=0u;i<N;i++){angle[i]+=dt*speed[i];}
|
|
143
|
+
kinematics();
|
|
144
|
+
for(var i=0u;i<N;i++){let pose=solved[i];
|
|
145
|
+
if(!finite(vec4f(angle[i],speed[i],impulse[i]/dt,0))||!finite(pose.position)||!finite(pose.rotation)||!finite(pose.velocity)||!finite(pose.spin)){counters[1]=1u;return;}
|
|
146
|
+
}
|
|
147
|
+
for(var i=0u;i<N;i++){coordinates[i]=vec4f(angle[i],speed[i],impulse[i]/dt,0);poses[i]=solved[i];}
|
|
148
|
+
${contact ? 'counters[2]=bitcast<u32>(normalImpulse/dt);' : ''}
|
|
149
|
+
${publishMatrices
|
|
150
|
+
? `for(var i=0u;i<N;i++){
|
|
151
|
+
let pose=solved[i];let q=pose.rotation;
|
|
152
|
+
matrices[i]=mat4x4f(vec4f(rotate(q,vec3f(1,0,0)),0),vec4f(rotate(q,vec3f(0,1,0)),0),vec4f(rotate(q,vec3f(0,0,1)),0),pose.position);
|
|
153
|
+
}`
|
|
154
|
+
: ''}
|
|
155
|
+
counters[0]++;
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=articulation-tree-shader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"articulation-tree-shader.js","sourceRoot":"","sources":["../../src/gpu-physics/articulation-tree-shader.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,uFAAuF;AACvF,MAAM,UAAU,yBAAyB,CACvC,KAAa,EACb,OAAO,GAAG,KAAK,EACf,eAAe,GAAG,KAAK;IAEvB,OAAO,UAAU,CAAC;YACR,KAAK;;;;;;;;;;;;;EAaf,eAAe,CAAC,CAAC,CAAC,wEAAwE,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwE9F,OAAO;QACL,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;wBA0BiB;QACnB,CAAC,CAAC,EACN;;;;;;;;;;;;IAaG,OAAO;QACL,CAAC,CAAC;;;;;;IAMJ;QACE,CAAC,CAAC,EACN;;;;;;;;;GASC,OAAO,CAAC,CAAC,CAAC,6CAA6C,CAAC,CAAC,CAAC,EAAE;GAE5D,eAAe;QACb,CAAC,CAAC;;;GAGJ;QACE,CAAC,CAAC,EACN;;;CAGA,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var gpu_articulation_tree_exports = {};
|
|
19
|
+
__export(gpu_articulation_tree_exports, {
|
|
20
|
+
GPUArticulationTree: () => GPUArticulationTree
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(gpu_articulation_tree_exports);
|
|
23
|
+
var import_core = require("@luma.gl/core");
|
|
24
|
+
var import_bound_kernel = require("../gpu-core/utils/bound-kernel.cjs");
|
|
25
|
+
var import_articulation_tree_shader = require("./articulation-tree-shader.cjs");
|
|
26
|
+
class GPUArticulationTree {
|
|
27
|
+
timeStep;
|
|
28
|
+
id;
|
|
29
|
+
links;
|
|
30
|
+
indices = /* @__PURE__ */ new Map();
|
|
31
|
+
buffers = [];
|
|
32
|
+
base;
|
|
33
|
+
gravity;
|
|
34
|
+
contact;
|
|
35
|
+
publishMatrices;
|
|
36
|
+
/** Column-major world transforms in link order, available after registration with publishMatrices. */
|
|
37
|
+
get poseMatrices() {
|
|
38
|
+
return this.buffers[6] ?? null;
|
|
39
|
+
}
|
|
40
|
+
destroyed = false;
|
|
41
|
+
constructor(props) {
|
|
42
|
+
this.id = props.id ?? "articulation-tree";
|
|
43
|
+
this.timeStep = props.timeStep ?? 1 / 120;
|
|
44
|
+
this.contact = structuredClone(props.contact);
|
|
45
|
+
this.publishMatrices = Boolean(props.publishMatrices);
|
|
46
|
+
this.links = structuredClone([...props.links]);
|
|
47
|
+
this.base = [...props.base ?? [0, 0, 0]];
|
|
48
|
+
this.gravity = [...props.gravity ?? [0, 0, -9.81]];
|
|
49
|
+
const finite = (x) => Number.isFinite(Math.fround(x));
|
|
50
|
+
if (!this.links.length || this.links.length > 16 || !finite(this.timeStep) || Math.fround(this.timeStep) <= 0 || ![...this.base, ...this.gravity].every(finite))
|
|
51
|
+
throw new Error("Invalid articulation settings");
|
|
52
|
+
for (const [index, link] of this.links.entries()) {
|
|
53
|
+
if (!link.id || this.indices.has(link.id) || !Number.isInteger(link.parent) || link.parent < -1 || link.parent >= index || !finite(link.mass) || Math.fround(link.mass) <= 0 || !link.inertia.every((value) => finite(value) && Math.fround(value) > 0) || ![...link.parentAnchor, ...link.childAnchor, link.angle ?? 0, link.speed ?? 0].every(finite) || (link.axis ? !(Math.abs(Math.hypot(...link.axis) - 1) < 1e-6) : Boolean(link.angle || link.speed)) || link.restOrientation && !(Math.abs(Math.hypot(...link.restOrientation) - 1) < 1e-6))
|
|
54
|
+
throw new Error("Invalid articulation link");
|
|
55
|
+
this.indices.set(link.id, index);
|
|
56
|
+
}
|
|
57
|
+
const contact = this.contact;
|
|
58
|
+
if (contact && (!this.indices.has(contact.link) || !contact.center.every(finite) || ![contact.radius, ...contact.halfExtents].every((value) => finite(value) && Math.fround(value) > 0)))
|
|
59
|
+
throw new Error("Invalid articulation contact");
|
|
60
|
+
}
|
|
61
|
+
/** Register one simulation step. The output pose buffer uses four vec4s per link: COM, quaternion, velocity, spin. */
|
|
62
|
+
addToGraph(graph) {
|
|
63
|
+
var _a, _b, _c;
|
|
64
|
+
if (this.destroyed || this.buffers.length)
|
|
65
|
+
throw new Error("Inactive or already registered articulation");
|
|
66
|
+
const names = ["links", "drives", "coordinates", "poses", "counters", "settings"];
|
|
67
|
+
const data = [
|
|
68
|
+
new Float32Array(this.links.flatMap((link) => [
|
|
69
|
+
...link.parentAnchor,
|
|
70
|
+
link.parent,
|
|
71
|
+
...link.childAnchor,
|
|
72
|
+
0,
|
|
73
|
+
...link.axis ?? [0, 0, 0],
|
|
74
|
+
link.mass,
|
|
75
|
+
...link.inertia,
|
|
76
|
+
0,
|
|
77
|
+
...link.restOrientation ?? [0, 0, 0, 1]
|
|
78
|
+
])),
|
|
79
|
+
new Float32Array(this.links.length * 4),
|
|
80
|
+
new Float32Array(this.links.flatMap((link) => [link.angle ?? 0, link.speed ?? 0, 0, 0])),
|
|
81
|
+
new Float32Array(this.links.length * 16),
|
|
82
|
+
new Uint32Array(4),
|
|
83
|
+
new Float32Array([
|
|
84
|
+
...this.base,
|
|
85
|
+
0,
|
|
86
|
+
...this.gravity,
|
|
87
|
+
this.timeStep,
|
|
88
|
+
...((_a = this.contact) == null ? void 0 : _a.center) ?? [0, 0, 0],
|
|
89
|
+
((_b = this.contact) == null ? void 0 : _b.radius) ?? 0,
|
|
90
|
+
...((_c = this.contact) == null ? void 0 : _c.halfExtents) ?? [0, 0, 0],
|
|
91
|
+
this.contact ? this.indices.get(this.contact.link) : 0
|
|
92
|
+
])
|
|
93
|
+
];
|
|
94
|
+
if (this.publishMatrices) {
|
|
95
|
+
names.push("matrices");
|
|
96
|
+
data.push(new Float32Array(this.links.length * 16));
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const handles = data.map((values, index) => {
|
|
100
|
+
const usage = (index === 5 ? import_core.Buffer.UNIFORM : import_core.Buffer.STORAGE) | import_core.Buffer.COPY_SRC | import_core.Buffer.COPY_DST;
|
|
101
|
+
const buffer = graph.device.createBuffer({
|
|
102
|
+
id: this.id + "-" + names[index],
|
|
103
|
+
data: values,
|
|
104
|
+
usage
|
|
105
|
+
});
|
|
106
|
+
this.buffers.push(buffer);
|
|
107
|
+
return graph.importBuffer({ id: buffer.id, byteLength: buffer.byteLength, usage }, buffer);
|
|
108
|
+
});
|
|
109
|
+
const resources = handles.map((buffer, index) => ({
|
|
110
|
+
buffer,
|
|
111
|
+
usage: index === 5 ? "uniform" : index < 2 ? "storage-read" : "storage-read-write"
|
|
112
|
+
}));
|
|
113
|
+
const shaderLayout = {
|
|
114
|
+
attributes: [],
|
|
115
|
+
bindings: names.map((name, location) => location === 5 ? { name, location, group: 0, type: "uniform" } : { name, location, group: 0, type: location < 2 ? "read-only-storage" : "storage" })
|
|
116
|
+
};
|
|
117
|
+
const props = {
|
|
118
|
+
source: (0, import_articulation_tree_shader.getArticulationTreeShader)(this.links.length, Boolean(this.contact), this.publishMatrices),
|
|
119
|
+
shaderLayout
|
|
120
|
+
};
|
|
121
|
+
const executable = (bound) => ({
|
|
122
|
+
encode: ({ computePass, getBuffer }) => {
|
|
123
|
+
const bindings = {};
|
|
124
|
+
names.forEach((name, index) => {
|
|
125
|
+
bindings[name] = getBuffer(handles[index]);
|
|
126
|
+
});
|
|
127
|
+
bound.kernel.dispatch(computePass, { bindings, x: 1 });
|
|
128
|
+
},
|
|
129
|
+
destroy: () => bound.kernel.destroy()
|
|
130
|
+
});
|
|
131
|
+
graph.addComputePass({
|
|
132
|
+
id: handles[0].id + "-joint-space",
|
|
133
|
+
description: "Integrate joint-space dynamics and publish articulated link poses.",
|
|
134
|
+
resources,
|
|
135
|
+
compile: ({ device }) => executable((0, import_bound_kernel.createBoundKernel)(device, props)),
|
|
136
|
+
compileAsync: async ({ device }) => executable(await (0, import_bound_kernel.createBoundKernelAsync)(device, props))
|
|
137
|
+
});
|
|
138
|
+
return handles[3];
|
|
139
|
+
} catch (error) {
|
|
140
|
+
this.destroy();
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
driveIndex(id) {
|
|
145
|
+
const index = this.indices.get(id);
|
|
146
|
+
if (this.destroyed || !this.buffers.length || index === void 0 || !this.links[index].axis)
|
|
147
|
+
throw new Error("Inactive or missing revolute drive");
|
|
148
|
+
return index;
|
|
149
|
+
}
|
|
150
|
+
/** Update the named revolute drive between submitted steps. */
|
|
151
|
+
setDrive(id, drive) {
|
|
152
|
+
const index = this.driveIndex(id);
|
|
153
|
+
const values = new Float32Array([
|
|
154
|
+
drive.angle,
|
|
155
|
+
drive.stiffness,
|
|
156
|
+
drive.damping,
|
|
157
|
+
drive.maximumTorque
|
|
158
|
+
]);
|
|
159
|
+
if (!values.every(Number.isFinite) || values.slice(1).some((value) => value < 0))
|
|
160
|
+
throw new Error("Invalid articulation drive");
|
|
161
|
+
this.buffers[1].write(values, index * 16);
|
|
162
|
+
}
|
|
163
|
+
/** Signed motor torque during the most recently accepted step. */
|
|
164
|
+
async readTorque(id) {
|
|
165
|
+
const index = this.driveIndex(id);
|
|
166
|
+
const bytes = await this.buffers[2].readAsync(index * 16 + 8, 4);
|
|
167
|
+
return new DataView(bytes.buffer, bytes.byteOffset, 4).getFloat32(0, true);
|
|
168
|
+
}
|
|
169
|
+
/** Read COM poses and world-space velocities in link order after stepping. */
|
|
170
|
+
async readState() {
|
|
171
|
+
const bytes = await this.buffers[3].readAsync();
|
|
172
|
+
const values = new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
173
|
+
return this.links.map((_, index) => {
|
|
174
|
+
const start = index * 16;
|
|
175
|
+
return {
|
|
176
|
+
position: Array.from(values.subarray(start, start + 3)),
|
|
177
|
+
orientation: Array.from(values.subarray(start + 4, start + 8)),
|
|
178
|
+
velocity: Array.from(values.subarray(start + 8, start + 11)),
|
|
179
|
+
angularVelocity: Array.from(values.subarray(start + 12, start + 15))
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** Numerical failure latches and preserves the last accepted state. */
|
|
184
|
+
async readSimulationDiagnostics() {
|
|
185
|
+
const bytes = await this.buffers[4].readAsync();
|
|
186
|
+
const values = new Uint32Array(bytes.buffer, bytes.byteOffset, 2);
|
|
187
|
+
return {
|
|
188
|
+
steps: values[0],
|
|
189
|
+
complete: values[1] === 0,
|
|
190
|
+
...this.contact ? { normalForce: new DataView(bytes.buffer, bytes.byteOffset).getFloat32(8, true) } : {}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
destroy() {
|
|
194
|
+
this.destroyed = true;
|
|
195
|
+
for (const buffer of this.buffers)
|
|
196
|
+
buffer.destroy();
|
|
197
|
+
this.buffers.length = 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
GPUArticulationTree
|
|
203
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Buffer } from '@luma.gl/core';
|
|
2
|
+
import type { GPUCommandGraph } from "../gpu-core/gpu-command-graph.js";
|
|
3
|
+
type Vector = readonly [number, number, number];
|
|
4
|
+
/** Link origins are centers of mass. Both anchor offsets use their respective local frames. */
|
|
5
|
+
export type GPUArticulationLink = {
|
|
6
|
+
id: string;
|
|
7
|
+
/** Parent link index, or -1 for the fixed base. Parents precede children. */
|
|
8
|
+
parent: number;
|
|
9
|
+
parentAnchor: Vector;
|
|
10
|
+
childAnchor: Vector;
|
|
11
|
+
/** Unit revolute axis in the parent frame. Omit for a welded attachment. */
|
|
12
|
+
axis?: Vector;
|
|
13
|
+
/** Child-to-parent orientation at zero angle. */
|
|
14
|
+
restOrientation?: readonly [number, number, number, number];
|
|
15
|
+
mass: number;
|
|
16
|
+
/** Principal moments about the COM in the child frame. */
|
|
17
|
+
inertia: Vector;
|
|
18
|
+
angle?: number;
|
|
19
|
+
speed?: number;
|
|
20
|
+
};
|
|
21
|
+
/** Position control in radians, N·m/rad, N·m·s/rad and N·m respectively. */
|
|
22
|
+
export type GPUArticulationDrive = {
|
|
23
|
+
angle: number;
|
|
24
|
+
stiffness: number;
|
|
25
|
+
damping: number;
|
|
26
|
+
maximumTorque: number;
|
|
27
|
+
};
|
|
28
|
+
/** Frictionless unilateral contact between a link-centered sphere and a static world-space box. */
|
|
29
|
+
export type GPUArticulationContact = {
|
|
30
|
+
link: string;
|
|
31
|
+
radius: number;
|
|
32
|
+
center: Vector;
|
|
33
|
+
halfExtents: Vector;
|
|
34
|
+
};
|
|
35
|
+
/** Small fixed-base trees. The graph owns the kernel and the tree owns the buffers. */
|
|
36
|
+
export declare class GPUArticulationTree {
|
|
37
|
+
readonly timeStep: number;
|
|
38
|
+
readonly id: string;
|
|
39
|
+
private readonly links;
|
|
40
|
+
private readonly indices;
|
|
41
|
+
private readonly buffers;
|
|
42
|
+
private readonly base;
|
|
43
|
+
private readonly gravity;
|
|
44
|
+
private readonly contact?;
|
|
45
|
+
private readonly publishMatrices;
|
|
46
|
+
/** Column-major world transforms in link order, available after registration with publishMatrices. */
|
|
47
|
+
get poseMatrices(): Buffer;
|
|
48
|
+
private destroyed;
|
|
49
|
+
constructor(props: {
|
|
50
|
+
id?: string;
|
|
51
|
+
links: readonly GPUArticulationLink[];
|
|
52
|
+
base?: Vector;
|
|
53
|
+
gravity?: Vector;
|
|
54
|
+
timeStep?: number;
|
|
55
|
+
contact?: GPUArticulationContact;
|
|
56
|
+
publishMatrices?: boolean;
|
|
57
|
+
});
|
|
58
|
+
/** Register one simulation step. The output pose buffer uses four vec4s per link: COM, quaternion, velocity, spin. */
|
|
59
|
+
addToGraph<P>(graph: GPUCommandGraph<P>): import("..").GraphBufferHandle;
|
|
60
|
+
private driveIndex;
|
|
61
|
+
/** Update the named revolute drive between submitted steps. */
|
|
62
|
+
setDrive(id: string, drive: GPUArticulationDrive): void;
|
|
63
|
+
/** Signed motor torque during the most recently accepted step. */
|
|
64
|
+
readTorque(id: string): Promise<number>;
|
|
65
|
+
/** Read COM poses and world-space velocities in link order after stepping. */
|
|
66
|
+
readState(): Promise<{
|
|
67
|
+
position: number[];
|
|
68
|
+
orientation: number[];
|
|
69
|
+
velocity: number[];
|
|
70
|
+
angularVelocity: number[];
|
|
71
|
+
}[]>;
|
|
72
|
+
/** Numerical failure latches and preserves the last accepted state. */
|
|
73
|
+
readSimulationDiagnostics(): Promise<{
|
|
74
|
+
normalForce?: number | undefined;
|
|
75
|
+
steps: number;
|
|
76
|
+
complete: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
destroy(): void;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=gpu-articulation-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpu-articulation-tree.d.ts","sourceRoot":"","sources":["../../src/gpu-physics/gpu-articulation-tree.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,MAAM,EAA2D,MAAM,eAAe,CAAC;AAC/F,OAAO,KAAK,EAAC,eAAe,EAAiB,yCAAsC;AASnF,KAAK,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAChD,+FAA+F;AAC/F,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,eAAe,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,4EAA4E;AAC5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,mGAAmG;AACnG,MAAM,MAAM,sBAAsB,GAAG;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,uFAAuF;AACvF,qBAAa,mBAAmB;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwB;IAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAC1C,sGAAsG;IACtG,IAAI,YAAY,WAEf;IACD,OAAO,CAAC,SAAS,CAAS;gBAEd,KAAK,EAAE;QACjB,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,SAAS,mBAAmB,EAAE,CAAC;QACtC,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,sBAAsB,CAAC;QACjC,eAAe,CAAC,EAAE,OAAO,CAAC;KAC3B;IAkDD,sHAAsH;IACtH,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC;IA8FvC,OAAO,CAAC,UAAU;IAOlB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,oBAAoB;IAahD,kEAAkE;IAC5D,UAAU,CAAC,EAAE,EAAE,MAAM;IAM3B,8EAA8E;IACxE,SAAS;;;;;;IAaf,uEAAuE;IACjE,yBAAyB;;;;;IAW/B,OAAO;CAKR"}
|