mujoco-react 10.9.0 → 11.0.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/dist/onnx.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as ort from 'onnxruntime-web';
2
- import { bq as PolicyActionChunk } from './types-Bu8Aki_j.js';
2
+ import { bs as PolicyActionChunk } from './types-BP8iiYei.js';
3
3
  import 'react';
4
4
  import '@react-three/fiber';
5
5
  import 'three';
package/dist/spark.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as _sparkjsdev_spark from '@sparkjsdev/spark';
3
- import { o as SplatEnvironmentProps, r as PairedSplatEnvironmentConfig, S as SceneConfig, u as SplatEnvironmentReadiness, p as VisualScenarioConfig } from './types-Bu8Aki_j.js';
3
+ import { p as SplatEnvironmentProps, s as PairedSplatEnvironmentConfig, S as SceneConfig, v as SplatEnvironmentReadiness, q as VisualScenarioConfig } from './types-BP8iiYei.js';
4
4
  import 'react';
5
5
  import '@react-three/fiber';
6
6
  import 'three';
package/dist/spark.js CHANGED
@@ -1,4 +1,4 @@
1
- import { useSplatSceneConfig, useSplatEnvironment, SplatEnvironment, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY } from './chunk-5WFYM73E.js';
1
+ import { useSplatSceneConfig, useSplatEnvironment, SplatEnvironment, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY } from './chunk-UCQ5MJP4.js';
2
2
  import { useThree } from '@react-three/fiber';
3
3
  import { useMemo, useState, useEffect, useCallback, useRef } from 'react';
4
4
  import * as THREE from 'three';
