packages feed

hsjuiz 0.3.3 → 0.3.4

raw patch · 7 files changed

+80/−9 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Juiz: clearModel :: IO ()
+ Juiz: juizContainerModelInvalidError :: Int64
+ Juiz: setModel :: ByteString -> Text -> Value -> IO Value
+ Juiz.Capsule: fill :: Value -> Ptr CValue -> IO ()
+ Juiz.Capsule: withCallback :: FunPtr cb -> ((IO () -> IO ()) -> f) -> (FunPtr cb -> Ptr () -> IO r) -> IO r
+ Juiz.Capsule: withLockCallback :: (Ptr CValue -> IO ()) -> (FunPtr LockCallback -> Ptr () -> IO Int64) -> IO Int64
+ Juiz.Error: juizContainerModelInvalidError :: Int64
+ Juiz.Pose: clearModel :: IO ()
+ Juiz.Pose: setModel :: ByteString -> Text -> Value -> IO Value

Files

CHANGELOG.md view
@@ -3,6 +3,12 @@ hsjuiz の版は juiz(crates.io の juiz_app、PyPI の pyjuiz / juiz-cli)と同じ番号にそろえています。 使う libjuiz_sdk も同じ版にしてください。 +## 0.3.4++- `Juiz.Pose` に `setModel` / `clearModel` を足した。ContainerProcess の中から、その Container の 3D モデルを差し替える・外す+  (docs/spec/container-model.md §13.2、juiz#564)。値の誤りは `juizContainerModelInvalidError`(-908)。+- `Juiz.Capsule` から `fill`・`withCallback`・`withLockCallback` を出した(`setModel` が使う)。+ ## 0.3.3  - hsjuiz の API は 0.3.2 から変えていない(juiz の Zig 対応 #571 の公開に版をそろえた)。
README.md view
@@ -352,7 +352,7 @@ `scripts/install-juiz-sdk.sh` で取得して `~/.juiz/sdk/<版>` に展開できます。  ```terminal-curl -fsSL https://raw.githubusercontent.com/OpenJUIZ/juiz/main/scripts/install-juiz-sdk.sh | sh -s -- 0.3.3+curl -fsSL https://raw.githubusercontent.com/OpenJUIZ/juiz/main/scripts/install-juiz-sdk.sh | sh -s -- 0.3.4 ```  それより前の版では、juiz のソースを同じ版のタグで取得し、`cargo build --release -p juiz_sdk` でできる `target/release` の libjuiz_sdk を使います。@@ -366,8 +366,8 @@ packages: .  package hsjuiz-  extra-lib-dirs: /home/me/.juiz/sdk/0.3.3/lib-  ghc-options: -optl-Wl,-rpath,/home/me/.juiz/sdk/0.3.3/lib+  extra-lib-dirs: /home/me/.juiz/sdk/0.3.4/lib+  ghc-options: -optl-Wl,-rpath,/home/me/.juiz/sdk/0.3.4/lib ```  ```terminal@@ -379,11 +379,11 @@ その `bindings/hsjuiz` を `cabal.project` の `packages:` に足します。  ```cabal-packages: . /home/me/juiz-0.3.3/bindings/hsjuiz+packages: . /home/me/juiz-0.3.4/bindings/hsjuiz ```  ```terminal-git clone --depth 1 --branch v0.3.3 https://github.com/OpenJUIZ/juiz.git /home/me/juiz-0.3.3+git clone --depth 1 --branch v0.3.4 https://github.com/OpenJUIZ/juiz.git /home/me/juiz-0.3.4 ```  juiz のリポジトリの中でビルドするときは、`cargo build` でできる `target/debug` の libjuiz_sdk を
hsjuiz.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               hsjuiz-version:            0.3.3+version:            0.3.4 synopsis:           Write juiz processes and containers in Haskell description:     Write Process / Container / Component plugins of
src/Juiz.hs view
@@ -125,6 +125,8 @@   , ContainerTransform (..)   , identityTransform   , setTransform+  , setModel+  , clearModel   , transformToValue   , transformStampedToValue   , poseToValue@@ -142,6 +144,7 @@   , juizTransformationsError   , juizTransformNotWritableError   , juizTransformNotFoundError+  , juizContainerModelInvalidError     -- * よく使う型   , Int64   , Word64
src/Juiz/Capsule.hs view
@@ -12,6 +12,9 @@   , (.=)     -- * libjuiz_sdk の値の読み書き   , peekValue+  , fill+  , withCallback+  , withLockCallback   , readArgument   , readArgumentOrImage   , readTypedArgument
src/Juiz/Error.hs view
@@ -23,6 +23,7 @@   , juizTransformationsError   , juizTransformNotWritableError   , juizTransformNotFoundError+  , juizContainerModelInvalidError   ) where  import Control.Exception (Exception, throwIO)@@ -105,3 +106,8 @@ -- | 'Juiz.Pose.setTransform' の Transform が無い (§7.5、#410) juizTransformNotFoundError :: Int64 juizTransformNotFoundError = -907++-- | 'Juiz.Pose.setModel' の値の誤り (形式に合わない・上限超えなど)、readonly の ContainerProcess からの差し替え+-- (docs/spec/container-model.md §13.2、#564)+juizContainerModelInvalidError :: Int64+juizContainerModelInvalidError = -908
src/Juiz/Pose.hs view
@@ -18,6 +18,10 @@ -- -- > (t, _) <- setTransform "map" "odom" (ContainerTransform (0.1, 0, 0) (0, 0, 0, 1)) --+-- 3D モデルは 'setModel' / 'clearModel' で差し替える (docs/spec/container-model.md §13.2、#564):+--+-- > info <- setModel closedGlb "glb" (object ["file_name" .= ("closed.glb" :: Text)])+-- -- ContainerProcess の関数は Container の状態だけを受け取り、Container そのものは受け取らないので、 -- 読み書きの相手は「今呼ばれている ContainerProcess の Container」になる。juiz が呼んだスレッドの上 -- (関数の中) でだけ使える。'Control.Concurrent.forkIO' した先や、関数から戻った後では@@ -32,6 +36,8 @@   , ContainerTransform (..)   , identityTransform   , setTransform+  , setModel+  , clearModel   , transformToValue   , transformStampedToValue   , poseToValue@@ -43,18 +49,21 @@ import Control.Exception (finally) import Control.Monad (when) import Data.Int (Int32, Int64)+import Data.IORef (newIORef, readIORef, writeIORef) import qualified Data.Map.Strict as Map import Data.Text (Text) import qualified Data.Text as T import qualified Data.ByteString as BS import qualified Data.Text.Encoding as TE import Foreign.C.String (CString, peekCString)+import Foreign.C.Types (CSize (..)) import Foreign.Marshal.Alloc (allocaBytes)-import Foreign.Ptr (Ptr, nullPtr)+import Foreign.Ptr (FunPtr, Ptr, castPtr, nullFunPtr, nullPtr) import Foreign.Storable (peekByteOff, pokeByteOff) +import Juiz.Capsule (fill, peekValue, withCallback, withLockCallback) import Juiz.Error-import Juiz.Internal.FFI (CCapsuleMap)+import Juiz.Internal.FFI (ArrayCallback, CCapsuleMap, LockCallback, arrayTrampoline) import Juiz.Value  -- | 位置姿勢 (@juiz_std.geometry.Pose@)。位置 (x, y, z) [m] と四元数 (x, y, z, w)@@ -98,6 +107,12 @@   c_juiz_container_pose_lookup :: Ptr CCapsuleMap -> CString -> CString -> Ptr () -> IO Int64 foreign import ccall safe "juiz_container_transform_set"   c_juiz_container_transform_set :: Ptr CCapsuleMap -> CString -> CString -> Ptr () -> Ptr () -> IO Int64+foreign import ccall safe "juiz_container_model_set"+  c_juiz_container_model_set+    :: Ptr CCapsuleMap -> Ptr () -> CSize -> CString+    -> FunPtr LockCallback -> Ptr () -> FunPtr ArrayCallback -> Ptr () -> IO Int64+foreign import ccall safe "juiz_container_model_clear"+  c_juiz_container_model_clear :: Ptr CCapsuleMap -> IO Int64 foreign import ccall unsafe "juiz_container_pose_last_error"   c_juiz_container_pose_last_error :: IO CString @@ -114,7 +129,7 @@   _ <- c_hsjuiz_swap_pose_call cm   when (cm == nullPtr) $     throwJuiz juizTransformationsNotAttachedError-      "containerPose / setContainerPose / lookupContainerPose / setTransform can be used only inside a container process (on the thread that juiz called it)"+      "containerPose / setContainerPose / lookupContainerPose / setTransform / setModel can be used only inside a container process (on the thread that juiz called it)"   pure cm  -- juiz_pose_stamped の並び: position (0, 8, 16)、orientation (24, 32, 40, 48)、stamp.sec 56、stamp.nanosec 64@@ -184,6 +199,44 @@           c_juiz_container_transform_set cm src dst inp out >>= check           (ContainerPose t' q', stamp) <- peekStamped out           pure (ContainerTransform t' q', stamp)++-- | 今呼ばれている ContainerProcess の Container の 3D モデルを、bytes の中身に差し替える+-- (docs/spec/container-model.md §13.2、#564)。差し替えた後のモデル情報+-- (@juiz_std.model.ContainerModelInfo@ の辞書) を返す。+--+-- format は @glb@・@gltf@・@stl@・@sdf@・@other@ (空なら options の @file_name@ の拡張子から決める)。+-- options は @scale@・@origin@・@up_axis@・@color@・@file_name@ の辞書 ('JNull' なら無し)。+-- 値の誤り (形式に合わない・上限超えなど) と readonly の ContainerProcess からの差し替えは+-- 'juizContainerModelInvalidError' (今のモデルは変わらない)+setModel :: BS.ByteString -> Text -> Value -> IO Value+setModel bytes format options = do+  cm <- currentPoseCall+  case options of+    JNull -> pure ()+    JObject _ -> pure ()+    _ -> throwJuiz juizContainerModelInvalidError "model options must be a dictionary"+  info <- newIORef JNull+  code <-+    withOptions $ \optFn optArg ->+      withCallback arrayTrampoline (\guarded v -> guarded (peekValue v >>= writeIORef info)) $ \infoFn infoArg ->+        BS.useAsCStringLen bytes $ \(p, n) ->+          withFormat $ \fmt ->+            c_juiz_container_model_set cm (castPtr p) (fromIntegral n) fmt optFn optArg infoFn infoArg+  check code+  readIORef info+  where+    withOptions act = case options of+      JObject _ -> withLockCallback (fill options) act+      _ -> act nullFunPtr nullPtr+    withFormat act+      | T.null format = act nullPtr+      | otherwise = withUtf8 format act++-- | 今呼ばれている ContainerProcess の Container の 3D モデルを外す (§13.2)。conf や型の既定のモデルにも戻らない+clearModel :: IO ()+clearModel = do+  cm <- currentPoseCall+  c_juiz_container_model_clear cm >>= check  -- | @juiz_std.geometry.Transform@ の辞書にする transformToValue :: ContainerTransform -> Value