Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ vite.config.ts.timestamp-*

# Sentry Config File
.env.sentry-build-plugin

# Protobuf
gen
src/lib/gen
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
package-lock.json
pnpm-lock.yaml
yarn.lock
.changeset
.changeset

# Protobuf
gen
src/lib/gen
33 changes: 29 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help setup up
.PHONY: help setup up proto-generate proto-lint proto-format proto-clean

# Default target - show help when no target is specified
.DEFAULT_GOAL := help
Expand All @@ -8,12 +8,37 @@ help:
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@echo ' setup - Set up development environment (install pnpm, bun, dependencies)'
@echo ' up - Start development server'
@echo ' help - Show this help message'
@echo ' setup - Set up development environment (install pnpm, bun, dependencies)'
@echo ' up - Start development server'
@echo ' proto-generate - Generate Go and TypeScript code from protobuf definitions'
@echo ' proto-lint - Lint protobuf files'
@echo ' proto-format - Format protobuf files'
@echo ' proto-clean - Clean generated protobuf code'
@echo ' help - Show this help message'

setup:
@./etc/setup.sh

up:
pnpm dev

proto-clean:
@echo 'Cleaning generated protobuf code...'
@rm -rf gen src/lib/gen
@echo 'Clean complete!'

proto-gen: proto-clean
@echo 'Generating protobuf code...'
@echo 'Updating buf dependencies...'
@pnpm exec buf dep update
@echo 'Installing protoc-gen-go...'
@go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
@echo 'Generating code...'
@PATH="$(shell go env GOPATH)/bin:$(shell pnpm bin):$$PATH" pnpm exec buf generate
@echo 'Protobuf code generation complete!'

proto-lint:
@pnpm exec buf lint

proto-format:
@pnpm exec buf format -w
16 changes: 16 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
managed:
enabled: false
plugins:
# Go code generation
- local: protoc-gen-go
out: gen
opt: paths=source_relative

# TypeScript code generation (v1 - matches Viam SDK)
- remote: buf.build/bufbuild/es:v1.10.0
out: src/lib/gen
opt:
- target=ts
- import_extension=none
include_imports: true
9 changes: 9 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/googleapis/googleapis
commit: 62f35d8aed1149c291d606d958a7ce32
digest: b5:d66bf04adc77a0870bdc9328aaf887c7188a36fb02b83a480dc45ef9dc031b4d39fc6e9dc6435120ccf4fe5bfd5c6cb6592533c6c316595571f9a31420ab47fe
- name: buf.build/viamrobotics/api
commit: a4b2b3ea4a094ad69b9c26f96d1f43aa
digest: b5:8997d57a7bba43c2c0b8ad1884e1ec43d337bce946fb2750b9324b859a15983271c2db4b0ceae648f929d62768c4839686d1cb8477d323f51c49cb91df73709c
11 changes: 11 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: v2
modules:
- path: protos
deps:
- buf.build/viamrobotics/api
lint:
use:
- STANDARD
breaking:
use:
- FILE
29 changes: 5 additions & 24 deletions client/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/golang/geo/r3"
"github.com/viam-labs/motion-tools/client/colorutil"
"github.com/viam-labs/motion-tools/client/shapes"
"github.com/viam-labs/motion-tools/draw"
"google.golang.org/protobuf/encoding/protojson"

