Skip to content

Commit

Permalink
[Assimp] Simplify attribute buffer creation
Browse files Browse the repository at this point in the history
  • Loading branch information
hyazinthh committed Sep 16, 2024
1 parent 9737c77 commit c232790
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/Aardvark.SceneGraph.Assimp/Loader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ module Loader =
let private VertexBoneWeights4 = Symbol.Create "VertexBoneWeights4"
let private VertexBoneIndices4 = Symbol.Create "VertexBoneIndices4"

open System.Runtime.InteropServices
open Microsoft.FSharp.NativeInterop

let private bitsToV4f(v : obj) =
let mutable res = V4f.Zero
let gc = GCHandle.Alloc(v, GCHandleType.Pinned)
try
let size = min (Marshal.SizeOf v) sizeof<V4f>
Marshal.Copy (gc.AddrOfPinnedObject(), NativePtr.toNativeInt &&res, size)
res
finally
gc.Free()

type Mesh =
{
index : int
Expand All @@ -95,17 +82,16 @@ module Loader =
member x.All = Seq.empty
member x.TryGetAttribute(sem) =
match x.geometry.IndexedAttributes.TryGetValue sem with
| (true, arr) ->
let b = arr |> ArrayBuffer :> IBuffer |> AVal.constant
Some (BufferView(b, arr.GetType().GetElementType()))
| _ ->
match x.geometry.SingleAttributes.TryGetValue sem with
| (true, value) ->
let v = bitsToV4f value
Some (BufferView(SingleValueBuffer(AVal.constant v), value.GetType()))
| (true, arr) ->
Some <| BufferView(arr)

| _ ->
Some (BufferView(SingleValueBuffer(AVal.constant V4f.Zero), typeof<V4f>))
| _ ->
match x.geometry.SingleAttributes.TryGetValue sem with
| (true, value) ->
Some <| BufferView(SingleValueBuffer.create value)

| _ ->
Some <| BufferView(SingleValueBuffer<V4f>.Zero)

member x.Dispose() = ()

Expand Down

0 comments on commit c232790

Please sign in to comment.