Post

Replies

Boosts

Views

Activity

SpriteKit PPI
Hi, I’m looking for a way to keep some custom buttons in SpriteKit the same physical size (inches) accross iOS devices (or only slightly vary their size so they’re not humongous on large screens). How do I get PPI in Swift? (cannot be library code which doesn’t compile in Swift Playgrounds). I will use PPI for determining total screen size which I will use to determine how to adjust the button sizes while also respecting some physical desirable dimensions for the buttons. I'm only asking for handheld (same distance from eyes to screen) use, so I don't care about Apple TV (longer distance).
2
0
615
Jul ’24
Converted OBJ to SCN and now the object won't load
let pathToBalloon = Bundle.main.path(forResource: "./Balloon2", ofType: "scn")!     let balloonAsset = MDLAsset(url: URL(fileURLWithPath: pathToBalloon))     let balloonObject: MDLObject? = balloonAsset.object(at: 0)     let balloon = SCNNode(mdlObject: balloonObject!) // Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value Using an .obj file with a balloon works great and displays in SCNView just fine. To use extra features Xcode asked me to convert to a .scn format. The model loads just fine in the Xcode editor, however balloonAsset.object(at: 0) now returns nil. I really wanted to smooth the geometry and other stuff so continuing to use .obj files is meh. What could the issue be?
1
1
1.4k
Nov ’22
How to sort the indices of Slice<UnsafeMutableBufferPointer<Double>> using vDSP?
I’m using buffer in many other vDSP operations before the code below. To those operations it is naturally a contiguous piece of memory, and that’s handy as there are vastly reduced number of calls to vDSP. // […] many operations with buffer here var buffer = UnsafeMutableBufferPointer<Double>.allocate(capacity: 10000000) var sortedIndices: UnsafeMutablePointer<UInt> = UnsafeMutablePointer<UInt>.allocate(capacity: 10000000) for (indexIndices, indexC) in buffer.indices.enumerated() { sortedIndices[indexIndices] = UInt(indexC) } vDSP_vsortiD( UnsafePointer<Double>(buffer.baseAddress)!, sortedIndices, nil, UInt(buffer.count), vDSP.SortOrder.descending.rawValue ) buffer needs to be sorted sliced up (a grouped sort, where each Slice corresponds to some special attribute of the value and it needs to be sorted separately because the resulting data is used separately later). Also, copying the buffer’s contents into smaller buffers before every sort has to be avoided as performance is critical (as many times as possible per second). vDSP_vsortiD() and vDSP_vsorti() do not support Slice. For example this code is not possible since .baseAddress doesn’t exist on a Slice and I guess UnsafePointer doesn’t understand Slice either. var sliceOfBuffer: Slice<UnsafeMutableBufferPointer<Double>> = buffer[0...30000] vDSP_vsortiD( UnsafePointer<Double>(sliceOfBuffer.baseAddress)!, // This fails sortedIndices[0...30000], // This also fails nil, UInt(30000), vDSP.SortOrder.descending.rawValue ) // Is there another sort indices function which accepts those types as params? Many operations under vDSP accept Slice, however the above sort functions don’t. Swift v5.6
1
1
1k
Sep ’22