"go.viam.com/rdk/referenceframe"
Expand Down Expand Up @@ -402,18 +402,9 @@ func DrawPoses(poses []spatialmath.Pose, colors []string, arrowHeadAtPose bool)
// - nurbs: A nurbs curve
// - color: The color of the line
// - name: A unique label for the curve
func DrawNurbs(nurbs shapes.Nurbs, color string, name string) error {
poseData := make([]json.RawMessage, len(nurbs.ControlPts))
for i, pose := range nurbs.ControlPts {
data, err := protojson.Marshal(spatialmath.PoseToProtobuf(pose))
if err != nil {
return err
}
poseData[i] = json.RawMessage(data)
}

func DrawNurbs(nurbs *draw.Nurbs, color string, name string) error {
wrappedData := map[string]interface{}{
"ControlPts": poseData,
"ControlPts": nurbs.ControlPoints,
"Degree": nurbs.Degree,
"Weights": nurbs.Weights,
"Knots": nurbs.Knots,
Expand Down Expand Up @@ -465,18 +456,8 @@ func RemoveAllSpatialObjects() error {
// - lookAt: The direction the camera should look at
// - animate: Whether or not to animate to this pose
func SetCameraPose(position r3.Vector, lookAt r3.Vector, animate bool) error {
positionM := map[string]interface{}{
"X": position.X / 1000.0,
"Y": position.Y / 1000.0,
"Z": position.Z / 1000.0,
}

lookAtM := map[string]interface{}{
"X": lookAt.X / 1000.0,
"Y": lookAt.Y / 1000.0,
"Z": lookAt.Z / 1000.0,
}

positionM := position.Mul(0.001)
lookAtM := lookAt.Mul(0.001)
data := map[string]interface{}{
"setCameraPose": true,
"Position": positionM,
Expand Down
2 changes: 1 addition & 1 deletion client/client/draw_nurbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ func TestDrawNurbs(t *testing.T) {
t.Run("DrawNurbs", func(t *testing.T) {
nurbs := shapes.GenerateNURBS(20, 3, r3.Vector{X: 0, Y: 0, Z: 0})

test.That(t, DrawNurbs(nurbs, "#40E0D0", "nurbs-1"), test.ShouldBeNil)
test.That(t, DrawNurbs(&nurbs, "#40E0D0", "nurbs-1"), test.ShouldBeNil)
})
}
4 changes: 2 additions & 2 deletions client/client/draw_pointcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestDrawPointCloud(t *testing.T) {
pc, err := pointcloud.NewFromFile("../data/Zaghetto.pcd", pointcloud.BasicType)
test.That(t, err, test.ShouldBeNil)

for i := 0; i < 10; i++ {
time.Sleep(16 * time.Millisecond)
for i := range 10 {
time.Sleep(100 * time.Millisecond)
test.That(t, DrawPointCloud("Zaghetto"+strconv.Itoa(i+1), pc, nil), test.ShouldBeNil)
}
})
Expand Down
20 changes: 7 additions & 13 deletions client/shapes/shapes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import (
"math/rand"

"github.com/golang/geo/r3"
"github.com/viam-labs/motion-tools/draw"
"go.viam.com/rdk/spatialmath"
)

type Nurbs struct {
ControlPts []spatialmath.Pose
Degree int
Weights []float64
Knots []float64
}

// Generate a NURBS structure similar to the Three.js version
func GenerateNURBS(numControlPoints int, degree int, offset r3.Vector) Nurbs {
func GenerateNURBS(numControlPoints int, degree int, offset r3.Vector) draw.Nurbs {
controlPts := make([]spatialmath.Pose, numControlPoints)
weights := make([]float64, numControlPoints)
knots := make([]float64, numControlPoints+degree+1)
Expand All @@ -42,11 +36,11 @@ func GenerateNURBS(numControlPoints int, degree int, offset r3.Vector) Nurbs {
knots[i+degree+1] = clamp(knot, 0, 1)
}

return Nurbs{
ControlPts: controlPts,
Degree: degree,
Weights: weights,
Knots: knots,
return draw.Nurbs{
ControlPoints: controlPts,
Degree: int32(degree),
Weights: weights,
Knots: knots,
}
}

Expand Down
1 change: 1 addition & 0 deletions draw/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__snapshots__
Empty file added draw/README.md
Empty file.
Binary file added draw/__fixtures__/BoxAnimated.glb
Binary file not shown.
Binary file added draw/__fixtures__/CesiumMilkTruck.glb
Binary file not shown.
Binary file added draw/__fixtures__/Fox.glb
Binary file not shown.
Loading
Loading