@@ -242,6 +242,7 @@ interface MujocoModel {
242
242
  ngeom: number;
243
243
  nsite: number;
244
244
  nu: number;
245
+ nactuator: number;
245
246
  njnt: number;
246
247
  nq: number;
247
248
  nv: number;
@@ -314,6 +315,9 @@ interface MujocoModel {
314
315
  mesh_texcoord?: Float32Array;
315
316
  mesh_facetexcoord?: Int32Array;
316
317
  site_bodyid: Int32Array;
318
+ actuator_ctrladr: Int32Array;
319
+ actuator_ctrlnum: Int32Array;
320
+ actuator_ctrllimited: Uint8Array;
317
321
  actuator_trnid: Int32Array;
318
322
  actuator_ctrlrange: Float64Array;
319
323
  actuator_trntype: Int32Array;
@@ -353,9 +357,14 @@ interface MujocoModel {
353
357
  ten_width: Float64Array;
354
358
  flex_vertadr: Int32Array;
355
359
  flex_vertnum: Int32Array;
356
- flex_faceadr: Int32Array;
357
- flex_facenum: Int32Array;
358
- flex_face: Int32Array;
360
+ flex_dim: Int32Array;
361
+ flex_elemadr: Int32Array;
362
+ flex_elemnum: Int32Array;
363
+ flex_elemdataadr: Int32Array;
364
+ flex_elem: Int32Array;
365
+ flex_shelldataadr: Int32Array;
366
+ flex_shellnum: Int32Array;
367
+ flex_shell: Int32Array;
359
368
  flex_rgba: Float32Array;
360
369
  opt: {
361
370
  timestep: number;
@@ -402,7 +411,25 @@ interface MujocoData {
402
411
  /**
403
412
  * Minimal interface for the MuJoCo WASM Module.
404
413
  */
414
+ interface MujocoBuffer {
415
+ GetView(): Float64Array;
416
+ delete(): void;
417
+ }
405
418
  interface MujocoModule {
419
+ DoubleBuffer: new (size: number) => MujocoBuffer;
420
+ mj_jacSite(model: MujocoModel, data: MujocoData, jacp: MujocoBuffer | null, jacr: MujocoBuffer | null, site: number): void;
421
+ mj_integratePos(model: MujocoModel, qpos: MujocoBuffer, velocity: number[], dt: number): void;
422
+ mj_stateSize(model: MujocoModel, signature: number): number;
423
+ mj_getState(model: MujocoModel, data: MujocoData, state: MujocoBuffer, signature: number): void;
424
+ mj_setState(model: MujocoModel, data: MujocoData, state: number[], signature: number): void;
425
+ mjtState: {
426
+ mjSTATE_INTEGRATION: {
427
+ value: number;
428
+ };
429
+ };
430
+ mj_resetCtrl(model: MujocoModel, data: MujocoData): void;
431
+ mj_actuatorInputName(model: MujocoModel, id: number, input: number): string;
432
+ mju_threadpool(data: MujocoData, threads: number): void;
406
433
  MjModel: {
407
434
  from_xml_path?: (path: string) => MujocoModel;
408
435
  from_xml_string?: (xml: string, vfs?: unknown) => MujocoModel;
@@ -559,6 +586,8 @@ interface SceneMarker {
559
586
  interface PhysicsConfig {
560
587
  gravity?: [number, number, number];
561
588
  timestep?: number;
589
+ /** Override the MJCF integrator. Omit to preserve model settings. */
590
+ integrator?: MujocoIntegrator;
562
591
  substeps?: number;
563
592
  paused?: boolean;
564
593
  speed?: number;
@@ -607,6 +636,12 @@ interface SelectionCallbackInput {
607
636
  }
608
637
  type PhysicsStepCallback = (input: PhysicsStepInput) => void;
609
638
  interface StateSnapshot {
639
+ /** Complete engine integration state. Absent on legacy snapshots. */
640
+ integration?: {
641
+ signature: number;
642
+ values: Float64Array;
643
+ model: MujocoModel;
644
+ };
610
645
  time: number;
611
646
  qpos: Float64Array;
612
647
  qvel: Float64Array;
@@ -647,8 +682,13 @@ interface SiteInfo {
647
682
  interface ActuatorInfo {
648
683
  id: number;
649
684
  name: string;
685
+ /** Range of the first input; use ranges for multi-input actuators. */
650
686
  range: [number, number];
687
+ ctrlAdr: number;
688
+ ctrlCount: number;
689
+ ranges: [number, number][];
651
690
  }
691
+ type ActuatorControlValue = number | readonly number[];
652
692
  interface ActuatedJointInfo extends JointInfo {
653
693
  actuatorId: number;
654
694
  actuatorName: string;
@@ -749,6 +789,7 @@ interface ImagePointProjectionResult extends RayHit {
749
789
  /** Camera pose provenance, matching camera-frame capture results. */
750
790
  source: CameraFrameCaptureSource;
751
791
  }
792
+ type MujocoIntegrator = 'Euler' | 'RK4' | 'implicit' | 'implicitfast' | 'discrete';
752
793
  interface ModelOptions {
753
794
  timestep: number;
754
795
  gravity: [number, number, number];
@@ -1247,7 +1288,7 @@ interface MujocoSimAPI {
1247
1288
  setQvel(values: Float64Array | number[]): void;
1248
1289
  getQpos(): Float64Array;
1249
1290
  getQvel(): Float64Array;
1250
- setCtrl(nameOrValues: Actuators | Record<Actuators, number>, value?: number): void;
1291
+ setCtrl(nameOrValues: Actuators | Record<Actuators, ActuatorControlValue>, value?: ActuatorControlValue): void;
1251
1292
  getCtrl(): Float64Array;
1252
1293
  getControlMap(): ControlGroupInfo;
1253
1294
  getActuatedJoints(): ActuatedJointInfo[];
@@ -1584,6 +1625,8 @@ type MujocoCanvasProps = Omit<CanvasProps, 'onError'> & {
1584
1625
  onSelection?: (input: SelectionCallbackInput) => void;
1585
1626
  gravity?: [number, number, number];
1586
1627
  timestep?: number;
1628
+ /** Override the MJCF integrator. Omit to preserve model settings. */
1629
+ integrator?: MujocoIntegrator;
1587
1630
  substeps?: number;
1588
1631
  paused?: boolean;
1589
1632
  speed?: number;
@@ -1659,4 +1702,4 @@ interface ArrayJointStateResult {
1659
1702
  velocity: React__default.RefObject<Float64Array>;
1660
1703
  }
1661
1704
 
1662
- export { type Joints as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type VisualScenarioExecutionContext as E, type ScenarioLightingPreset as F, type SplatEnvironmentMetadataInput as G, type SplatEnvironmentMetadata as H, type IkConfig as I, type SplatSceneInput as J, type CameraFrameCaptureOptions as K, type DebugProps as L, type MujocoContextValue as M, type GeomInfo as N, type ObservationConfig as O, type PhysicsStepCallback as P, type ContactListenerProps as Q, type ReadyCallbackInput as R, type SceneConfig as S, type TrajectoryPlayerProps as T, type ActuatorInfo as U, type VisualScenarioEffectsProps as V, type Sites as W, type SitePositionResult as X, type Sensors as Y, type SensorHandle as Z, type SensorInfo as _, type MujocoCanvasProps as a, type IKSolveFn as a$, type ScalarJointStateResult as a0, type ArrayJointStateResult as a1, type JointStateOptions as a2, type JointStateResult as a3, type Bodies as a4, type BodyStateResult as a5, type Geoms as a6, type Actuators as a7, type CtrlHandle as a8, type ContactInfo as a9, type PolicyCameraFrameCaptureAPI as aA, type CameraFrameCaptureTensorOptions as aB, type CameraFrameTensorResult as aC, type CameraFrameSequenceRecorderAPI as aD, type ImagePointCoordinateSpace as aE, type ImagePointProjectionOptions as aF, type ImagePointProjectionResult as aG, type PolicyVector as aH, type BodyInfo as aI, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY as aJ, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY as aK, CAPTURE_EXCLUDE_KEY as aL, type CameraFrameCaptureBlobResult as aM, type CameraFrameCaptureQuaternion as aN, type CameraFrameCaptureResult as aO, type CameraFrameCaptureSession as aP, type CameraFrameCaptureVector3 as aQ, type CameraFramePixelsResult as aR, type CameraFrameSequenceCameraSummary as aS, type CameraFrameSequenceFrame as aT, type CameraFrameSequenceSampleInput as aU, type CameraFrameSequenceStepInput as aV, type CameraInfo as aW, type ControlJointInfo as aX, type DebugVirtualCamera as aY, type FrameCaptureTarget as aZ, type FrameCaptureTargetRef as a_, type KeyboardTeleopConfig as aa, type KeyboardIkTargetConfig as ab, type PolicyConfig as ac, type PolicyAPI as ad, type RemotePolicyConfig as ae, type RemotePolicyAPI as af, type ObservationHandle as ag, type ObservationOutput as ah, type TrajectoryInput as ai, type TrajectoryStateChangeInput as aj, type PlaybackState as ak, type TrajectoryFrame as al, type FrameCaptureOptions as am, type FrameCaptureResult as an, type FrameCaptureBlobResult as ao, type FrameCaptureAPI as ap, type CameraFrameCaptureAPI as aq, type Cameras as ar, type CameraFrameSequenceCamera as as, type CameraFrameCaptureSource as at, type CameraFrameSequenceOptions as au, type CameraFrameSequenceResult as av, type PolicyCameraFrameStream as aw, type PolicyCameraFrameCaptureOptions as ax, type PolicyCameraFrameCaptureResult as ay, type FrameCaptureStatus as az, type MujocoSimAPI as b, captureCameraFrameBlob as b$, type IkGizmoDragInput as b0, type IkSolveInput as b1, type JointInfo as b2, type JointStateKind as b3, type KeyBinding as b4, type KeyboardIkTargetAction as b5, type KeyboardIkTargetBinding as b6, type Keyframes as b7, ModelActuators as b8, ModelBodies as b9, type PolicyInferenceResult as bA, type PolicyObservationInput as bB, type RayHit as bC, type Register as bD, type RegisteredModelMap as bE, type RemotePolicyRequestInfo as bF, type RemotePolicyRequestInput as bG, type RemotePolicyResponseInfo as bH, type RemotePolicyStatus as bI, type ResetCallbackInput as bJ, type ResolvedScenarioCameraConfig as bK, type ResolvedScenarioMaterialConfig as bL, type ResourceSelector as bM, type ScenarioCameraConfig as bN, type ScenarioMaterialConfig as bO, type SceneMarker as bP, type SceneObject as bQ, type SensorResult as bR, type SiteInfo as bS, type SplatAssetConfig as bT, type SplatScenarioConfig as bU, type StateSnapshot as bV, type TrajectoryData as bW, type TrajectoryFrameCallbackInput as bX, type VisualScenarioMaterialFilterInput as bY, type XmlPatch as bZ, captureCameraFrame as b_, ModelCameras as ba, ModelGeoms as bb, ModelJoints as bc, ModelKeyframes as bd, type ModelOptions as be, type ModelResource as bf, ModelResources as bg, ModelSensors as bh, ModelSites as bi, type Models as bj, type MujocoContact as bk, type MujocoContactArray as bl, type MujocoFrameCaptureOptions as bm, type ObservationLayoutItem as bn, type PhysicsConfig as bo, type PhysicsStepInput as bp, type PolicyActionChunk as bq, type PolicyActionInput as br, type PolicyImageTensorLayout as bs, type PolicyImageTensorOptions as bt, type PolicyImageTensorPixelOptions as bu, type PolicyImageTensorRange as bv, type PolicyImageTensorResult as bw, type PolicyImageTensorSourceOrigin as bx, type PolicyInferenceInput as by, type PolicyInferenceOutput as bz, type StepCallbackInput as c, captureCameraFrameTensor as c0, createCameraFrameCaptureSession as c1, dataUrlToPolicyImageTensor as c2, getContact as c3, imageDataToPolicyImageTensor as c4, pixelsToPolicyImageTensor as c5, registerModelResources as c6, renderCameraFrameToCanvas as c7, type SelectionCallbackInput as d, type MujocoModule as e, type MujocoRenderOptions as f, type MujocoModel as g, type MujocoData as h, type ControlGroupSelector as i, type ObservationResult as j, type IkContextValue as k, type IkGizmoProps as l, type SceneLightsProps as m, type ScenarioLightingProps as n, type SplatEnvironmentProps as o, type VisualScenarioConfig as p, type SplatRendererKind as q, type PairedSplatEnvironmentConfig as r, type SplatFormat as s, type SplatCollisionProxyConfig as t, type SplatEnvironmentReadiness as u, type SplatCollisionPrimitive as v, SplatEnvironmentReadinessStatus as w, type SplatSceneConfigInput as x, type SplatSceneConfigState as y, type VisualScenarioExecutionContextInput as z };
1705
+ export { type SensorInfo as $, type ActuatedJointInfo as A, type BodyProps as B, type ControlGroupInfo as C, type DragInteractionProps as D, type VisualScenarioExecutionContextInput as E, type VisualScenarioExecutionContext as F, type ScenarioLightingPreset as G, type SplatEnvironmentMetadataInput as H, type IkConfig as I, type SplatEnvironmentMetadata as J, type SplatSceneInput as K, type CameraFrameCaptureOptions as L, type MujocoContextValue as M, type DebugProps as N, type ObservationConfig as O, type PhysicsStepCallback as P, type GeomInfo as Q, type ReadyCallbackInput as R, type SceneConfig as S, type ContactListenerProps as T, type TrajectoryPlayerProps as U, type VisualScenarioEffectsProps as V, type ActuatorInfo as W, type Sites as X, type SitePositionResult as Y, type Sensors as Z, type SensorHandle as _, type MujocoCanvasProps as a, type FrameCaptureTarget as a$, type Joints as a0, type ScalarJointStateResult as a1, type ArrayJointStateResult as a2, type JointStateOptions as a3, type JointStateResult as a4, type Bodies as a5, type BodyStateResult as a6, type Geoms as a7, type Actuators as a8, type CtrlHandle as a9, type FrameCaptureStatus as aA, type PolicyCameraFrameCaptureAPI as aB, type CameraFrameCaptureTensorOptions as aC, type CameraFrameTensorResult as aD, type CameraFrameSequenceRecorderAPI as aE, type ImagePointCoordinateSpace as aF, type ImagePointProjectionOptions as aG, type ImagePointProjectionResult as aH, type PolicyVector as aI, type ActuatorControlValue as aJ, type BodyInfo as aK, CAMERA_FRAME_CAPTURE_PRE_RENDER_USER_DATA_KEY as aL, CAMERA_FRAME_CAPTURE_RENDER_USER_DATA_KEY as aM, CAPTURE_EXCLUDE_KEY as aN, type CameraFrameCaptureBlobResult as aO, type CameraFrameCaptureQuaternion as aP, type CameraFrameCaptureResult as aQ, type CameraFrameCaptureSession as aR, type CameraFrameCaptureVector3 as aS, type CameraFramePixelsResult as aT, type CameraFrameSequenceCameraSummary as aU, type CameraFrameSequenceFrame as aV, type CameraFrameSequenceSampleInput as aW, type CameraFrameSequenceStepInput as aX, type CameraInfo as aY, type ControlJointInfo as aZ, type DebugVirtualCamera as a_, type ContactInfo as aa, type KeyboardTeleopConfig as ab, type KeyboardIkTargetConfig as ac, type PolicyConfig as ad, type PolicyAPI as ae, type RemotePolicyConfig as af, type RemotePolicyAPI as ag, type ObservationHandle as ah, type ObservationOutput as ai, type TrajectoryInput as aj, type TrajectoryStateChangeInput as ak, type PlaybackState as al, type TrajectoryFrame as am, type FrameCaptureOptions as an, type FrameCaptureResult as ao, type FrameCaptureBlobResult as ap, type FrameCaptureAPI as aq, type CameraFrameCaptureAPI as ar, type Cameras as as, type CameraFrameSequenceCamera as at, type CameraFrameCaptureSource as au, type CameraFrameSequenceOptions as av, type CameraFrameSequenceResult as aw, type PolicyCameraFrameStream as ax, type PolicyCameraFrameCaptureOptions as ay, type PolicyCameraFrameCaptureResult as az, type MujocoSimAPI as b, type XmlPatch as b$, type FrameCaptureTargetRef as b0, type IKSolveFn as b1, type IkGizmoDragInput as b2, type IkSolveInput as b3, type JointInfo as b4, type JointStateKind as b5, type KeyBinding as b6, type KeyboardIkTargetAction as b7, type KeyboardIkTargetBinding as b8, type Keyframes as b9, type PolicyInferenceInput as bA, type PolicyInferenceOutput as bB, type PolicyInferenceResult as bC, type PolicyObservationInput as bD, type RayHit as bE, type Register as bF, type RegisteredModelMap as bG, type RemotePolicyRequestInfo as bH, type RemotePolicyRequestInput as bI, type RemotePolicyResponseInfo as bJ, type RemotePolicyStatus as bK, type ResetCallbackInput as bL, type ResolvedScenarioCameraConfig as bM, type ResolvedScenarioMaterialConfig as bN, type ResourceSelector as bO, type ScenarioCameraConfig as bP, type ScenarioMaterialConfig as bQ, type SceneMarker as bR, type SceneObject as bS, type SensorResult as bT, type SiteInfo as bU, type SplatAssetConfig as bV, type SplatScenarioConfig as bW, type StateSnapshot as bX, type TrajectoryData as bY, type TrajectoryFrameCallbackInput as bZ, type VisualScenarioMaterialFilterInput as b_, ModelActuators as ba, ModelBodies as bb, ModelCameras as bc, ModelGeoms as bd, ModelJoints as be, ModelKeyframes as bf, type ModelOptions as bg, type ModelResource as bh, ModelResources as bi, ModelSensors as bj, ModelSites as bk, type Models as bl, type MujocoContact as bm, type MujocoContactArray as bn, type MujocoFrameCaptureOptions as bo, type ObservationLayoutItem as bp, type PhysicsConfig as bq, type PhysicsStepInput as br, type PolicyActionChunk as bs, type PolicyActionInput as bt, type PolicyImageTensorLayout as bu, type PolicyImageTensorOptions as bv, type PolicyImageTensorPixelOptions as bw, type PolicyImageTensorRange as bx, type PolicyImageTensorResult as by, type PolicyImageTensorSourceOrigin as bz, type StepCallbackInput as c, captureCameraFrame as c0, captureCameraFrameBlob as c1, captureCameraFrameTensor as c2, createCameraFrameCaptureSession as c3, dataUrlToPolicyImageTensor as c4, getContact as c5, imageDataToPolicyImageTensor as c6, pixelsToPolicyImageTensor as c7, registerModelResources as c8, renderCameraFrameToCanvas as c9, type SelectionCallbackInput as d, type MujocoIntegrator as e, type MujocoModule as f, type MujocoRenderOptions as g, type MujocoModel as h, type MujocoData as i, type ControlGroupSelector as j, type ObservationResult as k, type IkContextValue as l, type IkGizmoProps as m, type SceneLightsProps as n, type ScenarioLightingProps as o, type SplatEnvironmentProps as p, type VisualScenarioConfig as q, type SplatRendererKind as r, type PairedSplatEnvironmentConfig as s, type SplatFormat as t, type SplatCollisionProxyConfig as u, type SplatEnvironmentReadiness as v, type SplatCollisionPrimitive as w, SplatEnvironmentReadinessStatus as x, type SplatSceneConfigInput as y, type SplatSceneConfigState as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mujoco-react",
3
- "version": "10.9.0",
3
+ "version": "11.0.0",
4
4
  "description": "Composable React Three Fiber building blocks for MuJoCo WASM simulations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -62,15 +62,16 @@
62
62
  "scripts": {
63
63
  "build": "tsup",
64
64
  "dev": "tsup --watch",
65
- "typecheck": "tsc --noEmit"
65
+ "typecheck": "tsc --noEmit",
66
+ "test:runtime": "tsup --config tests/tsup.config.ts && node --test .test-dist/runtime.js"
66
67
  },
67
68
  "peerDependencies": {
68
69
  "@react-three/drei": ">=9",
69
70
  "@react-three/fiber": ">=8",
70
71
  "@sparkjsdev/spark": ">=2.1.0",
72
+ "onnxruntime-web": ">=1.20.0",
71
73
  "react": ">=18",
72
- "three": ">=0.180.0",
73
- "onnxruntime-web": ">=1.20.0"
74
+ "three": ">=0.180.0"
74
75
  },
75
76
  "peerDependenciesMeta": {
76
77
  "@sparkjsdev/spark": {
@@ -81,7 +82,7 @@
81
82
  }
82
83
  },
83
84
  "dependencies": {
84
- "@mujoco/mujoco": "^3.9.0"
85
+ "@mujoco/mujoco": "3.15.0"
85
86
  },
86
87
  "devDependencies": {
87
88
  "@react-three/drei": "^10.7.7",
@@ -9,6 +9,7 @@ import { useEffect, useRef } from 'react';
9
9
  import { useFrame } from '@react-three/fiber';
10
10
  import type { ThreeElements } from '@react-three/fiber';
11
11
  import * as THREE from 'three';
12
+ import { getFlexTopology } from '../rendering/flexTopology';
12
13
  import { useMujocoContext } from '../core/MujocoSimProvider';
13
14
 
14
15
  /**
@@ -18,7 +19,7 @@ import { useMujocoContext } from '../core/MujocoSimProvider';
18
19
  export function FlexRenderer(props: Omit<ThreeElements['group'], 'ref'>) {
19
20
  const { mjModelRef, mjDataRef, status } = useMujocoContext();
20
21
  const groupRef = useRef<THREE.Group>(null);
21
- const meshesRef = useRef<THREE.Mesh[]>([]);
22
+ const meshesRef = useRef<Array<THREE.Mesh | THREE.LineSegments | THREE.Points>>([]);
22
23
 
23
24
  // Build flex meshes once when model is ready
24
25
  useEffect(() => {
@@ -39,11 +40,8 @@ export function FlexRenderer(props: Omit<ThreeElements['group'], 'ref'>) {
39
40
  const positions = new Float32Array(vertNum * 3);
40
41
  geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
41
42
 
42
- // Note: flex_faceadr/flex_facenum/flex_face may not be available in all MuJoCo WASM builds.
43
- // Without face data we render as a point cloud. If future WASM versions expose
44
- // face arrays, index-based triangle rendering can be added here.
45
-
46
- geometry.computeVertexNormals();
43
+ const topology = getFlexTopology(model, f);
44
+ if (topology.indices.length) geometry.setIndex(topology.indices);
47
45
 
48
46
  let color = new THREE.Color(0.5, 0.5, 0.5);
49
47
  if (model.flex_rgba) {
@@ -54,13 +52,14 @@ export function FlexRenderer(props: Omit<ThreeElements['group'], 'ref'>) {
54
52
  );
55
53
  }
56
54
 
57
- const material = new THREE.MeshStandardMaterial({
58
- color,
59
- roughness: 0.7,
60
- side: THREE.DoubleSide,
61
- });
62
-
63
- const mesh = new THREE.Mesh(geometry, material);
55
+ const opacity = model.flex_rgba[4 * f + 3];
56
+ const materialOptions = { color, opacity, transparent: opacity < 1 };
57
+ const mesh = topology.kind === 'mesh'
58
+ ? new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ ...materialOptions, roughness: 0.7, side: THREE.DoubleSide }))
59
+ : topology.kind === 'lines'
60
+ ? new THREE.LineSegments(geometry, new THREE.LineBasicMaterial(materialOptions))
61
+ : new THREE.Points(geometry, new THREE.PointsMaterial({ ...materialOptions, size: 0.01 }));
62
+ mesh.frustumCulled = false;
64
63
  mesh.userData.flexId = f;
65
64
  mesh.userData.vertAdr = vertAdr;
66
65
  mesh.userData.vertNum = vertNum;
@@ -94,7 +93,7 @@ export function FlexRenderer(props: Omit<ThreeElements['group'], 'ref'>) {
94
93
  posAttr.setXYZ(v, data.flexvert_xpos[srcIdx], data.flexvert_xpos[srcIdx + 1], data.flexvert_xpos[srcIdx + 2]);
95
94
  }
96
95
  posAttr.needsUpdate = true;
97
- mesh.geometry.computeVertexNormals();
96
+ if (mesh instanceof THREE.Mesh) mesh.geometry.computeVertexNormals();
98
97
  }
99
98
  });
100
99