Post

Replies

Boosts

Views

Activity

Reply to SCNGeometry and .copy()
as an attempted work-around I created a global array of mySCNGeometry.copy() which should have allowed the materials to be changed independently as stated in the Developer Documentation. They are in fact all the same geometry whereas changing any one "copy" changes them all.
Topic: Graphics & Games SubTopic: SceneKit Tags:
Dec ’24
Reply to SCNGeometry and .copy()
OK, I have just learned that objc methods can be called with Swift. Most examples are of custom functions or methods. How can I call the existing objc version of .copy() since Swift's doesn't work? Thanks fyi: I could never grasp objc and stopped programming during that period. Please be generous with example code.
Topic: Graphics & Games SubTopic: SceneKit Tags:
Dec ’24
Reply to SCNGeometry and .copy()
curiously, when I use .copy() on an SCNGeometry the geometry?.geometrySourceChannels, geometry?.elements, and geometry?.materials are all == to the original but the test whether the geometries themselves are equal returns false. How can a copy not equal its original? Idk what else to test for "as missing" from the copy() .
Topic: Graphics & Games SubTopic: SceneKit Tags:
Dec ’24
Reply to SceneView camera viewpoint restoration
SceneKit and SwiftUI are both imported. The documentation shows SceneView is a member of both yet after SceneView is initiated any attempt to access ".defaultCameraController" gives the error "This property is defined on SCNView and may not be available in this context." And indeed, is not. So I'm guessing the SwiftUI-SceneView overrides the SceneKit-SceneView and it has no ".defaultCameraController" nor a camera as far as I can tell. Every search involves importing AVFoundation which seems like another can of worms. Converting to ARKit, likewise. If the user chooses to manipulate the viewpoint, then he'll just have to restore it himself.
Nov ’24
Reply to SecureCoding roadblock?
FYI, I append JSON files millions of times per file. Here's the code: func saveBAToJSON(BA: myCustomClass) { let fileName = "created from BA" let ArchiveURL = getArchiveURL(fileName: fileName, ext: "JSON") var ArchiveDirectoryPath = fileDirPath let localFileManager = FileManager() do { let resources = try? ArchiveURL.resourceValues(forKeys: [.fileSizeKey]) let fileSize = resources?.fileSize ?? 0 /* The JSON file is appended many times and it must be limited in size otherwise memory is over taxed. maxFileSize is a global var that is machine specific. */ if fileSize > maxFileSize { let dirContents = try! localFileManager.contentsOfDirectory(atPath: ArchiveDirectoryPath) var elemFiles = 0 /* If a file would exceed MaxFileSize, start a new file copying it and appending an incremented counter to the name. */ for elem in 0..<dirContents.count { if dirContents[elem].contains(fileName) { elemFiles += 1 } } try FileManager.default.copyItem(at: ArchiveURL, to: getArchiveURL(fileName: fileName+"-\(elemFiles)", ext: "JSON")) try FileManager.default.removeItem(at: ArchiveURL) } } catch { print("\(Date.now):\(#file):\(#line) saveBAToJSON():fileSize", error) } do { let myJSONencoder = JSONEncoder() myJSONencoder.nonConformingFloatEncodingStrategy = .convertToString(positiveInfinity: "+Infinity", negativeInfinity: "-Infinity", nan: "NaN") var data = try myJSONencoder.encode(BA) if let fileHandle = try? FileHandle(forWritingTo: ArchiveURL) { defer { fileHandle.closeFile() } /* This is the main trick: truncate the repeating JSON components from the top of file to be appended, strip the JSON components at the end of the file to append-to (after converting to base64) replacing it with a comma (in my case). Write to file. */ let truncateCount = UInt64(36 + filename.count + String(BA.myCustomClassElement1).count) /* you must count chars in your specific JSON's to get this right. I'm sure this could be coded to adapt to any JSON file. */ let strippedRange = data.range(of: Data(base64Encoded: "my base64 encoded repeating components at end-of-file" )!) let commaData = Data(base64Encoded: "LA==")! data.replaceSubrange(strippedRange!, with: commaData ) let end = try fileHandle.seekToEnd() if end > truncateCount { try fileHandle.truncate(atOffset: end - truncateCount ) try fileHandle.write(contentsOf: data ) } } else { try data.write(to: ArchiveURL, options: [.atomic, .noFileProtection]) } } catch { print("\(Date.now):\(#file):\(#line) saveBAToJSON():fileSize", error) } } Share and Enjoy homage Eskimo
Topic: App & System Services SubTopic: General Tags:
Feb ’24
Reply to simple? filename sort
Armed with Scott's clue, ".localizedStandard", here's what works: after collecting [URL] with "contentsOfDirectory(at:", parse-out a [String] from the URL components. apply .sorted(using: .localizedStandard) and use in Picker() from Picker() use the return value and re-assemble a path to use with "URL(fileWithPath:" finish-off with JSONDecoder() Gives a nice Finder-style Picker list and opens the file. Thanks Scott
Feb ’24
Reply to precompiler test for cpu count
Is this work entirely CPU bound? No GPU's involved, so I guess so. The app does nothing outside of the machine upon which it runs. Once the database is generated the app just becomes a viewing instrument. This reply is two weeks late because for two weeks the machine was busy generating useless data. lol. (Down from a 300 year estimated compute time, so yay, progress!) We can probably close this thread because I have no need to generate data on unknown machines. Thanks.
Topic: App & System Services SubTopic: Core OS Tags:
Jul ’22
Reply to precompiler test for cpu count
My original intent was flawed, i. e., trying to optimize code using pre-compiler tests would only be useful for those who would be compiling, and not app users. What do you plan to do with that info? My app has nested for-loops sometimes eighteen deep. By strategically placing DispatchQueue's between the outer loops I can keep all my cpu's busy, minimizing compute time. In an app I can Switch() on the ncpu to the appropriate nest for optimization. As one who compiles the code, it's actually easier for me to edit the nests to my machines ncpu. A second flaw in my thought process is that once the data is generated no-one need generate it again. Nevertheless, I love solving mysteries or maybe just pursuing solutions.
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’22
Reply to precompiler test for cpu count
Re-discovered eskimo's "//developer.apple.com/forums/thread/690310". Result: launch(tool: URL(fileURLWithPath: "/usr/sbin/sysctl"), arguments: ["-n", "hw.ncpu" ], completionHandler: { (status, outputData) in let output = String(data: outputData, encoding: .utf8) ?? "" self.ncpu = (output as NSString).integerValue print("done, status: \(status), output: \(self.ncpu)") }) where I had declared ncpu elsewhere in the app. Thank you eskimo!
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’22