From 15a7dd0cc8b7a19fff9aab904622d65cca6df221 Mon Sep 17 00:00:00 2001 From: Matthew MacFarquhar Date: Wed, 29 Oct 2025 13:54:53 -0400 Subject: [PATCH] implement Get3DMesh api --- Makefile | 8 +++++++- src/components/arm/arm.ts | 16 +++++++++++++++- src/components/arm/client.ts | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d084369cf..06fe9a8af 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,13 @@ update-buf: $(node_modules) .PHONY: build-buf build-buf: $(node_modules) clean-buf $(buf) generate buf.build/googleapis/googleapis - $(buf) generate buf.build/viamrobotics/api:$$(cat api_version.lock) --path common,component,robot,service,app,provisioning,tagger,stream + @if [ -z "$(LOCAL_API_PATH)" ]; then \ + echo "using production API"; \ + $(buf) generate buf.build/viamrobotics/api:$$(cat api_version.lock) --path common,component,robot,service,app,provisioning,tagger,stream; \ + else \ + echo "using local API from $(LOCAL_API_PATH)"; \ + $(buf) generate $(LOCAL_API_PATH); \ + fi $(buf) generate buf.build/viamrobotics/goutils $(buf) generate buf.build/grpc/grpc --path grpc/reflection/v1/reflection.proto diff --git a/src/components/arm/arm.ts b/src/components/arm/arm.ts index f6f2682b9..71ff73834 100644 --- a/src/components/arm/arm.ts +++ b/src/components/arm/arm.ts @@ -2,7 +2,7 @@ import type { PlainMessage, Struct } from '@bufbuild/protobuf'; import type { Pose, Resource } from '../../types'; import * as armApi from '../../gen/component/arm/v1/arm_pb'; -import type { Geometry } from '../../gen/common/v1/common_pb'; +import type { Geometry, Mesh } from '../../gen/common/v1/common_pb'; export type ArmJointPositions = PlainMessage; @@ -41,6 +41,20 @@ export interface Arm extends Resource { */ getGeometries: (extra?: Struct) => Promise; + /** + * + * Get the 3D models of the component + * + * @example + * + * ```ts + * const arm = new VIAM.ArmClient(machine, 'my_arm'); + * const models = await arm.get3DModels(); + * console.log(models); + * ``` + */ + get3DModels: (extra?: Struct) => Promise>; + /** * Move the end of the arm to the pose. * diff --git a/src/components/arm/client.ts b/src/components/arm/client.ts index be2651067..d107df9eb 100644 --- a/src/components/arm/client.ts +++ b/src/components/arm/client.ts @@ -14,7 +14,7 @@ import type { RobotClient } from '../../robot'; import type { Options, Pose } from '../../types'; import { doCommandFromClient } from '../../utils'; import type { Arm } from './arm'; -import { GetGeometriesRequest } from '../../gen/common/v1/common_pb'; +import { Get3DModelsRequest, GetGeometriesRequest, type Mesh } from '../../gen/common/v1/common_pb'; /** * A gRPC-web client for the Arm component. @@ -59,6 +59,19 @@ export class ArmClient implements Arm { return response.geometries; } + async get3DModels(extra = {}, callOptions = this.callOptions): Promise> { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const request = new Get3DModelsRequest({ + name: this.name, + extra: Struct.fromJson(extra), + }); + + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const response = await this.client.get3DModels(request, callOptions); + // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access + return response.models; + } + async moveToPosition(pose: Pose, extra = {}, callOptions = this.callOptions) { const request = new MoveToPositionRequest({ name: this.name,