resourceRefOf function Assets and loading

ResourceRefValue? resourceRefOf(
  1. Object? live,
  2. SerializeContext context
)

The serialized reference for live (a geometry, material, texture, or environment the resource realizer produced), copying the resource into context's document when it originated in another one. Null for a hand-built object, which has no source resource to reference.

Implementation

ResourceRefValue? resourceRefOf(Object? live, SerializeContext context) {
  if (live == null) return null;
  final origin = resourceOrigin(live);
  if (origin == null) return null;
  return ResourceRefValue(
    copyResourceInto(context.document, origin.document, origin.resourceId),
  );
}