├── supportFiles ├── text │ └── japanese_hello.txt └── images │ ├── Lily.bmp │ ├── Lily.jpg │ ├── Lily.png │ ├── bit16.png │ ├── bit8.gif │ ├── bit8.jpg │ ├── bit8.png │ ├── bit8.tga │ ├── bit8.tif │ ├── leaf.png │ ├── smoke.png │ ├── test1.jpg │ ├── test1.png │ ├── bit8lzw.tif │ ├── bit16alpha.png │ ├── bit8alpha.png │ ├── bit8alpha.tga │ ├── hanabira_1.png │ ├── hanabira_2.png │ ├── hanabira_3.png │ ├── Lily359x257.png │ ├── LilyNoAlpha.png │ └── test16alpha.png ├── projects └── apple │ ├── Lily │ ├── LilySwift.xcodeproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ └── kengo.xcuserdatad │ │ │ └── WorkspaceSettings.xcsettings │ └── Configures │ │ ├── InfoMacTests.plist │ │ ├── InfoiOSTests.plist │ │ ├── InfoiOS.plist │ │ └── InfoMac.plist │ ├── LilySwift.xcworkspace │ ├── xcuserdata │ │ └── kengo.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ ├── WorkspaceSettings.xcsettings │ │ │ └── Bookmarks │ │ │ └── bookmarks.plist │ ├── xcshareddata │ │ └── WorkspaceSettings.xcsettings │ └── contents.xcworkspacedata │ └── LICENSE │ └── Apple.txt ├── Sources ├── LilyCore │ ├── LLMath.type.swift │ ├── extensions │ │ ├── LCData+LilyCore+overload.swift │ │ ├── LCData+LilyCore+ext.swift │ │ ├── LCString+LilyCore+overload.swift │ │ ├── ClosedRange+LilyCore+ext.swift │ │ ├── Data+LilyCore+ext.swift │ │ ├── LLSizeFloat+LilyCore+ext.swift │ │ └── CGSize+LilyCore+ext.swift │ ├── LCImage.proc.pending.swift │ ├── LLMath.const.swift │ ├── LCImageLoader.internal.swift │ ├── LCImageSaver.internal.swift │ ├── LCImage.hsvf.swift │ ├── LCImage.hsvi.swift │ ├── LCImage.rgba8.swift │ ├── LCImage.rgbaf.swift │ ├── LCImage.grey8.swift │ ├── LCImage.greyf.swift │ ├── LCImage.grey16.swift │ ├── LCImage.rgba16.swift │ ├── LCImageLoader.swift │ ├── LCImageSaver.swift │ ├── LLType.graphics.const.swift │ ├── LLError.swift │ ├── macro │ │ ├── LLMath.macro.swift │ │ └── LLLog.macro.swift │ ├── LCAlgoLine.swift │ ├── LLLog.swift │ ├── LLMath.util.swift │ ├── LCClock.swift │ ├── LCAlignedMemory.16.swift │ └── LCAlignedMemory.4096.swift ├── Lily │ ├── apple │ │ ├── extensions │ │ │ ├── UUID+Lily+ext.swift │ │ │ ├── String+Lily+ext.swift │ │ │ ├── UserDefault+Lily+ext.swift │ │ │ ├── CGColor+Lily+ext.swift │ │ │ └── CGImage+Lily+ext.swift │ │ ├── protocols │ │ │ └── LLField.swift │ │ ├── LLClock.swift │ │ ├── LLFileReader.swift │ │ ├── LLFileWriter.swift │ │ └── LLTextAttribute.swift │ ├── Lily.Family.swift │ ├── mac │ │ └── extensions │ │ │ ├── LLColor+Lily+ext.mac.swift │ │ │ └── NSColor+Lily+ext.swift │ └── ios │ │ └── extensions │ │ ├── LLColor+Lily+ext.ios.swift │ │ └── UIColor+Lily+ext.swift ├── Lily_View │ ├── mac │ │ ├── Lily.View.WindowController.mac.swift │ │ ├── extensions │ │ │ ├── NSToolbarItem+Lily+ext.mac.swift │ │ │ └── NSMenuItem+Lily+ext.mac.swift │ │ └── Lily.View.Tablet.mac.swift │ ├── ios │ │ └── extensions │ │ │ ├── UITouch+Lily+ext.swift │ │ │ └── UIWindowScene+Lily+ext.swift │ └── apple │ │ ├── extensions │ │ ├── CALayer+Lily+ext.swift │ │ └── CATransaction+Lily+ext.swift │ │ ├── Lily.View.RecursiveMutex.swift │ │ └── Lily.Field.ViewEvent.swift ├── Lily_Stage │ ├── Standard │ │ ├── Models │ │ │ ├── Lily.Stage.Model.Quadrangles.swift │ │ │ └── Lily.Stage.Model.Triangles.swift │ │ ├── Lily.Stage.Bundle.swift │ │ ├── Shaders │ │ │ ├── Lily.Stage.Model.Obj.metal │ │ │ ├── Lily.Stage.Macro.metal │ │ │ ├── Lily.Stage.MemoryLess.h │ │ │ ├── Lily.Stage.MemoryLess.metal │ │ │ └── Lily.Stage.MathMatrix.metal │ │ └── SMetal │ │ │ ├── Lily.Stage.Macro.SM.swift │ │ │ ├── Lily.Stage.Model.Obj.SMetal.swift │ │ │ ├── Lily.Stage.MemoryLess.SM.swift │ │ │ └── Lily.Stage.MemoryLess.h.SM.swift │ └── Playground │ │ ├── Model │ │ ├── Data │ │ │ └── Lily.Stage.Playground.Model.Enum.swift │ │ ├── Accessors │ │ │ ├── Lily.Stage.Playground.MDSphere.swift │ │ │ ├── Lily.Stage.Playground.MDObj.swift │ │ │ └── Lily.Stage.Playground.MDPool.swift │ │ ├── Shaders │ │ │ ├── Lily.Stage.Playground.Model.Lighting.Vs.metal │ │ │ ├── Lily.Stage.Playground.Model.Mesh.Fs.metal │ │ │ ├── Lily.Stage.Playground.Model.Mesh.ComDelta.metal │ │ │ ├── Lily.Stage.Playground.Model.Lighting.h │ │ │ ├── Lily.Stage.Playground.Model.Mesh.ShadowVs.metal │ │ │ ├── Lily.Stage.Playground.Model.Mesh.Vs.metal │ │ │ └── Lily.Stage.Playground.Model.Mesh.h │ │ └── SMetal │ │ │ ├── Lily.Stage.Playground.Model.Lighting.Vs.SM.swift │ │ │ ├── Lily.Stage.Playground.Model.Mesh.Fs.SM.swift │ │ │ ├── Lily.Stage.Playground.Model.Mesh.ComDelta.SM.swift │ │ │ └── Lily.Stage.Playground.Model.Lighting.h.SM.swift │ │ ├── sRGB │ │ ├── Shaders │ │ │ ├── Lily.Stage.Playground.SRGB.h │ │ │ ├── Lily.Stage.Playground.SRGB.Vs.metal │ │ │ └── Lily.Stage.Playground.SRGB.Fs.metal │ │ ├── SMetal │ │ │ ├── Lily.Stage.Playground.SRGB.h.SM.swift │ │ │ ├── Lily.Stage.Playground.SRGB.Vs.SM.swift │ │ │ ├── Lily.Stage.Playground.SRGB.Fs.SM.swift │ │ │ └── Lily.Stage.Playground.SRGB.SMetal.swift │ │ └── Renderers │ │ │ └── Lily.Stage.Playground.SRGBPass.swift │ │ ├── Lily.Stage.Playground.Family.swift │ │ ├── Billboard │ │ ├── Accessors │ │ │ ├── Lily.Stage.Playground.BBShaderActor.swift │ │ │ ├── Lily.Stage.Playground.BBEmpty.swift │ │ │ ├── Lily.Stage.Playground.BBCircle.swift │ │ │ ├── Lily.Stage.Playground.BBTriangle.swift │ │ │ ├── Lily.Stage.Playground.BBRecntangle.swift │ │ │ ├── Lily.Stage.Playground.BBBlurryCircle.swift │ │ │ ├── Lily.Stage.Playground.BBPool.swift │ │ │ ├── Lily.Stage.Playground.BBMask.swift │ │ │ ├── Lily.Stage.Playground.BBPicture.swift │ │ │ ├── Lily.Stage.Playground.BBShaderTriangle.swift │ │ │ └── Lily.Stage.Playground.BBShaderRectangle.swift │ │ ├── Shaders │ │ │ └── Lily.Stage.Playground.Billboard.ComDelta.metal │ │ ├── Data │ │ │ ├── Lily.Stage.Playground.Billboard.LocalUniform.swift │ │ │ ├── Lily.Stage.Playground.Billboard.Enum.swift │ │ │ └── Lily.Stage.Playground.Billboard.BBFunction.swift │ │ └── SMetal │ │ │ └── Lily.Stage.Playground.Billboard.ComDelta.SM.swift │ │ ├── Plane │ │ ├── Accessors │ │ │ ├── Lily.Stage.Playground.PGShaderActor.swift │ │ │ ├── Lily.Stage.Playground.PGEmpty.swift │ │ │ ├── Lily.Stage.Playground.PGCircle.swift │ │ │ ├── Lily.Stage.Playground.PGTriangle.swift │ │ │ ├── Lily.Stage.Playground.PGRectangle.swift │ │ │ ├── Lily.Stage.Playground.PGBlurryCircle.swift │ │ │ ├── Lily.Stage.Playground.PGPool.swift │ │ │ ├── Lily.Stage.Playground.PGMask.swift │ │ │ ├── Lily.Stage.Playground.PGPicture.swift │ │ │ ├── Lily.Stage.Playground.PGShaderTriangle.swift │ │ │ └── Lily.Stage.Playground.PGShaderRectangle.swift │ │ ├── Shaders │ │ │ └── Lily.Stage.Playground.Plane.ComDelta.metal │ │ ├── Data │ │ │ ├── Lily.Stage.Playground.Plane.LocalUniform.swift │ │ │ ├── Lily.Stage.Playground.Plane.Enum.swift │ │ │ └── Lily.Stage.Playground.Plane.PGFunction.swift │ │ └── SMetal │ │ │ └── Lily.Stage.Playground.Plane.ComDelta.SM.swift │ │ ├── Utils │ │ ├── Lily.Stage.Playground.ActorInterval.swift │ │ ├── Lily.Stage.Playground.ActorTimer.swift │ │ ├── Shaders │ │ │ ├── Lily.Stage.Playground.CameraUniform.h │ │ │ └── Lily.Stage.Playground.GlobalUniform.h │ │ └── SMetal │ │ │ └── Lily.Stage.Playground.CameraUniform.h.SMetal.swift │ │ ├── Lily.Stage.Playground.Serial.swift │ │ ├── Engines │ │ └── Lily.Stage.Playground.BaseRenderFlow.swift │ │ ├── Lily.Stage.Playground.Defines.swift │ │ ├── Lily.Stage.Playground.PGField.swift │ │ ├── Views │ │ └── Lily.Stage.Playground.PGTouch.swift │ │ └── Audio │ │ └── Accessors │ │ └── Lily.Stage.Playground.PGAudioPool.swift └── Lily_Metal │ ├── extensions │ ├── MTLRenderPassDescriptor+Lily+ext.swift │ ├── MTLComputePipelineDescriptor+Lily+ext.swift │ ├── MTLRenderPipelineDescriptor+Lily+ext.swift │ ├── MTLComputeCommandEncoder+Lily+ext.swift │ ├── MTLDepthStencilDescriptor+Lily+ext.swift │ ├── MTLRenderPassDepthAttachmentDescriptor+Lily+ext.swift │ └── MTLRenderPassColorAttachmentDescriptor+Lily+ext.swift │ ├── follows │ └── MTLRasterizationRateMap+Lily+follow.swift │ └── Lily.Metal.RingBuffer.swift ├── .gitignore ├── Tests └── apple │ └── LilyCore │ ├── TestLLLog.swift │ ├── swift_extensions │ ├── TestCGSize+ext.swift │ ├── TestData+ext.swift │ ├── TestCGRect+ext.swift │ ├── TestLCData+ext.swift │ ├── TestLLRect+ext.swift │ ├── TestLLSize+ext.swift │ ├── TestCGPoint+ext.swift │ ├── TestLLPoint+ext.swift │ ├── TestLCData+overload.swift │ ├── TestLCString+overload.swift │ └── TestLLPointInt+ext.swift │ ├── Helper.swift │ ├── TestLCClock.swift │ ├── TestLCAlignedMemory.swift │ ├── TestLCSystem.swift │ ├── TestLLError.swift │ ├── swift_macro_helper │ └── TestLLMath.macro.swift │ └── TestLCZ.swift ├── LICENSE └── Package.swift /supportFiles/text/japanese_hello.txt: -------------------------------------------------------------------------------- 1 | こんにちわ、良い天気ですね。 -------------------------------------------------------------------------------- /supportFiles/images/Lily.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/Lily.bmp -------------------------------------------------------------------------------- /supportFiles/images/Lily.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/Lily.jpg -------------------------------------------------------------------------------- /supportFiles/images/Lily.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/Lily.png -------------------------------------------------------------------------------- /supportFiles/images/bit16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit16.png -------------------------------------------------------------------------------- /supportFiles/images/bit8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8.gif -------------------------------------------------------------------------------- /supportFiles/images/bit8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8.jpg -------------------------------------------------------------------------------- /supportFiles/images/bit8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8.png -------------------------------------------------------------------------------- /supportFiles/images/bit8.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8.tga -------------------------------------------------------------------------------- /supportFiles/images/bit8.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8.tif -------------------------------------------------------------------------------- /supportFiles/images/leaf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/leaf.png -------------------------------------------------------------------------------- /supportFiles/images/smoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/smoke.png -------------------------------------------------------------------------------- /supportFiles/images/test1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/test1.jpg -------------------------------------------------------------------------------- /supportFiles/images/test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/test1.png -------------------------------------------------------------------------------- /supportFiles/images/bit8lzw.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8lzw.tif -------------------------------------------------------------------------------- /supportFiles/images/bit16alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit16alpha.png -------------------------------------------------------------------------------- /supportFiles/images/bit8alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8alpha.png -------------------------------------------------------------------------------- /supportFiles/images/bit8alpha.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/bit8alpha.tga -------------------------------------------------------------------------------- /supportFiles/images/hanabira_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/hanabira_1.png -------------------------------------------------------------------------------- /supportFiles/images/hanabira_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/hanabira_2.png -------------------------------------------------------------------------------- /supportFiles/images/hanabira_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/hanabira_3.png -------------------------------------------------------------------------------- /supportFiles/images/Lily359x257.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/Lily359x257.png -------------------------------------------------------------------------------- /supportFiles/images/LilyNoAlpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/LilyNoAlpha.png -------------------------------------------------------------------------------- /supportFiles/images/test16alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wdkk/LilySwift/HEAD/supportFiles/images/test16alpha.png -------------------------------------------------------------------------------- /projects/apple/Lily/LilySwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /projects/apple/LilySwift.xcworkspace/xcuserdata/kengo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /projects/apple/LilySwift.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /projects/apple/Lily/LilySwift.xcodeproj/project.xcworkspace/xcuserdata/kengo.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseTargetSettings 7 | 8 | 9 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLMath.type.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | // 角度 12 | public struct LLAngle 13 | { 14 | public var value:LLDouble 15 | 16 | init( radians:LLDouble ) { 17 | self.value = radians 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/Lily/apple/extensions/UUID+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// UUID拡張 14 | public extension UUID 15 | { 16 | var labelString:String { 17 | return uuidString.replace( old: "-", new: "_" ) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Sources/Lily_View/mac/Lily.View.WindowController.mac.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | #if os(macOS) 11 | 12 | import Foundation 13 | import AppKit 14 | 15 | extension Lily.View 16 | { 17 | public typealias WindowController = NSWindowController 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.mp3 2 | *.m4a 3 | *.wav 4 | 5 | .DS_Store 6 | 7 | html/ 8 | 9 | build/ 10 | _build/ 11 | _devbuild/ 12 | _xcdevbuild/ 13 | _xcarchivebuild/ 14 | _lib/ 15 | _app/ 16 | 17 | libLily*.a 18 | libLily*d.a 19 | Lily*.lib 20 | Lily*d.lib 21 | Lily*.framework 22 | Lily*.xcframework 23 | NUL 24 | 25 | 26 | *.xcodeproj/* 27 | !*.xcodeproj/project.pbxproj 28 | !*.xcworkspace/contents.xcworkspacedata 29 | xcuserdata/* 30 | UserInterfaceState.xcuserstate 31 | 32 | 33 | Projects/apple/Lily/DevEnv/ 34 | 35 | .swiftpm/ 36 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/LCData+LilyCore+overload.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// LCDataMake関数の型オーバーロード 14 | public func LCDataMakeWithBytes( _ bin:LLUInt8Ptr, _ length:Int ) -> LCDataSmPtr { 15 | return LCDataMakeWithBytes( bin, length.i64 ) 16 | } 17 | -------------------------------------------------------------------------------- /Sources/Lily/apple/extensions/String+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | import Foundation 14 | 15 | public extension String 16 | { 17 | func pixelSize( attr textAttr:LLTextAttribute ) async -> LLSize { 18 | return await self.pixelSize( attr: textAttr.lcAttr ) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.proc.pending.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public func LCImageProcBilateralFilter( 14 | _ img_src_:LCImageSmPtr, 15 | _ img_dst_:LCImageSmPtr, 16 | _ kernel:Int, 17 | _ dist:Double, 18 | _ lumi:Double 19 | ) 20 | { 21 | // TODO: 未実装 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLMath.const.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | // π 12 | public let LL_PI:Double = 3.141592653589793 13 | 14 | // 0.5π 15 | public let LL_PI_DIV2:Double = 1.570796326794897 16 | 17 | // 0.25π 18 | public let LL_PI_DIV4:Double = 0.785398163397448 19 | 20 | // 2π 21 | public let LL_2_PI:Double = 6.283185307179586 22 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Models/Lily.Stage.Model.Quadrangles.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Model 16 | { 17 | // 四角形メッシュ形状メモリクラス 18 | public class Quadrangles 19 | : Shape> 20 | { 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Models/Lily.Stage.Model.Triangles.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Model 16 | { 17 | // 三角形メッシュ形状メモリクラス 18 | public class Triangles 19 | : Shape> 20 | { 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /projects/apple/LilySwift.xcworkspace/xcuserdata/kengo.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | ShowSharedSchemesAutomaticallyEnabled 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Data/Lily.Stage.Playground.Model.Enum.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model 17 | { 18 | public enum LifeState : Float 19 | { 20 | case active = 1.0 21 | case trush = 0.0 22 | } 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/Shaders/Lily.Stage.Playground.SRGB.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import 12 | #import 13 | 14 | using namespace metal; 15 | 16 | struct SRGBVOut 17 | { 18 | float4 position [[ position ]]; 19 | uint ampID; 20 | }; 21 | 22 | struct SRGBFOut 23 | { 24 | float4 backBuffer [[ color(0) ]]; 25 | }; 26 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImageLoader.internal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageLoaderInternal 14 | { 15 | public init() {} 16 | } 17 | 18 | /// 画像ロードモジュール 19 | public class LCImageLoaderSmPtr 20 | { 21 | /// 内部オブジェクト 22 | var loader:LCImageLoaderInternal 23 | 24 | /// 初期化 25 | init() { loader = LCImageLoaderInternal() } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImageSaver.internal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | 12 | import Foundation 13 | 14 | public class LCImageSaverInternal 15 | { 16 | public init() {} 17 | } 18 | 19 | /// 画像セーブモジュール 20 | public class LCImageSaverSmPtr 21 | { 22 | /// 内部オブジェクト 23 | var saver:LCImageSaverInternal 24 | 25 | /// 初期化 26 | init() { saver = LCImageSaverInternal() } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLLLog.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLLog: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_log() { 26 | LLLog( "test" ) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestCGSize+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestCGSize_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestData+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestData_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestCGRect+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestCGRect_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLCData+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCData_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLLRect+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLRect_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLLSize+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLSize_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestCGPoint+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestCGPoint_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLLPoint+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLPoint_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLCData+overload.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCData_overload: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLCString+overload.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCString_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_extensions/TestLLPointInt+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLPointInt_ext: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_NONE() { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/Lily/apple/protocols/LLField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public final class LLEmpty : Sendable 14 | { 15 | public static let none = LLEmpty() 16 | } 17 | 18 | public protocol LLField 19 | { 20 | associatedtype TObj 21 | 22 | func appear() 23 | func appear( _ objs:TObj? ) 24 | } 25 | 26 | public extension LLField 27 | { 28 | func appear() { self.appear( nil ) } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/LCData+LilyCore+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// LCDataSmPtr拡張 14 | public extension LCDataSmPtr 15 | { 16 | /// Data型への変換(別メモリとして確保して返す) 17 | var data:Data { 18 | guard let ptr = LCDataPointer( self ) else { return Data() } 19 | guard let length = LCDataLength( self ).i else { return Data() } 20 | return Data( bytes: ptr, count: length ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/LCString+LilyCore+overload.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// LCDataMake関数の型オーバーロード(Int64 -> Int) 14 | public func LCStringMakeWithBytes( _ bin:LLUInt8Ptr, _ length:LLInt64 ) -> LCStringSmPtr { 15 | guard let leng = length.i else { 16 | LLLogWarning( "length(int64)をintに変換できませんでした." ) 17 | return LCStringZero() 18 | } 19 | return LCStringMakeWithBytes( bin, leng ) 20 | } 21 | -------------------------------------------------------------------------------- /Sources/Lily_View/ios/extensions/UITouch+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if os(iOS) || os(tvOS) || os(visionOS) 12 | 13 | import UIKit 14 | 15 | public extension UITouch 16 | { 17 | func locationPixel( in view:UIView?=nil ) -> LLPoint { 18 | let pt:CGPoint = self.location(in: view) 19 | let scale = LLSystem.retinaScale 20 | return LLPoint( (pt.x.d * scale), (pt.y.d * scale) ) 21 | } 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLRenderPassDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | extension MTLRenderPassDescriptor 17 | { 18 | public static func make( setupFunction:( inout MTLRenderPassDescriptor )->Void ) -> MTLRenderPassDescriptor { 19 | var desc = MTLRenderPassDescriptor() 20 | setupFunction( &desc ) 21 | return desc 22 | } 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Accessors/Lily.Stage.Playground.MDSphere.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Model 16 | { 17 | public class MDSphere : MDActor 18 | { 19 | @discardableResult 20 | public init( storage:ModelStorage? = ModelStorage.current ) { 21 | super.init( storage:storage, assetName:"sphere" ) 22 | } 23 | } 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /projects/apple/LilySwift.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 13 | 15 | 16 | 17 | 19 | 20 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Accessors/Lily.Stage.Playground.MDObj.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Model 16 | { 17 | public class MDObj : MDActor 18 | { 19 | @discardableResult 20 | public override init( storage:ModelStorage? = ModelStorage.current, assetName:String ) { 21 | super.init( storage:storage, assetName:assetName ) 22 | } 23 | } 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/follows/MTLRasterizationRateMap+Lily+follow.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | // TODO: CatalystのバージョンでRasterizationRateMapが使えないのでInt代入で代用しておく 17 | #if targetEnvironment(macCatalyst) 18 | extension Lily.Metal 19 | { 20 | public typealias RasterizationRateMap = Int 21 | } 22 | #else 23 | extension Lily.Metal 24 | { 25 | public typealias RasterizationRateMap = MTLRasterizationRateMap 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.hsvf.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageHSVf : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLHSVftoColorf } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftoHSVf } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .hsvf ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.hsvi.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageHSVi : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLHSVitoColorf } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftoHSVi } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .hsvi ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.rgba8.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageRGBA8 : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLColor8tof } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorfto8 } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .rgba8 ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.rgbaf.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageRGBAf : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLColorftof } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftof } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .rgbaf ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLComputePipelineDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | /// コメント未済 14 | 15 | import Foundation 16 | import Metal 17 | 18 | extension MTLComputePipelineDescriptor 19 | { 20 | public static var `default`:MTLComputePipelineDescriptor { 21 | return MTLComputePipelineDescriptor() 22 | } 23 | 24 | public func computeShader( _ shader:Lily.Metal.Shader ) { 25 | self.computeFunction = shader.function 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLRenderPipelineDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | /// コメント未済 14 | 15 | import Foundation 16 | import Metal 17 | 18 | extension MTLRenderPipelineDescriptor 19 | { 20 | public func vertexShader( _ shader:Lily.Metal.Shader ) { 21 | self.vertexFunction = shader.function 22 | } 23 | 24 | public func fragmentShader( _ shader:Lily.Metal.Shader ) { 25 | self.fragmentFunction = shader.function 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Sources/Lily_View/apple/extensions/CALayer+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if canImport(QuartzCore) 12 | import QuartzCore 13 | #endif 14 | 15 | #if canImport(QuartzCore) 16 | extension CALayer 17 | : LLUIRectControllable 18 | { 19 | public var center: CGPoint { 20 | get { return self.position } 21 | set { self.position = newValue } 22 | } 23 | 24 | public var ownFrame:CGRect { 25 | get { return self.bounds } 26 | set { self.bounds = newValue } 27 | } 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/Helper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// 丸め誤差100億倍した値(小数点以下10位)をint64で返す 14 | func roundDouble( _ num:Double ) -> Int64 { 15 | return Int64( ( num * 10000000000.0 ) ) 16 | } 17 | 18 | /// 対象の値が誤差±内に収まっているかをboolで返す 19 | extension Double { 20 | func withinRange( of value:Double, plus_or_minus:Double ) -> Bool { 21 | let minv = (value - plus_or_minus) 22 | let maxv = (value + plus_or_minus) 23 | return (minv <= self) && (self <= maxv) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/Lily/apple/LLClock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// 時間管理モジュール 14 | open class LLClock 15 | { 16 | /// 現在時間(ミリ秒)を取得する 17 | public static var now:LLInt64 { return LCClockNow() } 18 | 19 | open class Precision { 20 | /// 現在時間(秒 & 小数でのマイクロ秒までの値)を取得する 21 | public static var now:Double { return LCClockPrecisionNow() } 22 | } 23 | 24 | /// くりかえす呼び出すことでframe per secondをコンソールに出力する 25 | @MainActor public static func fps() { 26 | return LCClockFPS() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.grey8.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageGrey8 : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLGrey8toColorf } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftoGrey8 } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .grey8 ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.greyf.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageGreyf : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLGreyftoColorf } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftoGreyf } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .greyf ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.grey16.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageGrey16 : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLGrey16toColorf } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorftoGrey16 } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .grey16 ) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImage.rgba16.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public class LCImageRGBA16 : LCImageGenericRaw 14 | { 15 | public override func requestFunctionOfConvertRawColorFrom() -> ConvertFromFunc? { return LLColor16tof } 16 | public override func requestFunctionOfConvertRawColorTo() -> ConvertToFunc? { return LLColorfto16 } 17 | 18 | public required init( _ wid: Int, _ hgt: Int ) { 19 | super.init( wid, hgt ) 20 | treatMemory( wid, hgt, .rgba16 ) 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/ClosedRange+LilyCore+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public extension ClosedRange where Bound:BinaryInteger 14 | { 15 | var randomize:Bound { 16 | Bound( LLRandomi( Int32(self.upperBound - self.lowerBound) ) + Int32(self.lowerBound) ) 17 | } 18 | } 19 | 20 | public extension ClosedRange where Bound:BinaryFloatingPoint 21 | { 22 | var randomize:Bound { 23 | Bound( LLRandomd( Double(self.upperBound - self.lowerBound) ) + Double(self.lowerBound) ) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Lily.Stage.Playground.Family.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage 16 | { 17 | open class Playground 18 | { 19 | open class Shared { } 20 | 21 | open class Plane { } 22 | 23 | open class Billboard { } 24 | 25 | open class Model { 26 | open class Mesh { } 27 | open class Lighting { } 28 | } 29 | 30 | open class sRGB { } 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBShaderActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | open class BBShaderActor : BBActor 19 | { 20 | public init( storage:BBStorage?, shaderName:String ) { 21 | super.init( storage:storage ) 22 | status?.shaderIndex = BBShader.shared.getFuncIndex( name:shaderName ) 23 | } 24 | } 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBEmpty.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBEmpty : BBActor 18 | { 19 | @discardableResult 20 | public override init( storage:BBStorage? = BBStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .empty 23 | status?.compositeType = .none 24 | } 25 | } 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/Shaders/Lily.Stage.Playground.SRGB.Vs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.SRGB.h" 12 | 13 | vertex SRGBVOut Lily_Stage_Playground_SRGB_Vs 14 | ( 15 | uint vid [[vertex_id]], 16 | ushort amp_id [[ amplification_id ]] 17 | ) 18 | { 19 | const float2 vertices[] = { 20 | float2(-1, -1), 21 | float2( 3, -1), 22 | float2(-1, 3) 23 | }; 24 | 25 | SRGBVOut out; 26 | out.position = float4( vertices[vid], 0.0, 1.0 ); 27 | out.ampID = amp_id; 28 | return out; 29 | } 30 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGShaderActor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | open class PGShaderActor : PGActor 19 | { 20 | 21 | public init( storage:PlaneStorage?, shaderName:String ) { 22 | super.init( storage:storage ) 23 | status?.shaderIndex = PGShader.shared.getFuncIndex( name:shaderName ) 24 | } 25 | } 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Sources/Lily_View/apple/extensions/CATransaction+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | #if canImport(QuartzCore) 13 | import QuartzCore 14 | #endif 15 | 16 | #if canImport(QuartzCore) 17 | public extension CATransaction 18 | { 19 | static func stop( _ f: ()->() ) { 20 | CATransaction.begin() 21 | //CATransaction.setValue( kCFBooleanTrue, forKey: kCATransactionDisableActions ) 22 | CATransaction.setDisableActions( true ) 23 | 24 | f() 25 | 26 | CATransaction.commit() 27 | } 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLCClock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCClock : XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_init() { 26 | LCClockInit() 27 | } 28 | 29 | func test_now() { 30 | // 時間が取れているかを取得 31 | XCTAssertTrue( 0 < LCClockNow() ) 32 | } 33 | 34 | func test_fps() { 35 | LCClockFPS() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGEmpty.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGEmpty : PGActor 18 | { 19 | @discardableResult 20 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .empty 23 | status?.compositeType = .none 24 | self.scale( square:2.0 ) 25 | } 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Lily.Stage.Bundle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | extension Lily.Stage 17 | { 18 | public static var bundle:Bundle? { 19 | Bundle( path:LLPath.bundle() + "/LilySwift_LilySwift.bundle" ) 20 | } 21 | 22 | public static func metalLibrary( of device:MTLDevice ) throws -> MTLLibrary { 23 | guard let bundle = bundle else { throw NSError( domain:"LilySwiftのバンドルが取得できませんでした", code:1 ) } 24 | return try device.makeDefaultLibrary( bundle:bundle ) 25 | } 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/Shaders/Lily.Stage.Playground.SRGB.Fs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.SRGB.h" 12 | 13 | fragment SRGBFOut Lily_Stage_Playground_SRGB_Fs( 14 | SRGBVOut in [[ stage_in ]], 15 | texture2d_array resultTexture [[ texture(0) ]] 16 | ) 17 | { 18 | const auto pixelPos = uint2( floor( in.position.xy ) ); 19 | float4 color = resultTexture.read( pixelPos, in.ampID ); 20 | color.xyz = pow( color.xyz, float3( 2.2 ) ); 21 | 22 | SRGBFOut out; 23 | out.backBuffer = color; 24 | return out; 25 | } 26 | -------------------------------------------------------------------------------- /projects/apple/Lily/Configures/InfoMacTests.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /projects/apple/Lily/Configures/InfoiOSTests.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImageLoader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public func LCImageLoaderMake() -> LCImageLoaderSmPtr { 14 | return LCImageLoaderSmPtr() 15 | } 16 | 17 | public func LCImageLoaderLoad( _ loader_:LCImageLoaderSmPtr, _ file_path_:LCStringSmPtr ) -> LCImageSmPtr { 18 | return loader_.loader.load( file_path_ ) 19 | } 20 | 21 | public func LCImageLoaderLoadWithOption( _ loader_:LCImageLoaderSmPtr, _ file_path_:LCStringSmPtr, 22 | _ option_:LLImageLoadOption ) -> LCImageSmPtr { 23 | return loader_.loader.load( file_path_, option_ ) 24 | } 25 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Lighting.Vs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.Lighting.h" 12 | 13 | vertex Model::Lighting::VOut Lily_Stage_Playground_Model_Lighting_Vs 14 | ( 15 | uint vid [[vertex_id]], 16 | ushort amp_id [[ amplification_id ]] 17 | ) 18 | { 19 | const float2 vertices[] = { 20 | float2(-1, -1), 21 | float2( 3, -1), 22 | float2(-1, 3) 23 | }; 24 | 25 | Model::Lighting::VOut out; 26 | out.position = float4( vertices[vid], 1.0, 1.0 ); 27 | out.ampID = amp_id; 28 | return out; 29 | } 30 | -------------------------------------------------------------------------------- /Sources/Lily_View/ios/extensions/UIWindowScene+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if os(iOS) || os(tvOS) || os(visionOS) 12 | 13 | import UIKit 14 | 15 | public extension UIWindowScene 16 | { 17 | func windowMinSizeForCatalyst( _ size:LLSize ) { 18 | #if targetEnvironment(macCatalyst) 19 | self.sizeRestrictions?.minimumSize = size.cgSize 20 | #endif 21 | } 22 | 23 | func windowMaxSizeForCatalyst( _ size:LLSize ) { 24 | #if targetEnvironment(macCatalyst) 25 | self.sizeRestrictions?.maximumSize = size.cgSize 26 | #endif 27 | } 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLComputeCommandEncoder+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | /// コメント未済 14 | 15 | import Metal 16 | 17 | extension MTLComputeCommandEncoder 18 | { 19 | public func setBuffer( _ buffer:MTLBuffer, index idx:Int ) { 20 | self.setBuffer( buffer, offset: 0, index: idx ) 21 | } 22 | 23 | public func setBuffer( 24 | _ obj:T, 25 | offset:Int = 0, 26 | index idx:Int 27 | ) 28 | { 29 | self.setBuffer( obj.metalBuffer, offset: offset, index: idx ) 30 | } 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/SMetal/Lily.Stage.Playground.SRGB.h.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.sRGB 16 | { 17 | public static var h_SMetal:String { """ 18 | #import 19 | #import 20 | 21 | using namespace metal; 22 | 23 | struct SRGBVOut 24 | { 25 | float4 position [[ position ]]; 26 | uint ampID; 27 | }; 28 | 29 | struct SRGBFOut 30 | { 31 | float4 backBuffer [[ color(0) ]]; 32 | }; 33 | """ 34 | } 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Shaders/Lily.Stage.Model.Obj.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #ifndef Lily_Stage_Model_Obj_h 12 | #define Lily_Stage_Model_Obj_h 13 | 14 | #import 15 | 16 | namespace Lily 17 | { 18 | namespace Stage 19 | { 20 | namespace Model 21 | { 22 | namespace Obj 23 | { 24 | struct Vertex 25 | { 26 | simd::float3 position; 27 | simd::float3 normal; 28 | simd::float3 color; 29 | }; 30 | }; 31 | }; 32 | }; 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCImageSaver.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public func LCImageSaverMake() -> LCImageSaverSmPtr { 14 | return LCImageSaverSmPtr() 15 | } 16 | 17 | public func LCImageSaverSave( _ saver_:LCImageSaverSmPtr, _ img_:LCImageSmPtr, _ file_path_:LCStringSmPtr ) -> Bool { 18 | return saver_.saver.save( img_, file_path_ ) 19 | } 20 | 21 | public func LCImageSaverSaveWithOption( _ saver_:LCImageSaverSmPtr, _ img_:LCImageSmPtr, _ file_path_:LCStringSmPtr, 22 | _ option_:LLImageSaveOption ) -> Bool { 23 | return saver_.saver.save( img_, file_path_, option_ ) 24 | } 25 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Utils/Lily.Stage.Playground.ActorInterval.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import simd 14 | 15 | extension Lily.Stage.Playground 16 | { 17 | public struct ActorInterval 18 | { 19 | var sec:Double = 1.0 20 | var prev:Double = 0.0 21 | var field:TField 22 | 23 | public init( 24 | sec:Double, 25 | prev:Double, 26 | field:TField 27 | ) 28 | { 29 | self.sec = sec 30 | self.prev = prev 31 | self.field = field 32 | } 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Lily.Stage.Playground.Serial.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | // コメント未着手 13 | 14 | import Foundation 15 | 16 | extension Lily.Stage.Playground 17 | { 18 | open class Serial 19 | { 20 | nonisolated(unsafe) public static let shared = Serial() 21 | private init() { } 22 | 23 | private var semaphore = DispatchSemaphore( value:1 ) 24 | 25 | open func serialize( _ f:@escaping ()->() ) { 26 | _ = semaphore.wait( timeout:.distantFuture ) 27 | f() 28 | semaphore.signal() 29 | } 30 | } 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Shaders/Lily.Stage.Macro.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #ifndef Lily_Stage_Macro_h 12 | #define Lily_Stage_Macro_h 13 | 14 | #import 15 | 16 | using namespace metal; 17 | 18 | #if ( !TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST ) 19 | #define LILY_MEMORY_LESS 1 20 | #endif 21 | 22 | #if LILY_MEMORY_LESS 23 | #define lily_memory(i) color(i) 24 | #define lily_memory_float4 float4 25 | #define lily_memory_depth float 26 | #else 27 | #define lily_memory(i) texture(i) 28 | #define lily_memory_float4 texture2d 29 | #define lily_memory_depth depth2d 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /projects/apple/Lily/Configures/InfoiOS.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /Sources/Lily_View/apple/Lily.View.RecursiveMutex.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | // コメント未着手 12 | 13 | import Foundation 14 | 15 | extension Lily.View 16 | { 17 | open class RecursiveMutex 18 | { 19 | private var _count:Int = 0 20 | private(set) var locking:Bool = false 21 | 22 | public init() { } 23 | 24 | open func lock( _ f:@escaping ()->() ) { 25 | _count += 1 26 | if _count == 1 && !locking { 27 | locking = true 28 | f() 29 | } 30 | _count -= 1 31 | if _count == 0 { locking = false } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/Lily/Lily.Family.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | open class Lily 14 | { 15 | // View(AppKit/UIKit)のモジュールセット 16 | open class View 17 | { 18 | } 19 | 20 | // SwiftUIのモジュールセット 21 | open class UI 22 | { 23 | } 24 | 25 | // Metalのモジュールセット 26 | open class Metal 27 | { 28 | } 29 | 30 | // 3Dグラフィック系のモジュールセット 31 | open class Stage 32 | { 33 | // Swift<->Metalの共有モジュール 34 | open class Shared { } 35 | // モデルデータ系のモジュール 36 | open class Model { } 37 | } 38 | 39 | // フィールドモジュールセット 40 | open class Field 41 | { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Sources/Lily/apple/extensions/UserDefault+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// UserDefault拡張 14 | public extension UserDefaults 15 | { 16 | /// Int64型の保存 17 | /// - Parameters: 18 | /// - value: 書き込む値 19 | /// - key: 対象キー 20 | func set( _ value:Int64, key:String ) { 21 | let num = NSNumber( value: value ) 22 | self.set( num, forKey: key ) 23 | } 24 | 25 | /// Int64型での取得 26 | /// - Parameter key: 対象キー 27 | func int64( _ key:String ) -> Int64 { 28 | guard let num = self.object( forKey: key ) as? NSNumber else { return 0 } 29 | return num.int64Value 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Mesh.Fs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.Mesh.h" 12 | 13 | // フラグメントシェーダ 14 | fragment Model::GBufferFOut Lily_Stage_Playground_Model_Mesh_Fs 15 | ( 16 | const Model::Mesh::VOut in [[ stage_in ]] 17 | ) 18 | { 19 | Model::BRDFSet brdf; 20 | brdf.albedo = saturate( in.color ); 21 | brdf.normal = in.normal; 22 | brdf.specIntensity = 1.f; 23 | brdf.specPower = 1.f; 24 | brdf.ao = 0.f; 25 | brdf.shadow = 0.f; 26 | 27 | auto output = Model::BRDFToGBuffers( brdf ); 28 | output.GBufferDepth = in.position.z; 29 | return output; 30 | } 31 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Mesh.ComDelta.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.Mesh.h" 12 | 13 | kernel void Lily_Stage_Playground_Model_Mesh_Com_Delta 14 | ( 15 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 16 | device Model::Mesh::UnitStatus* statuses [[ buffer(1) ]], 17 | uint gid [[thread_position_in_grid]] 18 | ) 19 | { 20 | auto us = statuses[gid]; 21 | 22 | us.position += us.deltaPosition; 23 | us.scale += us.deltaScale; 24 | us.rotation += us.deltaRotation; 25 | us.color += us.deltaColor; 26 | us.life += us.deltaLife; 27 | 28 | statuses[gid] = us; 29 | } 30 | -------------------------------------------------------------------------------- /Sources/Lily/apple/extensions/CGColor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if os(macOS) 14 | import AppKit 15 | #else 16 | import UIKit 17 | #endif 18 | 19 | import CoreGraphics 20 | 21 | public extension CGColor 22 | { 23 | var llColor:LLColor { 24 | var R:CGFloat = 0.0 25 | var G:CGFloat = 0.0 26 | var B:CGFloat = 0.0 27 | var A:CGFloat = 0.0 28 | 29 | #if os(macOS) 30 | NSColor( cgColor:self )?.getRed( &R, green:&G, blue:&B, alpha: &A ) 31 | #else 32 | UIColor( cgColor:self ).getRed( &R, green:&G, blue:&B, alpha: &A ) 33 | #endif 34 | return LLColor( R: R.f, G: G.f, B: B.f, A: A.f ) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /projects/apple/Lily/Configures/InfoMac.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2019 Watanabe-Denki, Inc. All rights reserved. 23 | 24 | 25 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Shaders/Lily.Stage.Playground.Plane.ComDelta.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Plane.h" 12 | 13 | kernel void Lily_Stage_Playground_Plane_Com_Delta 14 | ( 15 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 16 | device Plane::UnitStatus* statuses [[ buffer(1) ]], 17 | uint gid [[thread_position_in_grid]] 18 | ) 19 | { 20 | auto us = statuses[gid]; 21 | 22 | us.position += us.deltaPosition; 23 | us.scale += us.deltaScale; 24 | us.angle += us.deltaAngle; 25 | us.color += us.deltaColor; 26 | us.color2 += us.deltaColor2; 27 | us.color3 += us.deltaColor3; 28 | us.color4 += us.deltaColor4; 29 | us.life += us.deltaLife; 30 | 31 | statuses[gid] = us; 32 | } 33 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/Data+LilyCore+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// Data型拡張 14 | public extension Data 15 | { 16 | /// LCDataSmPtrを用いた実体化 17 | /// - Parameter lcdata: データ 18 | init( _ lcdata:LCDataSmPtr ) { 19 | self.init() 20 | guard let ptr = LCDataPointer( lcdata ) else { return } 21 | guard let length = LCDataLength( lcdata ).i else { return } 22 | self.append( ptr, count: length ) 23 | } 24 | /// LCDataSmPtrへの変換(別メモリとして確保して返す) 25 | var lcdata:LCDataSmPtr { 26 | let lcd = LCDataMakeWithSize( self.count.i64 ) 27 | guard let ptr = LCDataPointer( lcd ) else { return LCDataMake() } 28 | self.copyBytes(to: ptr, count: self.count ) 29 | return lcd 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/Lily/apple/extensions/CGImage+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | #if os(macOS) 14 | import AppKit 15 | #else 16 | import UIKit 17 | #endif 18 | 19 | extension CGImage 20 | { 21 | public static func load( assetName:String ) -> CGImage? { 22 | #if os(macOS) 23 | return NSImage( named:assetName )?.BGRtoRGB().cgImage 24 | #else 25 | return UIImage( named:assetName )?.BGRtoRGB().cgImage 26 | #endif 27 | } 28 | 29 | public var bytes:UnsafePointer? { 30 | guard let provider = self.dataProvider else { return nil } 31 | return CFDataGetBytePtr( provider.data ) 32 | } 33 | 34 | public var size:LLSizeInt { 35 | return .init( self.width, self.height ) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Shaders/Lily.Stage.MemoryLess.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #ifndef Lily_Stage_MemoryLess_h 12 | #define Lily_Stage_MemoryLess_h 13 | 14 | #import 15 | #import 16 | #import "Lily.Stage.Macro.metal" 17 | 18 | using namespace metal; 19 | 20 | namespace Lily 21 | { 22 | namespace Stage 23 | { 24 | namespace MemoryLess 25 | { 26 | #if LILY_MEMORY_LESS 27 | float4 float4OfPos( uint2 pos, float4 mem ); 28 | float depthOfPos( uint2 pos, float mem ); 29 | #else 30 | float4 float4OfPos( uint2 pos, texture2d mem ); 31 | float depthOfPos( uint2 pos, depth2d mem ); 32 | #endif 33 | }; 34 | }; 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Shaders/Lily.Stage.MemoryLess.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import 12 | #import 13 | #import "Lily.Stage.MemoryLess.h" 14 | 15 | using namespace metal; 16 | 17 | namespace Lily 18 | { 19 | namespace Stage 20 | { 21 | namespace MemoryLess 22 | { 23 | #if LILY_MEMORY_LESS 24 | float4 float4OfPos( uint2 pos, float4 mem ) { return mem; }; 25 | float depthOfPos( uint2 pos, float mem ) { return mem; }; 26 | #else 27 | float4 float4OfPos( uint2 pos, texture2d mem ) { return mem.read( pos ); }; 28 | float depthOfPos( uint2 pos, depth2d mem ) { return mem.read( pos ); }; 29 | #endif 30 | }; 31 | }; 32 | }; 33 | 34 | -------------------------------------------------------------------------------- /Sources/Lily_View/mac/extensions/NSToolbarItem+Lily+ext.mac.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if os(macOS) 12 | 13 | import AppKit 14 | 15 | nonisolated(unsafe) private var __toolbaritem_callback = [NSToolbarItem:NSToolbarItem.Callback]() 16 | 17 | public extension NSToolbarItem 18 | { 19 | typealias Callback = (() -> Void) 20 | 21 | var callback:Callback? { 22 | get { return __toolbaritem_callback[self] } 23 | set { 24 | target = self 25 | action = #selector(objcActionHandler(_:)) 26 | __toolbaritem_callback[self] = newValue 27 | } 28 | } 29 | 30 | @objc private func objcActionHandler( _ sender: NSControl ) { 31 | guard sender == self else { return } 32 | self.callback?() 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Shaders/Lily.Stage.Playground.Billboard.ComDelta.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Billboard.h" 12 | 13 | kernel void Lily_Stage_Playground_Billboard_Com_Delta 14 | ( 15 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 16 | device Billboard::UnitStatus* statuses [[ buffer(1) ]], 17 | uint gid [[thread_position_in_grid]] 18 | ) 19 | { 20 | auto us = statuses[gid]; 21 | 22 | us.position += us.deltaPosition; 23 | us.scale += us.deltaScale; 24 | us.rotation += us.deltaRotation; 25 | us.angle += us.deltaAngle; 26 | us.color += us.deltaColor; 27 | us.color2 += us.deltaColor2; 28 | us.color3 += us.deltaColor3; 29 | us.color4 += us.deltaColor4; 30 | us.life += us.deltaLife; 31 | 32 | statuses[gid] = us; 33 | } 34 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Utils/Lily.Stage.Playground.ActorTimer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import simd 14 | 15 | extension Lily.Stage.Playground 16 | { 17 | public class ActorTimer 18 | { 19 | nonisolated(unsafe) public static let shared = ActorTimer() 20 | private init() {} 21 | 22 | public private(set) var startTime:Double = 0.0 23 | public private(set) var nowTime:Double = 0.0 24 | 25 | public func start() { 26 | startTime = LLClock.now.d / 1000.0 27 | nowTime = startTime 28 | } 29 | 30 | public func update() { 31 | nowTime = LLClock.now.d / 1000.0 32 | } 33 | 34 | public var elapsedTime:Double { nowTime - startTime } 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /projects/apple/LICENSE/Apple.txt: -------------------------------------------------------------------------------- 1 | Copyright © 2021 Apple Inc. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Data/Lily.Stage.Playground.Billboard.LocalUniform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | public struct LocalUniform 19 | { 20 | var shaderCompositeType:LLUInt32 21 | var drawingType:LLUInt32 22 | var drawingOffset:LLInt32 23 | 24 | public init( 25 | shaderCompositeType: CompositeType = .none, 26 | drawingType:DrawingType = .quadrangles 27 | ) 28 | { 29 | self.shaderCompositeType = shaderCompositeType.rawValue 30 | self.drawingType = drawingType.rawValue 31 | self.drawingOffset = drawingType == .quadrangles ? 0 : 4 32 | } 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLDepthStencilDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | extension MTLDepthStencilDescriptor 17 | { 18 | public static func make( setupFunction:( inout MTLDepthStencilDescriptor )->Void ) -> MTLDepthStencilDescriptor { 19 | var desc = MTLDepthStencilDescriptor() 20 | setupFunction( &desc ) 21 | return desc 22 | } 23 | 24 | @discardableResult 25 | public func depthCompare( _ function:MTLCompareFunction ) -> Self { 26 | self.depthCompareFunction = function 27 | return self 28 | } 29 | 30 | @discardableResult 31 | public func depthWriteEnabled( _ enabled:Bool ) -> Self { 32 | self.isDepthWriteEnabled = enabled 33 | return self 34 | } 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/SMetal/Lily.Stage.Playground.SRGB.Vs.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.sRGB 16 | { 17 | public static var Vs_SMetal:String { """ 18 | //#import "Lily.Stage.Playground.SRGB.h" 19 | \(Lily.Stage.Playground.sRGB.h_SMetal) 20 | 21 | vertex SRGBVOut Lily_Stage_Playground_SRGB_Vs 22 | ( 23 | uint vid [[vertex_id]], 24 | ushort amp_id [[ amplification_id ]] 25 | ) 26 | { 27 | const float2 vertices[] = { 28 | float2(-1, -1), 29 | float2( 3, -1), 30 | float2(-1, 3) 31 | }; 32 | 33 | SRGBVOut out; 34 | out.position = float4( vertices[vid], 0.0, 1.0 ); 35 | out.ampID = amp_id; 36 | return out; 37 | } 38 | """ 39 | } 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Sources/Lily_View/mac/Lily.View.Tablet.mac.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if os(macOS) 12 | 13 | import AppKit 14 | 15 | extension Lily.View 16 | { 17 | open class Tablet 18 | { 19 | nonisolated(unsafe) static var _state = 20 | LLTabletState( x: 0.0, y: 0.0, z: 0.0, twist: 0.0, altitude: 0.0, azimuth: 0.0, pressure: 1.0 ) 21 | 22 | public static func updateState( event:NSEvent ) { 23 | _state.x = event.absoluteX.f 24 | _state.y = event.absoluteY.f 25 | _state.z = event.absoluteZ.f 26 | _state.pressure = event.pressure 27 | _state.twist = 0.0 28 | _state.altitude = 0.0 29 | _state.azimuth = 0.0 30 | } 31 | 32 | public static func currentState() -> LLTabletState { 33 | return _state 34 | } 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Sources/Lily/apple/LLFileReader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// ファイル読み込みモジュール 14 | open class LLFileReader 15 | { 16 | /// LilyCoreオブジェクト 17 | fileprivate var fr:LCFileReaderSmPtr 18 | 19 | /// 指定したパスのファイルでファイル読み込みオブジェクトを作成する 20 | /// - Parameter path: 読み込むファイルパス 21 | public init( path:String ) { 22 | fr = LCFileReaderMake( path.lcStr ) 23 | } 24 | 25 | /// ファイル読み込みオブジェクトがアクティブかどうかを取得する 26 | public var isActive:Bool { 27 | return LCFileReaderIsActive( fr ) 28 | } 29 | 30 | /// 前回読み終わった位置から指定したbinポインタにlengthの長さのバイト列を読み込む 31 | /// - Parameters: 32 | /// - bin: 読み込み先ポインタ 33 | /// - length: 長さ(バイト) 34 | /// - Returns: 読み込み成功 = true, 失敗 = false 35 | open func read( _ bin:LLNonNullUInt8Ptr, length:LLInt64 ) -> Bool { 36 | return LCFileReaderRead( fr, bin, length ) 37 | } 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020~ Watanabe-Denki, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/SMetal/Lily.Stage.Playground.SRGB.Fs.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.sRGB 16 | { 17 | public static var Fs_SMetal:String { """ 18 | //#import "Lily.Stage.Playground.SRGB.h" 19 | \(Lily.Stage.Playground.sRGB.h_SMetal) 20 | 21 | fragment SRGBFOut Lily_Stage_Playground_SRGB_Fs( 22 | SRGBVOut in [[ stage_in ]], 23 | texture2d_array resultTexture [[ texture(0) ]] 24 | ) 25 | { 26 | const auto pixelPos = uint2( floor( in.position.xy ) ); 27 | float4 color = resultTexture.read( pixelPos, in.ampID ); 28 | color.xyz = pow( color.xyz, float3( 2.2 ) ); 29 | 30 | SRGBFOut out; 31 | out.backBuffer = color; 32 | return out; 33 | } 34 | """ 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLType.graphics.const.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LLType.graphics.const.swift 3 | // LilySwift 4 | // 5 | // Created by Kengo on 2020/01/04. 6 | // Copyright © 2020 Watanabe-DENKI, Inc.. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /// LLColor8各要素の最小値 12 | public let LLColor8_MinValue:LLUInt8 = 0 13 | /// LLColor8各要素の最大値 14 | public let LLColor8_MaxValue:LLUInt8 = 255 15 | 16 | /// LLColor16各要素の最小値 17 | public let LLColor16_MinValue:LLUInt16 = 0 18 | /// LLColor16各要素の最大値 19 | public let LLColor16_MaxValue:LLUInt16 = 65535 20 | 21 | /// LLColor32各要素の最小値 22 | public let LLColor32_MinValue:LLInt32 = -2147483648 23 | /// LLColor32各要素の最大値 24 | public let LLColor32_MaxValue:LLInt32 = 2147483647 25 | 26 | /// LLColor64各要素の最小値 27 | public let LLColor64_MinValue:LLInt64 = -9223372036854775808 28 | /// LLColor64各要素の最大値 29 | public let LLColor64_MaxValue:LLInt64 = 9223372036854775807 30 | 31 | /// LLColor各要素の最小値 32 | public let LLColor_MinValue:LLFloat = 0.0 33 | /// LLColor各要素の最大値 34 | public let LLColor_MaxValue:LLFloat = 1.0 35 | 36 | /// LLColorD各要素の最小値 37 | public let LLColorD_MinValue:LLDouble = 0.0 38 | /// LLColorD各要素の最大値 39 | public let LLColorD_MaxValue:LLDouble = 1.0 40 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/SMetal/Lily.Stage.Playground.Model.Lighting.Vs.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model.Lighting 17 | { 18 | public static var Vs_SMetal:String { """ 19 | //#import "Lily.Stage.Playground.Model.Lighting.h" 20 | \(Lily.Stage.Playground.Model.Lighting.h_SMetal) 21 | 22 | vertex Model::Lighting::VOut Lily_Stage_Playground_Model_Lighting_Vs 23 | ( 24 | uint vid [[vertex_id]], 25 | ushort amp_id [[ amplification_id ]] 26 | ) 27 | { 28 | const float2 vertices[] = { 29 | float2(-1, -1), 30 | float2( 3, -1), 31 | float2(-1, 3) 32 | }; 33 | 34 | Model::Lighting::VOut out; 35 | out.position = float4( vertices[vid], 1.0, 1.0 ); 36 | out.ampID = amp_id; 37 | return out; 38 | } 39 | 40 | """ 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLRenderPassDepthAttachmentDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | extension MTLRenderPassDepthAttachmentDescriptor 17 | { 18 | @discardableResult 19 | public func clearDepth( _ depth:Double ) -> Self { 20 | self.clearDepth = depth 21 | return self 22 | } 23 | 24 | @discardableResult 25 | public func loadAction( _ action:MTLLoadAction ) -> Self { 26 | self.loadAction = action 27 | return self 28 | } 29 | 30 | @discardableResult 31 | public func storeAction( _ action:MTLStoreAction ) -> Self { 32 | self.storeAction = action 33 | return self 34 | } 35 | 36 | @discardableResult 37 | public func action( load:MTLLoadAction, store:MTLStoreAction ) -> Self { 38 | self.loadAction = load 39 | self.storeAction = store 40 | return self 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Engines/Lily.Stage.Playground.BaseRenderFlow.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import MetalKit 14 | 15 | extension Lily.Stage.Playground 16 | { 17 | open class BaseRenderFlow 18 | { 19 | var device:MTLDevice 20 | 21 | public init( device:MTLDevice ) { 22 | self.device = device 23 | } 24 | 25 | @MainActor 26 | open func changeSize( scaledSize:CGSize ) { } 27 | 28 | open func render( 29 | commandBuffer:MTLCommandBuffer, 30 | rasterizationRateMap:Lily.Metal.RasterizationRateMap?, 31 | viewports:[MTLViewport], 32 | viewCount:Int, 33 | destinationTexture:MTLTexture?, 34 | depthTexture:MTLTexture?, 35 | uniforms:Lily.Metal.RingBuffer 36 | ) 37 | { 38 | LLLog( "overrideしてください" ) 39 | } 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Data/Lily.Stage.Playground.Plane.LocalUniform.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | public struct LocalUniform 19 | { 20 | var projectionMatrix:LLMatrix4x4 21 | var shaderCompositeType:LLUInt32 22 | var drawingType:LLUInt32 23 | var drawingOffset:LLInt32 24 | 25 | public init( 26 | projectionMatrix: LLMatrix4x4 = .identity, 27 | shaderCompositeType:CompositeType = .none, 28 | drawingType:DrawingType = .quadrangles 29 | ) 30 | { 31 | self.projectionMatrix = projectionMatrix 32 | self.shaderCompositeType = shaderCompositeType.rawValue 33 | self.drawingType = drawingType.rawValue 34 | self.drawingOffset = drawingType == .quadrangles ? 0 : 4 35 | } 36 | } 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Lily.Stage.Playground.Defines.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import MetalKit 14 | import simd 15 | 16 | extension Lily.Stage.Playground 17 | { 18 | public static let shadowCascadesCount:Int = 3 19 | 20 | public enum BufferFormats 21 | { 22 | public static let backBuffer:MTLPixelFormat = .bgra8Unorm_srgb 23 | 24 | public static let linearSRGBBuffer:MTLPixelFormat = .bgra8Unorm 25 | 26 | public static let GBuffer0:MTLPixelFormat = .bgra8Unorm_srgb 27 | public static let GBuffer1:MTLPixelFormat = .rgba8Unorm 28 | public static let GBuffer2:MTLPixelFormat = .rgba8Unorm 29 | public static let GBufferDepth:MTLPixelFormat = .r32Float 30 | public static let depth:MTLPixelFormat = .depth32Float_stencil8 31 | public static let shadowDepth:MTLPixelFormat = .depth32Float_stencil8 32 | public static let sampleCount:Int = 1 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/SMetal/Lily.Stage.Macro.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage 17 | { 18 | public static var Macro_SMetal:String { """ 19 | #ifndef Lily_Stage_Macro_h 20 | #define Lily_Stage_Macro_h 21 | 22 | #import 23 | 24 | using namespace metal; 25 | 26 | #if ( !TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST ) 27 | #define LILY_MEMORY_LESS 1 28 | #endif 29 | 30 | #if LILY_MEMORY_LESS 31 | #define lily_memory(i) color(i) 32 | #define lily_memory_float4 float4 33 | #define lily_memory_depth float 34 | #else 35 | #define lily_memory(i) texture(i) 36 | #define lily_memory_float4 texture2d 37 | #define lily_memory_depth depth2d 38 | #endif 39 | 40 | #endif 41 | """ 42 | } 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLCAlignedMemory.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCAlignedMemory: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_allocate_memory166() { 26 | let memory = LCAlignedMemory16Make() 27 | 28 | LCAlignedMemory16Resize( memory, 100 ) 29 | 30 | XCTAssertEqual( LCAlignedMemory16Length( memory ), 100 ) 31 | XCTAssertEqual( LCAlignedMemory16AllocatedLength( memory ), 112 ) 32 | } 33 | 34 | func test_allocate_memory4096() { 35 | let memory = LCAlignedMemory4096Make() 36 | 37 | LCAlignedMemory4096Resize( memory, 100 ) 38 | 39 | XCTAssertEqual( LCAlignedMemory4096Length( memory ), 100 ) 40 | XCTAssertEqual( LCAlignedMemory4096AllocatedLength( memory ), 4096 ) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/SMetal/Lily.Stage.Playground.Model.Mesh.Fs.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model.Mesh 17 | { 18 | public static var Fs_SMetal:String { """ 19 | //#import "Lily.Stage.Playground.Model.Mesh.h" 20 | \(Lily.Stage.Playground.Model.Mesh.h_SMetal) 21 | 22 | // フラグメントシェーダ 23 | fragment Model::GBufferFOut Lily_Stage_Playground_Model_Mesh_Fs 24 | ( 25 | const Model::Mesh::VOut in [[ stage_in ]] 26 | ) 27 | { 28 | Model::BRDFSet brdf; 29 | brdf.albedo = saturate( in.color ); 30 | brdf.normal = in.normal; 31 | brdf.specIntensity = 1.f; 32 | brdf.specPower = 1.f; 33 | brdf.ao = 0.f; 34 | brdf.shadow = 0.f; 35 | 36 | auto output = Model::BRDFToGBuffers( brdf ); 37 | output.GBufferDepth = in.position.z; 38 | return output; 39 | } 40 | """ 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | fileprivate struct LLErrorInternal 14 | { 15 | var code:Int = 0 16 | var description:String = "" 17 | } 18 | 19 | public class LLErrorSmPtr 20 | { 21 | fileprivate var e:LLErrorInternal 22 | 23 | fileprivate init() { 24 | e = LLErrorInternal() 25 | } 26 | } 27 | 28 | func LLErrorMake() -> LLErrorSmPtr { 29 | let err = LLErrorSmPtr() 30 | err.e.code = 0 31 | err.e.description = "" 32 | return err 33 | } 34 | 35 | func LLErrorNone( _ err:LLErrorSmPtr ) { 36 | err.e.code = 0 37 | err.e.description = "" 38 | } 39 | 40 | func LLErrorSet( _ err:LLErrorSmPtr, _ code:Int, _ description:LLConstCCharsPtr ) { 41 | err.e.code = code 42 | err.e.description = String( cString: description ) 43 | } 44 | 45 | func LLErrorCode( _ err:LLErrorSmPtr ) -> Int { 46 | return err.e.code 47 | } 48 | 49 | func LLErrorDescription( _ err:LLErrorSmPtr ) -> LCStringSmPtr { 50 | return err.e.description.lcStr 51 | } 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/SMetal/Lily.Stage.Model.Obj.SMetal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Model 17 | { 18 | public static var Obj_SMetal:String { """ 19 | #ifndef Lily_Stage_Model_Obj_h 20 | #define Lily_Stage_Model_Obj_h 21 | 22 | #import 23 | 24 | namespace Lily 25 | { 26 | namespace Stage 27 | { 28 | namespace Model 29 | { 30 | namespace Obj 31 | { 32 | struct Vertex 33 | { 34 | simd::float3 position; 35 | simd::float3 normal; 36 | simd::float3 color; 37 | }; 38 | }; 39 | }; 40 | }; 41 | }; 42 | 43 | #endif 44 | """ 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/SMetal/Lily.Stage.Playground.Model.Mesh.ComDelta.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model.Mesh 17 | { 18 | public static var ComDelta_SMetal:String { """ 19 | //#import "Lily.Stage.Playground.Model.Mesh.h" 20 | \(Lily.Stage.Playground.Model.Mesh.h_SMetal) 21 | 22 | kernel void Lily_Stage_Playground_Model_Mesh_Com_Delta 23 | ( 24 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 25 | device Model::Mesh::UnitStatus* statuses [[ buffer(1) ]], 26 | uint gid [[thread_position_in_grid]] 27 | ) 28 | { 29 | auto us = statuses[gid]; 30 | 31 | us.position += us.deltaPosition; 32 | us.scale += us.deltaScale; 33 | us.rotation += us.deltaRotation; 34 | us.color += us.deltaColor; 35 | us.life += us.deltaLife; 36 | 37 | statuses[gid] = us; 38 | } 39 | """ 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Sources/LilyCore/macro/LLMath.macro.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// LLMaxマクロのSwift実装 14 | /// - Parameters: 15 | /// - v1: 比較値1 16 | /// - v2: 比較値2 17 | /// - Returns: v1, v2のうち大きい値 18 | public func LLMax( _ v1:T, _ v2:T ) -> T { 19 | return v1 > v2 ? v1 : v2 20 | } 21 | 22 | /// LLMinマクロのSwift実装 23 | /// - Parameters: 24 | /// - v1: 比較値1 25 | /// - v2: 比較値2 26 | /// - Returns: v1, v2のうち小さい値 27 | public func LLMin( _ v1:T, _ v2:T ) -> T { 28 | return v1 < v2 ? v1 : v2 29 | } 30 | 31 | /// 値を範囲で区切る. vの値をmin ~ maxの間に収めた値を返す 32 | /// - Parameters: 33 | /// - min: 最小値 34 | /// - v: 対象の値 35 | /// - max: 最大値 36 | /// - Returns: min~maxの間に収まるvの値 37 | public func LLWithin( min:T, _ v:T, max:T ) -> T { 38 | return LLMin( LLMax( min, v ), max ) 39 | } 40 | 41 | /// v1とv2の値を入れ替える 42 | /// - Parameters: 43 | /// - v1: 入れ替える値1 44 | /// - v2: 入れ替える値2 45 | public func LLSwap( _ v1:inout T, _ v2:inout T ) { 46 | let swap:T = v1 47 | v1 = v2 48 | v2 = swap 49 | } 50 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Data/Lily.Stage.Playground.Plane.Enum.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | public enum DrawingType : LLUInt32 19 | { 20 | case quadrangles = 0 21 | case triangles = 1 22 | } 23 | 24 | public enum LifeState : Float 25 | { 26 | case active = 1.0 27 | case trush = 0.0 28 | } 29 | 30 | public enum CompositeType : LLUInt32 31 | { 32 | case none = 0 33 | case alpha = 1 34 | case add = 2 35 | case sub = 3 36 | } 37 | 38 | public enum ShapeType : LLUInt32 39 | { 40 | case empty = 0 41 | case rectangle = 1 42 | case triangle = 2 43 | case circle = 3 44 | case blurryCircle = 4 45 | case picture = 101 46 | case mask = 102 47 | case shaderRectangle = 201 48 | case shaderTriangle = 202 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Utils/Shaders/Lily.Stage.Playground.CameraUniform.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #ifndef Lily_Stage_Shared_CameraUniform_h 12 | #define Lily_Stage_Shared_CameraUniform_h 13 | 14 | #import 15 | 16 | namespace Lily 17 | { 18 | namespace Stage 19 | { 20 | namespace Playground 21 | { 22 | struct CameraUniform 23 | { 24 | simd::float4x4 viewMatrix; 25 | simd::float4x4 projectionMatrix; 26 | simd::float4x4 viewProjectionMatrix; 27 | simd::float4x4 invOrientationProjectionMatrix; 28 | simd::float4x4 invViewProjectionMatrix; 29 | simd::float4x4 invProjectionMatrix; 30 | simd::float4x4 invViewMatrix; 31 | simd::float4 frustumPlanes[6]; 32 | simd::float3 position; 33 | simd::float3 up; 34 | simd::float3 right; 35 | simd::float3 direction; 36 | }; 37 | }; 38 | }; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Sources/Lily_View/mac/extensions/NSMenuItem+Lily+ext.mac.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if os(macOS) 12 | 13 | import AppKit 14 | 15 | nonisolated(unsafe) private var __menuitem_callback = [NSMenuItem:NSMenuItem.Callback]() 16 | 17 | public extension NSMenuItem 18 | { 19 | typealias Callback = (() -> Void) 20 | 21 | var callback:Callback? { 22 | get { 23 | return __menuitem_callback[self] 24 | } 25 | set { 26 | target = self 27 | action = #selector( objcActionHandler(_:) ) 28 | __menuitem_callback[self] = newValue 29 | } 30 | } 31 | 32 | convenience init(_ title:String, keyEquivalent: String, callback f: Callback? ) { 33 | self.init( title: title, action: nil, keyEquivalent: keyEquivalent ) 34 | self.callback = f 35 | } 36 | 37 | @objc private func objcActionHandler( _ sender: NSControl ) { 38 | guard sender == self else { return } 39 | self.callback?() 40 | } 41 | } 42 | 43 | public typealias LLMenuItem = NSMenuItem 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Data/Lily.Stage.Playground.Billboard.Enum.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | public enum DrawingType : LLUInt32 19 | { 20 | case quadrangles = 0 21 | case triangles = 1 22 | } 23 | 24 | public enum LifeState : Float 25 | { 26 | case active = 1.0 27 | case trush = 0.0 28 | } 29 | 30 | public enum CompositeType : LLUInt32 31 | { 32 | case none = 0 33 | case alpha = 1 34 | case add = 2 35 | case sub = 3 36 | } 37 | 38 | public enum ShapeType : LLUInt32 39 | { 40 | case empty = 0 41 | case rectangle = 1 42 | case triangle = 2 43 | case circle = 3 44 | case blurryCircle = 4 45 | case picture = 101 46 | case mask = 102 47 | case shaderRectangle = 201 48 | case shaderTriangle = 202 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /projects/apple/LilySwift.xcworkspace/xcuserdata/kengo.xcuserdatad/Bookmarks/bookmarks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | top-level-items 6 | 7 | 8 | destination 9 | 10 | rebasable-url 11 | 12 | base 13 | home-directory 14 | payload 15 | 16 | relative-path 17 | core/wd/dev/LilySwift 18 | 19 | 20 | type 21 | DVTDocumentLocation 22 | 23 | type 24 | bookmark 25 | 26 | 27 | destination 28 | 29 | rebasable-url 30 | 31 | base 32 | home-directory 33 | payload 34 | 35 | relative-path 36 | core/wd/dev/LilySwift 37 | 38 | 39 | type 40 | DVTDocumentLocation 41 | 42 | type 43 | bookmark 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/Lily.Metal.RingBuffer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if !os(watchOS) 14 | 15 | import Foundation 16 | import Metal 17 | 18 | extension Lily.Metal 19 | { 20 | open class RingBuffer 21 | { 22 | open var buffers:[Buffer] = [] 23 | private let ringLength:Int 24 | private var ringIndex:Int = 0 25 | 26 | public init( device:MTLDevice, ringSize:Int ) { 27 | ringLength = ringSize 28 | for _ in 0 ..< ringSize { 29 | buffers.append( .init( device:device, count:1 ) ) 30 | } 31 | } 32 | 33 | public func update( action:( inout T )->() ) { 34 | buffers[ringIndex].update( at:0, iteration:action ) 35 | } 36 | 37 | public var current:T? { buffers[ringIndex].accessor?.first } 38 | 39 | public var metalBuffer:MTLBuffer? { buffers[ringIndex].metalBuffer } 40 | 41 | public func next() { 42 | ringIndex = ( ringIndex + 1 ) % ringLength 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLCSystem.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCSystem: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_init() { 26 | LCSystemInit() 27 | } 28 | 29 | func test_getFreeMemory() { 30 | XCTAssertGreaterThan( LCSystemGetFreeMemory(), 0.0 ) 31 | } 32 | 33 | func test_getFreeStorage() { 34 | XCTAssertGreaterThan( LCSystemGetFreeStorage( "/" ), 0.0 ) 35 | } 36 | 37 | func test_getRetinaScale() { 38 | XCTAssertGreaterThan( LCSystemGetRetinaScale(), 0.0 ) 39 | } 40 | 41 | func test_getDpiScale() { 42 | XCTAssertGreaterThan( LCSystemGetDpiScale().width, 0.0 ) 43 | XCTAssertGreaterThan( LCSystemGetDpiScale().height, 0.0 ) 44 | } 45 | 46 | func test_sleep() { 47 | LCSystemSleep( 100 ) 48 | } 49 | 50 | func test_wait() { 51 | LCSystemWait( 100 ) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.9 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "LilySwift", 8 | platforms: [ 9 | .iOS( .v16 ), 10 | .macOS( .v13 ), 11 | .macCatalyst( .v16 ), 12 | .watchOS( .v9 ), 13 | .tvOS( .v16 ), 14 | .visionOS( .v1 ) 15 | ], 16 | products: [ 17 | .library( 18 | name: "LilySwift", 19 | targets: [ 20 | "LilySwift", 21 | "LilySwiftAlias" 22 | ] 23 | ) 24 | ], 25 | targets: [ 26 | .target( 27 | name: "LilySwift", 28 | dependencies: [], 29 | path: "./Sources/", 30 | swiftSettings: [ 31 | .define( "DEBUG", .when( platforms:[.iOS, .macOS, .macCatalyst, .watchOS, .tvOS, .visionOS], configuration:.debug ) ) 32 | ] 33 | ), 34 | .target( 35 | name: "LilySwiftAlias", 36 | dependencies: [ "LilySwift" ], 37 | path: "./Aliases/", 38 | swiftSettings: [ 39 | .define( "DEBUG", .when( platforms:[.iOS, .macOS, .macCatalyst, .watchOS, .tvOS, .visionOS], configuration:.debug ) ) 40 | ] 41 | ) 42 | ] 43 | ) 44 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/SMetal/Lily.Stage.Playground.Plane.ComDelta.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | public static var ComDelta_SMetal:String { """ 19 | //#import "Lily.Stage.Playground.Plane.h" 20 | \(Lily.Stage.Playground.Plane.h_SMetal) 21 | 22 | kernel void Lily_Stage_Playground_Plane_Com_Delta 23 | ( 24 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 25 | device Plane::UnitStatus* statuses [[ buffer(1) ]], 26 | uint gid [[thread_position_in_grid]] 27 | ) 28 | { 29 | auto us = statuses[gid]; 30 | 31 | us.position += us.deltaPosition; 32 | us.scale += us.deltaScale; 33 | us.angle += us.deltaAngle; 34 | us.color += us.deltaColor; 35 | us.color2 += us.deltaColor2; 36 | us.color3 += us.deltaColor3; 37 | us.color4 += us.deltaColor4; 38 | us.life += us.deltaLife; 39 | 40 | statuses[gid] = us; 41 | } 42 | 43 | """ 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Lighting.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import 12 | #import 13 | #import "../../../Standard/Shaders/Lily.Stage.MemoryLess.h" 14 | #import "../../Utils/Shaders/Lily.Stage.Playground.GlobalUniform.h" 15 | 16 | #import "Lily.Stage.Playground.Model.util.h" 17 | 18 | using namespace metal; 19 | using namespace Lily::Stage; 20 | using namespace Lily::Stage::Playground; 21 | 22 | namespace Lily 23 | { 24 | namespace Stage 25 | { 26 | namespace Playground 27 | { 28 | namespace Model 29 | { 30 | namespace Lighting 31 | { 32 | struct VOut 33 | { 34 | float4 position [[position]]; 35 | uint ampID; 36 | }; 37 | 38 | struct FOut 39 | { 40 | float4 backBuffer [[ color(IDX_OUTPUT) ]]; 41 | }; 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLLError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLError: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_init() { 26 | let err = LLErrorMake() 27 | XCTAssertEqual( LLErrorCode( err ), 0 ) 28 | XCTAssertTrue( LCStringIsEqual( LLErrorDescription( err ), LCStringZero() ) ) 29 | } 30 | 31 | func test_NONE() { 32 | let err = LLErrorMake() 33 | LLErrorNone( err ) 34 | XCTAssertEqual( LLErrorCode( err ), 0 ) 35 | XCTAssertTrue( LCStringIsEqual( LLErrorDescription( err ), LCStringZero() ) ) 36 | } 37 | 38 | func test_set() { 39 | let err = LLErrorMake() 40 | LLErrorSet( err, 1, "エラーを発生させました" ) 41 | 42 | XCTAssertEqual( LLErrorCode( err ), 1 ) 43 | XCTAssertEqual( String( LLErrorDescription( err ) ), "エラーを発生させました" ) 44 | } 45 | 46 | // LLErrorCodeとLLErrorDescriptionは上のテストで同時に用いるため省略 47 | } 48 | -------------------------------------------------------------------------------- /Sources/Lily_Metal/extensions/MTLRenderPassColorAttachmentDescriptor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Foundation 14 | import Metal 15 | 16 | extension MTLRenderPassColorAttachmentDescriptor 17 | { 18 | @discardableResult 19 | public func clearColor( _ color:MTLClearColor ) -> Self { 20 | self.clearColor = color 21 | return self 22 | } 23 | 24 | @discardableResult 25 | public func clearColor( _ color:LLColor ) -> Self { 26 | self.clearColor = color.metalColor 27 | return self 28 | } 29 | 30 | @discardableResult 31 | public func loadAction( _ action:MTLLoadAction ) -> Self { 32 | self.loadAction = action 33 | return self 34 | } 35 | 36 | @discardableResult 37 | public func storeAction( _ action:MTLStoreAction ) -> Self { 38 | self.storeAction = action 39 | return self 40 | } 41 | 42 | @discardableResult 43 | public func action( load:MTLLoadAction, store:MTLStoreAction ) -> Self { 44 | self.loadAction = load 45 | self.storeAction = store 46 | return self 47 | } 48 | } 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/SMetal/Lily.Stage.MemoryLess.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage 17 | { 18 | public static var MemoryLess_SMetal:String { """ 19 | #import 20 | #import 21 | //#import "Lily.Stage.MemoryLess.h" 22 | \(Lily.Stage.MemoryLess_h_SMetal) 23 | 24 | namespace Lily 25 | { 26 | namespace Stage 27 | { 28 | namespace MemoryLess 29 | { 30 | #if LILY_MEMORY_LESS 31 | float4 float4OfPos( uint2 pos, float4 mem ) { return mem; }; 32 | float depthOfPos( uint2 pos, float mem ) { return mem; }; 33 | #else 34 | float4 float4OfPos( uint2 pos, texture2d mem ) { return mem.read( pos ); }; 35 | float depthOfPos( uint2 pos, depth2d mem ) { return mem.read( pos ); }; 36 | #endif 37 | }; 38 | }; 39 | }; 40 | """ 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/SMetal/Lily.Stage.Playground.Billboard.ComDelta.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | public static var ComDelta_SMetal:String { """ 19 | //#import "Lily.Stage.Playground.Billboard.h" 20 | \(Lily.Stage.Playground.Billboard.h_SMetal) 21 | 22 | kernel void Lily_Stage_Playground_Billboard_Com_Delta 23 | ( 24 | constant GlobalUniformArray& uniformArray [[ buffer(0) ]], 25 | device Billboard::UnitStatus* statuses [[ buffer(1) ]], 26 | uint gid [[thread_position_in_grid]] 27 | ) 28 | { 29 | auto us = statuses[gid]; 30 | 31 | us.position += us.deltaPosition; 32 | us.scale += us.deltaScale; 33 | us.rotation += us.deltaRotation; 34 | us.angle += us.deltaAngle; 35 | us.color += us.deltaColor; 36 | us.color2 += us.deltaColor2; 37 | us.color3 += us.deltaColor3; 38 | us.color4 += us.deltaColor4; 39 | us.life += us.deltaLife; 40 | 41 | statuses[gid] = us; 42 | } 43 | """ 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCAlgoLine.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// ラインアルゴリズムのステップ情報構造体 14 | public struct LLAlgoLineStep 15 | { 16 | /// 座標 17 | public var pt:LLPoint 18 | /// 移動距離 19 | public var length:LLDouble 20 | /// 移動方向cos 21 | public var cosv:LLDouble 22 | /// 移動方向sin 23 | public var sinv:LLDouble 24 | /// ステップ間の長さ 25 | public var span:LLDouble 26 | /// ターゲット間移動の進捗率(0.0~1.0) 27 | public var progress:LLDouble 28 | 29 | /// 初期化関数 30 | /// - Parameters: 31 | /// - pt: 座標 32 | /// - length: 移動距離 33 | /// - cosv: 移動方向cos 34 | /// - sinv: 移動方向sin 35 | /// - span: ステップ間の長さ 36 | /// - progress: ターゲット間移動の進捗率 37 | public init( _ pt:LLPoint = LLPointZero(), 38 | _ length:LLDouble = 0.0, 39 | _ cosv:LLDouble = 0.0, 40 | _ sinv:LLDouble = 0.0, 41 | _ span:LLDouble = 0.0, 42 | _ progress:LLDouble = 0.0 ) 43 | { 44 | self.pt = pt 45 | self.length = length 46 | self.cosv = cosv 47 | self.sinv = sinv 48 | self.span = span 49 | self.progress = progress 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLLog.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// 有効ログタイプ 14 | /// - LLLogのみログタイプと関係なく、Debugモードならば必ず表示される 15 | public enum LLLogEnableType : Int 16 | { 17 | case none = 0 /// ログ出力無し (警告ログ,強いログともに無効) 18 | case force = 1 /// 強いログの表示 (警告ログは無効) 19 | case warning = 2 /// 警告ログの表示 (強いログは無効) 20 | case all = 3 /// すべてのログの表示 21 | } 22 | 23 | /// 内部変数: 有効なLLLogを示すタイプの状態変数 24 | nonisolated(unsafe) fileprivate var __LLLog_enable_type:LLLogEnableType = .all 25 | 26 | nonisolated(unsafe) public func LLLogEnabled() -> Bool { 27 | return (__LLLog_enable_type.rawValue & LLLogEnableType.all.rawValue) > 0 28 | } 29 | 30 | nonisolated(unsafe) public func LLLogWarningEnabled() -> Bool { 31 | return (__LLLog_enable_type.rawValue & LLLogEnableType.warning.rawValue) > 0 32 | } 33 | 34 | nonisolated(unsafe) public func LLLogForceEnabled() -> Bool { 35 | return (__LLLog_enable_type.rawValue & LLLogEnableType.force.rawValue) > 0 36 | } 37 | 38 | nonisolated(unsafe) public func LLLogSetEnableType( _ type:LLLogEnableType ) { 39 | __LLLog_enable_type = type 40 | } 41 | 42 | nonisolated(unsafe) public func LLLogGetEnableType() -> LLLogEnableType { 43 | return __LLLog_enable_type 44 | } 45 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBCircle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBCircle : BBActor 18 | { 19 | @discardableResult 20 | public override init( storage:BBStorage? = BBStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .circle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class BBAddCircle : BBActor 28 | { 29 | @discardableResult 30 | public override init( storage:BBStorage? = BBStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .circle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class BBSubCircle : BBActor 38 | { 39 | @discardableResult 40 | public override init( storage:BBStorage? = BBStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .circle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGCircle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGCircle : PGActor 18 | { 19 | @discardableResult 20 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .circle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class PGAddCircle : PGActor 28 | { 29 | @discardableResult 30 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .circle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class PGSubCircle : PGActor 38 | { 39 | @discardableResult 40 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .circle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_View/apple/Lily.Field.ViewEvent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | extension Lily.Field 14 | { 15 | public class ViewEvent 16 | : LLField 17 | { 18 | public private(set) var relayFunc:((TObj)->Void)? 19 | 20 | public init( 21 | me:TMe, 22 | action:@escaping (TMe, TObj)->Void 23 | ) 24 | { 25 | self.relayFunc = { [weak me] ( objs:TObj ) in 26 | guard let me:TMe = me else { return } 27 | action( me, objs ) 28 | } 29 | } 30 | 31 | public init( 32 | me:TMe, 33 | caller:TCaller, 34 | action:@escaping (TMe, TCaller, TObj)->Void 35 | ) 36 | { 37 | self.relayFunc = { [weak caller, weak me] ( objs:TObj ) in 38 | guard let caller:TCaller = caller, let me:TMe = me else { return } 39 | action( me, caller, objs ) 40 | } 41 | } 42 | 43 | public func appear(_ objs:TObj? ) { 44 | guard let tobjs = objs else { return } 45 | self.relayFunc?( tobjs ) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBTriangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBTriangle : BBActor 18 | { 19 | @discardableResult 20 | public override init( storage:BBStorage? = BBStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .triangle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class BBAddTriangle : BBActor 28 | { 29 | @discardableResult 30 | public override init( storage:BBStorage? = BBStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .triangle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class BBSubTriangle : BBActor 38 | { 39 | @discardableResult 40 | public override init( storage:BBStorage? = BBStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .triangle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/SMetal/Lily.Stage.MemoryLess.h.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage 17 | { 18 | public static var MemoryLess_h_SMetal:String { """ 19 | #ifndef Lily_Stage_MemoryLess_h 20 | #define Lily_Stage_MemoryLess_h 21 | 22 | #import 23 | #import 24 | //#import "Lily.Stage.Macro.metal" 25 | \(Lily.Stage.Macro_SMetal) 26 | 27 | using namespace metal; 28 | 29 | namespace Lily 30 | { 31 | namespace Stage 32 | { 33 | namespace MemoryLess 34 | { 35 | #if LILY_MEMORY_LESS 36 | float4 float4OfPos( uint2 pos, float4 mem ); 37 | float depthOfPos( uint2 pos, float mem ); 38 | #else 39 | float4 float4OfPos( uint2 pos, texture2d mem ); 40 | float depthOfPos( uint2 pos, depth2d mem ); 41 | #endif 42 | }; 43 | }; 44 | }; 45 | 46 | #endif 47 | """ 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBRecntangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBRectangle : BBActor 18 | { 19 | @discardableResult 20 | public override init( storage:BBStorage? = BBStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .rectangle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class BBAddRectangle : BBActor 28 | { 29 | @discardableResult 30 | public override init( storage:BBStorage? = BBStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .rectangle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class BBSubRectangle : BBActor 38 | { 39 | @discardableResult 40 | public override init( storage:BBStorage? = BBStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .rectangle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Lily.Stage.Playground.PGField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if !os(watchOS) 14 | 15 | import simd 16 | 17 | extension Lily.Stage.Playground 18 | { 19 | public class PGField 20 | : LLField 21 | { 22 | public private(set) var relayFunc:((TObj)->Void)? 23 | 24 | public init( me:TMe, action:@escaping (TMe)->Void ) 25 | where TObj == LLEmpty 26 | { 27 | self.relayFunc = { [weak me] ( objs:TObj ) in 28 | guard let me:TMe = me else { return } 29 | action( me ) 30 | } 31 | } 32 | 33 | public init( me:TMe, action:@escaping (TMe, TObj)->Void ) 34 | { 35 | self.relayFunc = { [weak me] ( objs:TObj ) in 36 | guard let me:TMe = me else { return } 37 | action( me, objs ) 38 | } 39 | } 40 | 41 | public func appear( _ objs:TObj? ) { 42 | if TObj.self == LLEmpty.self { self.relayFunc?( LLEmpty.none as! TObj ); return } 43 | guard let tobjs = objs else { return } 44 | self.relayFunc?( tobjs ) 45 | } 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGTriangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGTriangle : PGActor 18 | { 19 | @discardableResult 20 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .triangle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class PGAddTriangle : PGActor 28 | { 29 | @discardableResult 30 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .triangle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class PGSubTriangle : PGActor 38 | { 39 | @discardableResult 40 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .triangle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/swift_macro_helper/TestLLMath.macro.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLLMath_macro: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_min() { 26 | let v1 = 123 27 | let v2 = 124 28 | XCTAssertEqual( LLMin( v1, v2 ), v1 ) 29 | } 30 | 31 | func test_max() { 32 | let v1 = 123 33 | let v2 = 124 34 | XCTAssertEqual( LLMax( v1, v2 ), v2 ) 35 | } 36 | 37 | func test_within() { 38 | let minv = 100 39 | let maxv = 200 40 | let v1 = 150 41 | let v2 = 80 42 | let v3 = 208 43 | 44 | XCTAssertEqual( LLWithin( min:minv, v1, max:maxv ), v1 ) 45 | XCTAssertEqual( LLWithin( min:minv, v2, max:maxv ), minv ) 46 | XCTAssertEqual( LLWithin( min:minv, v3, max:maxv ), maxv ) 47 | } 48 | 49 | func test_swap() { 50 | var v1 = 150 51 | var v2 = 80 52 | 53 | LLSwap( &v1, &v2 ) 54 | XCTAssertEqual( v1, 80 ) 55 | XCTAssertEqual( v2, 150 ) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGRectangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGRectangle : PGActor 18 | { 19 | @discardableResult 20 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .rectangle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class PGAddRectangle : PGActor 28 | { 29 | @discardableResult 30 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .rectangle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class PGSubRectangle : PGActor 38 | { 39 | @discardableResult 40 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .rectangle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/Renderers/Lily.Stage.Playground.SRGBPass.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import MetalKit 14 | import simd 15 | 16 | extension Lily.Stage.Playground.sRGB 17 | { 18 | open class Pass 19 | { 20 | var device:MTLDevice 21 | 22 | public var passDesc:MTLRenderPassDescriptor? 23 | 24 | public init( device:MTLDevice ) { 25 | self.device = device 26 | 27 | passDesc = .make { 28 | $0.colorAttachments[0].action( load:.load, store:.store ) 29 | } 30 | } 31 | 32 | public func updatePass( 33 | rasterizationRateMap:Lily.Metal.RasterizationRateMap?, 34 | renderTargetViewIndex:Int 35 | ) 36 | { 37 | #if !targetEnvironment(macCatalyst) 38 | passDesc?.rasterizationRateMap = rasterizationRateMap 39 | #endif 40 | #if os(visionOS) 41 | passDesc?.renderTargetArrayLength = renderTargetViewIndex 42 | #endif 43 | } 44 | 45 | public func setDestination( texture:MTLTexture? ) { 46 | passDesc?.colorAttachments[0].texture = texture 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBBlurryCircle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBBlurryCircle : BBActor 18 | { 19 | @discardableResult 20 | public override init( storage:BBStorage? = BBStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .blurryCircle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class BBAddBlurryCircle : BBActor 28 | { 29 | @discardableResult 30 | public override init( storage:BBStorage? = BBStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .blurryCircle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class BBSubBlurryCircle : BBActor 38 | { 39 | @discardableResult 40 | public override init( storage:BBStorage? = BBStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .blurryCircle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/sRGB/SMetal/Lily.Stage.Playground.SRGB.SMetal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.sRGB 17 | { 18 | open class SMetal 19 | { 20 | public let vertexShader:Lily.Metal.Shader 21 | public let fragmentShader:Lily.Metal.Shader 22 | 23 | nonisolated(unsafe) private static var instance:SMetal? 24 | public static func shared( device:MTLDevice ) -> SMetal { 25 | if instance == nil { instance = .init( device:device ) } 26 | return instance! 27 | } 28 | 29 | private init( device:MTLDevice ) { 30 | //LLLog( "文字列からシェーダを生成しています." ) 31 | 32 | self.vertexShader = .init( 33 | device:device, 34 | code: Lily.Stage.Playground.sRGB.Vs_SMetal, 35 | shaderName:"Lily_Stage_Playground_SRGB_Vs" 36 | ) 37 | 38 | self.fragmentShader = .init( 39 | device:device, 40 | code: Lily.Stage.Playground.sRGB.Fs_SMetal, 41 | shaderName:"Lily_Stage_Playground_SRGB_Fs" 42 | ) 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/LilyCore/LLMath.util.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | public func LLRandom() -> LLFloat { 14 | return LLFloat( arc4random() ) / LLFloat( UINT32_MAX ) 15 | } 16 | 17 | public func LLRandomf( _ v_:LLFloat ) -> LLFloat { 18 | return v_ * LLFloat( arc4random() ) / LLFloat( UINT32_MAX ) 19 | } 20 | 21 | public func LLRandomd( _ v_:LLDouble ) -> LLDouble { 22 | return v_ * LLDouble( arc4random() ) / LLDouble( UINT32_MAX ) 23 | } 24 | 25 | public func LLRandomi( _ v_:LLInt32 ) -> LLInt32 { 26 | if v_ < 1 { return 0 } 27 | return Int32((arc4random() >> 1)) % v_ 28 | } 29 | 30 | public func LLRandomu( _ v_:LLUInt32 ) -> LLUInt32 { 31 | return arc4random() % v_ 32 | } 33 | 34 | public func LLAngleZero() -> LLAngle { 35 | return LLAngle( radians:0 ) 36 | } 37 | 38 | public func LLAngleMakeWithDegrees( _ deg_:LLDouble ) -> LLAngle { 39 | return LLAngle( radians:deg_ * LL_PI / 180.0 ) 40 | } 41 | 42 | public func LLAngleMakeWithRadians( _ rad_:LLDouble ) -> LLAngle { 43 | return LLAngle( radians:rad_ ) 44 | } 45 | 46 | public func LLAngleDegrees( _ angle_:LLAngle ) -> LLDouble { 47 | return angle_.value * 180.0 / LL_PI 48 | } 49 | 50 | public func LLAngleRadians( _ angle_:LLAngle ) -> LLDouble { 51 | return angle_.value 52 | } 53 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGBlurryCircle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGBlurryCircle : PGActor 18 | { 19 | @discardableResult 20 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .blurryCircle 23 | status?.compositeType = .alpha 24 | } 25 | } 26 | 27 | public class PGAddBlurryCircle : PGActor 28 | { 29 | @discardableResult 30 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 31 | super.init( storage:storage ) 32 | status?.shapeType = .blurryCircle 33 | status?.compositeType = .add 34 | } 35 | } 36 | 37 | public class PGSubBlurryCircle : PGActor 38 | { 39 | @discardableResult 40 | public override init( storage:PlaneStorage? = PlaneStorage.current ) { 41 | super.init( storage:storage ) 42 | status?.shapeType = .blurryCircle 43 | status?.compositeType = .sub 44 | } 45 | } 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Tests/apple/LilyCore/TestLCZ.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import XCTest 12 | 13 | @testable import LilySwift 14 | 15 | class TestLCZ: XCTestCase { 16 | 17 | override func setUp() { 18 | super.setUp() 19 | } 20 | 21 | override func tearDown() { 22 | super.tearDown() 23 | } 24 | 25 | func test_deflate_and_inflate() { 26 | // 元データ 27 | let str = "こんにちわ、良い天気ですね。今日はあたたかくて気持ちがよいですね。🍆" 28 | let data1 = LCDataMakeWithCChars( str ) 29 | let length1 = LCDataLength( data1 ) 30 | 31 | // zlib圧縮 32 | let data2 = LCZDeflate( LCDataPointer( data1 )!, length1.i!, .default_compression ) 33 | let length2 = LCDataLength( data2 ) 34 | 35 | // サイズが異なることを確認 36 | XCTAssertNotEqual( length1, length2 ) 37 | 38 | // zlib伸長 39 | let data3 = LCZInflate( LCDataPointer( data2 )!, length2.i! ) 40 | let length3 = LCDataLength( data3 ) 41 | 42 | // サイズが圧縮前と一緒であることを確認 43 | XCTAssertEqual( length1, length3 ) 44 | 45 | let lcStr2 = LCStringMakeWithBytes( LCDataPointer( data3 )!, length3.i! ) 46 | let str2 = String( lcStr2 ) 47 | 48 | // 文字列の一致の確認 49 | XCTAssertEqual( str, str2 ) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Utils/Shaders/Lily.Stage.Playground.GlobalUniform.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #ifndef Lily_Stage_Shared_GlobalUniform_h 12 | #define Lily_Stage_Shared_GlobalUniform_h 13 | 14 | #import 15 | #import "Lily.Stage.Playground.CameraUniform.h" 16 | 17 | namespace Lily 18 | { 19 | namespace Stage 20 | { 21 | namespace Playground 22 | { 23 | struct GlobalUniform 24 | { 25 | CameraUniform cameraUniform; 26 | CameraUniform shadowCameraUniforms[3]; 27 | 28 | simd::float2 invScreenSize; 29 | float aspect; 30 | 31 | simd::float3 sunDirection; 32 | float projectionYScale; 33 | float ambientOcclusionContrast; 34 | float ambientOcclusionScale; 35 | float ambientLightScale; 36 | 37 | float frameTime; 38 | }; 39 | 40 | // Vision用のGlobalUniform 41 | struct GlobalUniformArray 42 | { 43 | GlobalUniform uniforms[2]; 44 | }; 45 | }; 46 | }; 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBPool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | open class BBPool 19 | { 20 | nonisolated(unsafe) public static var shared:BBPool = .init() 21 | private init() {} 22 | 23 | private var actorGroup:[BBStorage:Set] = [:] 24 | 25 | public func shapes( on storage:BBStorage? ) -> Set { 26 | guard let storage = storage else { return [] } 27 | return actorGroup[storage] ?? [] 28 | } 29 | 30 | public func insert( shape:BBActor, to storage:BBStorage? ) { 31 | guard let storage = storage else { return } 32 | if actorGroup[storage] == nil { actorGroup[storage] = [] } 33 | actorGroup[storage]?.insert( shape ) 34 | } 35 | public func remove( shape:BBActor, to storage:BBStorage? ) { 36 | guard let storage = storage else { return } 37 | actorGroup[storage]?.remove( shape ) 38 | } 39 | 40 | public func removeAllShapes( on storage:BBStorage? ) { 41 | guard let storage = storage else { return } 42 | actorGroup[storage]?.forEach { $0.trush() } 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Accessors/Lily.Stage.Playground.MDPool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model 17 | { 18 | open class MDPool 19 | { 20 | nonisolated(unsafe) public static var shared:MDPool = .init() 21 | private init() {} 22 | 23 | private var actorGroup:[ModelStorage:Set] = [:] 24 | 25 | public func shapes( on storage:ModelStorage? ) -> Set { 26 | guard let storage = storage else { return [] } 27 | return actorGroup[storage] ?? [] 28 | } 29 | 30 | public func insert( shape:MDActor, to storage:ModelStorage? ) { 31 | guard let storage = storage else { return } 32 | if actorGroup[storage] == nil { actorGroup[storage] = [] } 33 | actorGroup[storage]?.insert( shape ) 34 | } 35 | public func remove( shape:MDActor, to storage:ModelStorage? ) { 36 | guard let storage = storage else { return } 37 | actorGroup[storage]?.remove( shape ) 38 | } 39 | 40 | public func removeAllShapes( on storage:ModelStorage? ) { 41 | guard let storage = storage else { return } 42 | actorGroup[storage]?.forEach { $0.trush() } 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGPool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | open class PGPool 19 | { 20 | nonisolated(unsafe) public static let shared:PGPool = .init() 21 | private init() {} 22 | 23 | private var actorGroup:[PlaneStorage:Set] = [:] 24 | 25 | public func shapes( on storage:PlaneStorage? ) -> Set { 26 | guard let storage = storage else { return [] } 27 | return actorGroup[storage] ?? [] 28 | } 29 | 30 | public func insert( shape:PGActor, to storage:PlaneStorage? ) { 31 | guard let storage = storage else { return } 32 | if actorGroup[storage] == nil { actorGroup[storage] = [] } 33 | actorGroup[storage]?.insert( shape ) 34 | } 35 | public func remove( shape:PGActor, to storage:PlaneStorage? ) { 36 | guard let storage = storage else { return } 37 | actorGroup[storage]?.remove( shape ) 38 | } 39 | 40 | public func removeAllShapes( on storage:PlaneStorage? ) { 41 | guard let storage = storage else { return } 42 | actorGroup[storage]?.forEach { $0.trush() } 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCClock.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// 時間モジュールの初期化 14 | public func LCClockInit() { 15 | } 16 | 17 | /// システムの現在時間をミリ秒の値で取得 18 | /// - Returns: システム現在時間(ミリ秒) 19 | public func LCClockNow() -> LLInt64 { 20 | var now_time:timeval = timeval() 21 | var tzp:timezone = timezone() 22 | gettimeofday( &now_time, &tzp ) 23 | return LLInt64( now_time.tv_sec * 1000 ) + LLInt64( now_time.tv_usec / 1000 ) 24 | } 25 | 26 | /// システムの現在時間を秒の小数値で取得(マイクロ秒まで含む) 27 | /// - Returns: システム現在時間(秒.マイクロ秒) 28 | public func LCClockPrecisionNow() -> Double { 29 | var now_time:timeval = timeval() 30 | var tzp:timezone = timezone() 31 | gettimeofday( &now_time, &tzp ) 32 | return (Double( now_time.tv_sec ) * 1_000_000 + Double( now_time.tv_usec )) / 1_000_000.0 33 | } 34 | 35 | @MainActor fileprivate var is_started:Bool = false 36 | @MainActor fileprivate var time_span:LLInt64 = 0 37 | @MainActor fileprivate var fps:Int = 0 38 | 39 | /// FPSをコンソール出力する 40 | /// - Description: アプリケーションループ内で繰り返し呼びだして用いる. 1秒に何回呼ばれたかを蓄積し、1秒毎に出力する 41 | @MainActor public func LCClockFPS() { 42 | if !is_started { 43 | is_started = true 44 | time_span = LCClockNow() 45 | fps = 0 46 | } 47 | 48 | if LCClockNow() - time_span >= 1000 { 49 | LLLogForce( "FPS:\(fps)" ) 50 | time_span = LCClockNow() 51 | fps = 0 52 | } 53 | 54 | fps += 1 55 | } 56 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Data/Lily.Stage.Playground.Plane.PGFunction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Plane 17 | { 18 | public struct PGFunction 19 | { 20 | public var name:String 21 | public var code:String 22 | public var function:MTLFunction? 23 | 24 | public init( device:MTLDevice, name:String, code:String ) { 25 | self.name = name 26 | self.code = code 27 | 28 | let shader = Lily.Metal.Shader( 29 | device:device, 30 | code:""" 31 | #include 32 | using namespace metal; 33 | \(Lily.Stage.Playground.Plane.h_SMetal) 34 | 35 | [[visible]] 36 | float4 \(name)( 37 | Plane::CustomShaderParam p 38 | ) 39 | { 40 | \(code) 41 | } 42 | """, 43 | shaderName:name 44 | ) 45 | 46 | self.function = shader.function 47 | } 48 | } 49 | } 50 | 51 | extension [Lily.Stage.Playground.Plane.PGFunction] 52 | { 53 | public var metalFunctions:[MTLFunction] { self.filter { $0.function != nil }.map { $0.function! } } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Data/Lily.Stage.Playground.Billboard.BBFunction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Billboard 17 | { 18 | public struct BBFunction 19 | { 20 | public var name:String 21 | public var code:String 22 | public var function:MTLFunction? 23 | 24 | public init( device:MTLDevice, name:String, code:String ) { 25 | self.name = name 26 | self.code = code 27 | 28 | let shader = Lily.Metal.Shader( 29 | device:device, 30 | code:""" 31 | #include 32 | using namespace metal; 33 | \(Lily.Stage.Playground.Billboard.h_SMetal) 34 | 35 | [[visible]] 36 | float4 \(name)( 37 | Billboard::CustomShaderParam p 38 | ) 39 | { 40 | \(code) 41 | } 42 | """, 43 | shaderName:name 44 | ) 45 | 46 | self.function = shader.function 47 | } 48 | } 49 | } 50 | 51 | extension [Lily.Stage.Playground.Billboard.BBFunction] 52 | { 53 | public var metalFunctions:[MTLFunction] { self.filter { $0.function != nil }.map { $0.function! } } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Sources/Lily/mac/extensions/LLColor+Lily+ext.mac.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if os(macOS) 14 | 15 | import AppKit 16 | 17 | public extension LLColor8 18 | { 19 | init( _ nsColor:NSColor ) { 20 | var r:CGFloat = 0.0 21 | var g:CGFloat = 0.0 22 | var b:CGFloat = 0.0 23 | var a:CGFloat = 0.0 24 | nsColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 25 | self.init(R: (r * 255.0).u8!, G: (g * 255.0).u8!, B: (b * 255.0).u8!, A: (a * 255.0).u8! ) 26 | } 27 | 28 | var nsColor:NSColor { NSColor( self ) } 29 | } 30 | 31 | public extension LLColor16 32 | { 33 | init( _ nsColor:NSColor ) { 34 | var r:CGFloat = 0.0 35 | var g:CGFloat = 0.0 36 | var b:CGFloat = 0.0 37 | var a:CGFloat = 0.0 38 | nsColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 39 | self.init(R: (r * 65535.0).u16!, G: (g * 65535.0).u16!, B: (b * 65535.0).u16!, A: (a * 65535.0).u16! ) 40 | } 41 | 42 | var nsColor:NSColor { NSColor( self ) } 43 | } 44 | 45 | public extension LLColor 46 | { 47 | init( _ nsColor:NSColor ) { 48 | var r:CGFloat = 0.0 49 | var g:CGFloat = 0.0 50 | var b:CGFloat = 0.0 51 | var a:CGFloat = 0.0 52 | nsColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 53 | self.init(R: r.f, G: g.f, B: b.f, A: a.f) 54 | } 55 | 56 | var nsColor:NSColor { NSColor( self ) } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Sources/Lily/ios/extensions/LLColor+Lily+ext.ios.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if os(iOS) || os(tvOS) || os(visionOS) 14 | 15 | import UIKit 16 | 17 | public extension LLColor8 18 | { 19 | init( _ uiColor:UIColor ) { 20 | var r:CGFloat = 0.0 21 | var g:CGFloat = 0.0 22 | var b:CGFloat = 0.0 23 | var a:CGFloat = 0.0 24 | uiColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 25 | self.init(R: (r * 255.0).u8!, G: (g * 255.0).u8!, B: (b * 255.0).u8!, A: (a * 255.0).u8! ) 26 | } 27 | 28 | var uiColor:UIColor { UIColor( self ) } 29 | } 30 | 31 | public extension LLColor16 32 | { 33 | init( _ uiColor:UIColor ) { 34 | var r:CGFloat = 0.0 35 | var g:CGFloat = 0.0 36 | var b:CGFloat = 0.0 37 | var a:CGFloat = 0.0 38 | uiColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 39 | self.init(R: (r * 65535.0).u16!, G: (g * 65535.0).u16!, B: (b * 65535.0).u16!, A: (a * 65535.0).u16! ) 40 | } 41 | 42 | var uiColor:UIColor { UIColor( self ) } 43 | } 44 | 45 | public extension LLColor 46 | { 47 | init( _ uiColor:UIColor ) { 48 | var r:CGFloat = 0.0 49 | var g:CGFloat = 0.0 50 | var b:CGFloat = 0.0 51 | var a:CGFloat = 0.0 52 | uiColor.getRed( &r, green: &g, blue: &b, alpha: &a ) 53 | self.init(R: r.f, G: g.f, B: b.f, A: a.f) 54 | } 55 | 56 | var uiColor:UIColor { UIColor( self ) } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCAlignedMemory.16.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | // ラッパークラス実装 14 | public class LCAlignedMemory16SmPtr { 15 | fileprivate var alignedMemory:LCAlignedMemoryInternal 16 | 17 | fileprivate init() { 18 | alignedMemory = LCAlignedMemoryInternal(alignment: 16 ) 19 | } 20 | } 21 | 22 | public func LCAlignedMemory16Make() -> LCAlignedMemory16SmPtr { 23 | return LCAlignedMemory16SmPtr() 24 | }; 25 | 26 | public func LCAlignedMemory16Pointer( _ mem_:LCAlignedMemory16SmPtr ) -> LLBytePtr? { 27 | return mem_.alignedMemory.pointer 28 | } 29 | 30 | public func LCAlignedMemory16Length( _ mem_:LCAlignedMemory16SmPtr ) -> Int { 31 | return mem_.alignedMemory.length 32 | } 33 | 34 | public func LCAlignedMemory16AllocatedLength( _ mem_:LCAlignedMemory16SmPtr ) -> Int { 35 | return mem_.alignedMemory.allocatedLength 36 | } 37 | 38 | public func LCAlignedMemory16Resize( _ mem_:LCAlignedMemory16SmPtr, _ length_:Int ) { 39 | mem_.alignedMemory.resize( length_ ) 40 | } 41 | 42 | public func LCAlignedMemory16Append( _ mem_:LCAlignedMemory16SmPtr, _ src_:LCAlignedMemory16SmPtr ) { 43 | mem_.alignedMemory.append( src_.alignedMemory ) 44 | } 45 | 46 | public func LCAlignedMemory16AppendBytes( _ mem_:LCAlignedMemory16SmPtr, _ bin_:LLNonNullUInt8Ptr, _ length_:Int ) { 47 | mem_.alignedMemory.append( bin_, length_ ) 48 | } 49 | 50 | public func LCAlignedMemory16Clear( _ mem_:LCAlignedMemory16SmPtr ) { 51 | mem_.alignedMemory.clear() 52 | } 53 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBMask.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBMask : BBActor 18 | { 19 | @discardableResult 20 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .mask 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class BBAddMask : BBActor 29 | { 30 | @discardableResult 31 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 32 | super.init( storage:storage ) 33 | status?.shapeType = .mask 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class BBSubMask : BBActor 40 | { 41 | @discardableResult 42 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 43 | super.init( storage:storage ) 44 | status?.shapeType = .mask 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGMask.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGMask : PGActor 18 | { 19 | @discardableResult 20 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .mask 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class PGAddMask : PGActor 29 | { 30 | @discardableResult 31 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 32 | super.init( storage:storage ) 33 | status?.shapeType = .mask 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class PGSubMask : PGActor 40 | { 41 | @discardableResult 42 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 43 | super.init( storage:storage ) 44 | status?.shapeType = .mask 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Views/Lily.Stage.Playground.PGTouch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if !os(watchOS) 14 | 15 | import Foundation 16 | 17 | extension Lily.Stage.Playground 18 | { 19 | public struct PGTouch 20 | { 21 | public enum State : Int 22 | { 23 | case began 24 | case touch 25 | case release 26 | case none 27 | } 28 | 29 | public var startPos:LLPointFloat = .zero 30 | 31 | public var xy:LLPointFloat = .zero 32 | public var uv:LLPointFloat = .zero 33 | public var state:State = .none 34 | 35 | public var x:LLFloat { xy.x } 36 | public var y:LLFloat { xy.y } 37 | 38 | public var u:LLFloat { uv.x } 39 | public var v:LLFloat { uv.y } 40 | 41 | public init( 42 | xy:LLPointFloat = .zero, 43 | uv:LLPointFloat = .zero, 44 | state:State = .none 45 | ) 46 | { 47 | self.xy = xy 48 | self.uv = uv 49 | self.state = state 50 | } 51 | 52 | public var isBegan:Bool { self.state == .began } 53 | public var isReleased:Bool { self.state == .release } 54 | } 55 | 56 | #if os(macOS) 57 | public enum MacOSMousePhase 58 | { 59 | case began 60 | case moved 61 | case stationary 62 | case ended 63 | case cancelled 64 | } 65 | #endif 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Sources/LilyCore/LCAlignedMemory.4096.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Lily Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | // ラッパークラス実装 14 | public class LCAlignedMemory4096SmPtr { 15 | fileprivate var alignedMemory:LCAlignedMemoryInternal 16 | 17 | fileprivate init() { 18 | alignedMemory = LCAlignedMemoryInternal(alignment: 4096 ) 19 | } 20 | } 21 | 22 | public func LCAlignedMemory4096Make() -> LCAlignedMemory4096SmPtr { 23 | return LCAlignedMemory4096SmPtr() 24 | }; 25 | 26 | public func LCAlignedMemory4096Pointer( _ mem_:LCAlignedMemory4096SmPtr ) -> LLBytePtr? { 27 | return mem_.alignedMemory.pointer 28 | } 29 | 30 | public func LCAlignedMemory4096Length( _ mem_:LCAlignedMemory4096SmPtr ) -> Int { 31 | return mem_.alignedMemory.length 32 | } 33 | 34 | public func LCAlignedMemory4096AllocatedLength( _ mem_:LCAlignedMemory4096SmPtr ) -> Int { 35 | return mem_.alignedMemory.allocatedLength 36 | } 37 | 38 | public func LCAlignedMemory4096Resize( _ mem_:LCAlignedMemory4096SmPtr, _ length_:Int ) { 39 | mem_.alignedMemory.resize( length_ ) 40 | } 41 | 42 | public func LCAlignedMemory4096Append( _ mem_:LCAlignedMemory4096SmPtr, _ src_:LCAlignedMemory4096SmPtr ) { 43 | mem_.alignedMemory.append( src_.alignedMemory ) 44 | } 45 | 46 | public func LCAlignedMemory4096AppendBytes( _ mem_:LCAlignedMemory4096SmPtr, _ bin_:LLNonNullUInt8Ptr, _ length_:Int ) { 47 | mem_.alignedMemory.append( bin_, length_ ) 48 | } 49 | 50 | public func LCAlignedMemory4096Clear( _ mem_:LCAlignedMemory4096SmPtr ) { 51 | mem_.alignedMemory.clear() 52 | } 53 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBPicture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBPicture : BBActor 18 | { 19 | @discardableResult 20 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .picture 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class BBAddPicture : BBActor 29 | { 30 | @discardableResult 31 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 32 | super.init( storage:storage ) 33 | status?.shapeType = .picture 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class BBSubPicture : BBActor 40 | { 41 | @discardableResult 42 | public init( storage:BBStorage? = BBStorage.current, _ assetName:String ) { 43 | super.init( storage:storage ) 44 | status?.shapeType = .picture 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGPicture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGPicture : PGActor 18 | { 19 | @discardableResult 20 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 21 | super.init( storage:storage ) 22 | status?.shapeType = .picture 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class PGAddPicture : PGActor 29 | { 30 | @discardableResult 31 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 32 | super.init( storage:storage ) 33 | status?.shapeType = .picture 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class PGSubPicture : PGActor 40 | { 41 | @discardableResult 42 | public init( storage:PlaneStorage? = PlaneStorage.current, _ assetName:String ) { 43 | super.init( storage:storage ) 44 | status?.shapeType = .picture 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/LLSizeFloat+LilyCore+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import CoreGraphics 12 | 13 | /// サイズ構造体拡張 14 | public extension LLSizeFloat 15 | { 16 | /// サイズゼロのサイズ構造体を返す 17 | static let zero:LLSizeFloat = { return LLSizeFloat( 0, 0 ) }() 18 | 19 | /// CGFloatを用いた実体化 20 | /// - Parameters: 21 | /// - w: 横幅 22 | /// - h: 高さ 23 | init( _ w:CGFloat, _ h:CGFloat ) { 24 | self.init( width:w.f, height:h.f ) 25 | } 26 | 27 | /// Doubleを用いた実体化 28 | /// - Parameters: 29 | /// - w: 横幅 30 | /// - h: 高さ 31 | init( _ w:Double, _ h:Double ) { 32 | self.init( width:w.f, height:h.f ) 33 | } 34 | 35 | /// Floatを用いた実体化 36 | /// - Parameters: 37 | /// - w: 横幅 38 | /// - h: 高さ 39 | init( _ w:Float, _ h:Float ) { 40 | self.init( width:w, height:h ) 41 | } 42 | 43 | /// Intを用いた実体化 44 | /// - Parameters: 45 | /// - w: 横幅 46 | /// - h: 高さ 47 | init( _ w:Int, _ h:Int ) { 48 | self.init( width:w.f, height:h.f ) 49 | } 50 | 51 | /// CGSizeからの実体化 52 | /// - Parameters: 53 | /// - cgSize: 大きさ 54 | init( _ cgSize:CGSize ) { 55 | self.init( width:cgSize.width.f, height:cgSize.height.f ) 56 | } 57 | 58 | /// CGSizeへの変換 59 | var cgSize:CGSize { 60 | return CGSize( self ) 61 | } 62 | 63 | /// 0~指定した値のランダムサイズ値 64 | var randomize:LLSizeFloat { 65 | return LLSizeFloat( LLRandomf( self.width ), LLRandomf( self.height ) ) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Utils/SMetal/Lily.Stage.Playground.CameraUniform.h.SMetal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground 17 | { 18 | public static var CameraUniform_h_SMetal:String { """ 19 | #ifndef Lily_Stage_Shared_CameraUniform_h 20 | #define Lily_Stage_Shared_CameraUniform_h 21 | 22 | #import 23 | 24 | namespace Lily 25 | { 26 | namespace Stage 27 | { 28 | namespace Playground 29 | { 30 | struct CameraUniform 31 | { 32 | simd::float4x4 viewMatrix; 33 | simd::float4x4 projectionMatrix; 34 | simd::float4x4 viewProjectionMatrix; 35 | simd::float4x4 invOrientationProjectionMatrix; 36 | simd::float4x4 invViewProjectionMatrix; 37 | simd::float4x4 invProjectionMatrix; 38 | simd::float4x4 invViewMatrix; 39 | simd::float4 frustumPlanes[6]; 40 | simd::float3 position; 41 | simd::float3 up; 42 | simd::float3 right; 43 | simd::float3 direction; 44 | }; 45 | 46 | } 47 | }; 48 | }; 49 | 50 | #endif 51 | """ 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Sources/Lily/apple/LLFileWriter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// ファイル書き込みモジュール 14 | open class LLFileWriter 15 | { 16 | /// LilyCoreオブジェクト 17 | fileprivate var fw:LCFileWriterSmPtr 18 | 19 | /// pathを指定してファイル書き込みオブジェクトを作成する 20 | /// - Parameters: 21 | /// - path: 書き込むファイルパス 22 | /// - mode: 追記モード = true, 新規書き込みモード = false 23 | public init( path:String, added mode:Bool = false ) { 24 | fw = LCFileWriterMake( path.lcStr, mode ) 25 | } 26 | 27 | /// ファイル読み込みオブジェクトがアクティブかどうかを取得する 28 | public var isActive:Bool { return LCFileWriterIsActive( fw ) } 29 | 30 | /// binのポインタの内容をファイルに書き込む 31 | /// - Parameters: 32 | /// - bin: 書き込み元ポインタ 33 | /// - length: 書き込み長さ(バイト) 34 | /// - Returns: 書き込み成功 = true, 失敗 = false 35 | @discardableResult 36 | open func write( _ bin:LLNonNullUInt8Ptr, length:LLInt64 ) -> Bool { 37 | return LCFileWriterWrite( fw, bin, length ) 38 | } 39 | 40 | /// LilyCore文字列をファイルに書き込む 41 | /// - Parameters: 42 | /// - lcStr: 書き込むLilyCore文字列 43 | /// - Returns: 書き込み成功 = true, 失敗 = false 44 | @discardableResult 45 | open func write( _ lcStr:LCStringSmPtr ) -> Bool { 46 | return LCFileWriterWriteText( fw, lcStr ) 47 | } 48 | 49 | /// Swift文字列をファイルに書き込む 50 | /// - Parameters: 51 | /// - str: 書き込む文字列 52 | /// - Returns: 書き込み成功 = true, 失敗 = false 53 | @discardableResult 54 | open func write( _ str:String ) -> Bool { 55 | return write( str.lcStr ) 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Mesh.ShadowVs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.Mesh.h" 12 | 13 | vertex Model::Mesh::VOut Lily_Stage_Playground_Model_Mesh_Shadow_Vs 14 | ( 15 | const device Obj::Vertex* in [[ buffer(0) ]], 16 | const device Model::Mesh::UnitStatus* statuses [[ buffer(1) ]], 17 | const device uint& cascadeIndex [[ buffer(2) ]], 18 | constant int& modelIndex [[ buffer(3) ]], 19 | constant float4x4& shadowCameraVPMatrix[[ buffer(6) ]], 20 | ushort amp_id [[ amplification_id ]], 21 | uint vid [[ vertex_id ]], 22 | uint iid [[ instance_id ]] 23 | ) 24 | { 25 | int idx = iid; 26 | 27 | auto us = statuses[idx]; 28 | 29 | // 一致しないインスタンスは破棄 30 | if( us.modelIndex != modelIndex ) { 31 | Model::Mesh::VOut trush_vout; 32 | trush_vout.position = float4( 0, 0, Model::TOO_FAR, 0 ); 33 | return trush_vout; 34 | } 35 | 36 | float4 position = float4( in[vid].position, 1.0 ); 37 | 38 | // アフィン変換の作成 39 | float3 pos = us.position; 40 | float3 ro = us.rotation; 41 | float3 sc = us.scale; 42 | 43 | float4x4 TRS = affineTransform( pos, sc, ro ); 44 | float4 world_pos = TRS * position; 45 | 46 | // 表示/非表示の判定( state, enabled, alphaのどれかが非表示を満たしているかを計算. 負の値 = 非表示 ) 47 | float visibility_z = us.state * us.enabled * us.color[3] > 0.00001 ? 0.0 : Model::TOO_FAR; 48 | 49 | Model::Mesh::VOut out; 50 | out.position = shadowCameraVPMatrix * world_pos; 51 | out.position.z += visibility_z; 52 | return out; 53 | } 54 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/SMetal/Lily.Stage.Playground.Model.Lighting.h.SM.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | import simd 15 | 16 | extension Lily.Stage.Playground.Model.Lighting 17 | { 18 | public static var h_SMetal:String { """ 19 | #import 20 | #import 21 | //#import "../../../Standard/Shaders/Lily.Stage.MemoryLess.h" 22 | \(Lily.Stage.MemoryLess_SMetal) 23 | //#import "../../Utils/Shaders/Lily.Stage.Playground.GlobalUniform.h" 24 | \(Lily.Stage.Playground.GlobalUniform_h_SMetal) 25 | #import "Lily.Stage.Playground.Model.util.h" 26 | \(Lily.Stage.Playground.Model.util_h_SMetal) 27 | 28 | using namespace metal; 29 | using namespace Lily::Stage; 30 | using namespace Lily::Stage::Playground; 31 | 32 | namespace Lily 33 | { 34 | namespace Stage 35 | { 36 | namespace Playground 37 | { 38 | namespace Model 39 | { 40 | namespace Lighting 41 | { 42 | struct VOut 43 | { 44 | float4 position [[position]]; 45 | uint ampID; 46 | }; 47 | 48 | struct FOut 49 | { 50 | float4 backBuffer [[ color(IDX_OUTPUT) ]]; 51 | }; 52 | } 53 | } 54 | } 55 | } 56 | } 57 | """ 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Sources/Lily/mac/extensions/NSColor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if os(macOS) 14 | 15 | import AppKit 16 | 17 | public extension NSColor 18 | { 19 | convenience init( _ r:CGFloat, _ g:CGFloat, _ b:CGFloat, _ a:CGFloat ) { 20 | self.init( red:r, green:g, blue:b, alpha:a ) 21 | } 22 | 23 | convenience init( _ llColor8:LLColor8 ) { 24 | self.init( red: llColor8.R.cgf / LLColor8_MaxValue.cgf, 25 | green: llColor8.G.cgf / LLColor8_MaxValue.cgf, 26 | blue: llColor8.B.cgf / LLColor8_MaxValue.cgf, 27 | alpha: llColor8.A.cgf / LLColor8_MaxValue.cgf ) 28 | } 29 | 30 | convenience init( _ llColor16:LLColor16 ) { 31 | self.init( red: llColor16.R.cgf / LLColor16_MaxValue.cgf, 32 | green: llColor16.G.cgf / LLColor16_MaxValue.cgf, 33 | blue: llColor16.B.cgf / LLColor16_MaxValue.cgf, 34 | alpha: llColor16.A.cgf / LLColor16_MaxValue.cgf ) 35 | } 36 | 37 | convenience init( _ llColor:LLColor ) { 38 | self.init( red: llColor.R.cgf / LLColor_MaxValue.cgf, 39 | green: llColor.G.cgf / LLColor_MaxValue.cgf, 40 | blue: llColor.B.cgf / LLColor_MaxValue.cgf, 41 | alpha: llColor.A.cgf / LLColor_MaxValue.cgf ) 42 | } 43 | 44 | convenience init( _ hex:String ) { 45 | self.init( LLHexColor8( hex.lcStr ) ) 46 | } 47 | 48 | var llColor8:LLColor8 { LLColor8( self ) } 49 | 50 | var llColor16:LLColor16 { LLColor16( self ) } 51 | 52 | var llColor:LLColor { LLColor( self ) } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Sources/Lily/ios/extensions/UIColor+Lily+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | #if os(iOS) || os(tvOS) || os(visionOS) 14 | 15 | import UIKit 16 | 17 | public extension UIColor 18 | { 19 | convenience init( _ r:CGFloat, _ g:CGFloat, _ b:CGFloat, _ a:CGFloat ) { 20 | self.init( red:r, green:g, blue:b, alpha:a ) 21 | } 22 | 23 | convenience init( _ llColor8:LLColor8 ) { 24 | self.init( red: llColor8.R.cgf / LLColor8_MaxValue.cgf, 25 | green: llColor8.G.cgf / LLColor8_MaxValue.cgf, 26 | blue: llColor8.B.cgf / LLColor8_MaxValue.cgf, 27 | alpha: llColor8.A.cgf / LLColor8_MaxValue.cgf ) 28 | } 29 | 30 | convenience init( _ llColor16:LLColor16 ) { 31 | self.init( red: llColor16.R.cgf / LLColor16_MaxValue.cgf, 32 | green: llColor16.G.cgf / LLColor16_MaxValue.cgf, 33 | blue: llColor16.B.cgf / LLColor16_MaxValue.cgf, 34 | alpha: llColor16.A.cgf / LLColor16_MaxValue.cgf ) 35 | } 36 | 37 | convenience init( _ llColor:LLColor ) { 38 | self.init( red: llColor.R.cgf / LLColor_MaxValue.cgf, 39 | green: llColor.G.cgf / LLColor_MaxValue.cgf, 40 | blue: llColor.B.cgf / LLColor_MaxValue.cgf, 41 | alpha: llColor.A.cgf / LLColor_MaxValue.cgf ) 42 | } 43 | 44 | convenience init( _ hex:String ) { 45 | self.init( LLHexColor8( hex.lcStr ) ) 46 | } 47 | 48 | var llColor8:LLColor8 { LLColor8( self ) } 49 | 50 | var llColor16:LLColor16 { LLColor16( self ) } 51 | 52 | var llColor:LLColor { LLColor( self ) } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBShaderTriangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBShaderTriangle : BBShaderActor 18 | { 19 | @discardableResult 20 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 21 | super.init( storage:storage, shaderName:shaderName ) 22 | status?.shapeType = .shaderTriangle 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class BBAddShaderTriangle : BBShaderActor 29 | { 30 | @discardableResult 31 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 32 | super.init( storage:storage, shaderName:shaderName ) 33 | status?.shapeType = .shaderTriangle 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class BBSubShaderTriangle : BBShaderActor 40 | { 41 | @discardableResult 42 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 43 | super.init( storage:storage, shaderName:shaderName ) 44 | status?.shapeType = .shaderTriangle 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Billboard/Accessors/Lily.Stage.Playground.BBShaderRectangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Billboard 16 | { 17 | public class BBShaderRectangle : BBShaderActor 18 | { 19 | @discardableResult 20 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 21 | super.init( storage:storage, shaderName:shaderName ) 22 | status?.shapeType = .shaderRectangle 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class BBAddShaderRectangle : BBShaderActor 29 | { 30 | @discardableResult 31 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 32 | super.init( storage:storage, shaderName:shaderName ) 33 | status?.shapeType = .shaderRectangle 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class BBSubShaderRectangle : BBShaderActor 40 | { 41 | @discardableResult 42 | public init( storage:BBStorage? = .current, assetName:String = "", shaderName:String ) { 43 | super.init( storage:storage, shaderName:shaderName ) 44 | status?.shapeType = .shaderRectangle 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/LilyCore/macro/LLLog.macro.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import Foundation 12 | 13 | /// ログの出力(Debugモードのみ表示される) 14 | /// - Parameters: 15 | /// - body: 出力文字列 16 | /// - file: ログ出力したソースファイル名(default = ファイル名) 17 | /// - function: ログ出力した関数名(default = 実行中関数名) 18 | /// - line: ログ出力した行数(default = 行数) 19 | #if DEBUG 20 | public func LLLog( _ body:Any?, file:String = #file, function:String = #function, line:Int = #line ) { 21 | if LLLogEnabled() && body != nil { 22 | let fn = file.fileUrl.lastPathComponent 23 | print( "[\( fn ):\(line) \(function)] \(body!)" ) 24 | } 25 | } 26 | #else 27 | public func LLLog( _ body:Any?, file:String = #file, function:String = #function, line:Int = #line ) {} 28 | #endif 29 | 30 | /// 警告ログの出力 31 | /// - Parameters: 32 | /// - body: 出力文字列 33 | /// - file: ログ出力したソースファイル名(default = ファイル名) 34 | /// - function: ログ出力した関数名(default = 実行中関数名) 35 | /// - line: ログ出力した行数(default = 行数) 36 | public func LLLogWarning( _ body:Any?, file:String = #file, function:String = #function, line:Int = #line ) { 37 | if LLLogWarningEnabled() && body != nil { 38 | let fn = file.fileUrl.lastPathComponent 39 | print( "[\( fn ):\(line) \(function)] \(body!)" ) 40 | } 41 | } 42 | 43 | /// 強いログの出力 44 | /// - Parameters: 45 | /// - body: 出力文字列 46 | /// - file: ログ出力したソースファイル名(default = ファイル名) 47 | /// - function: ログ出力した関数名(default = 実行中関数名) 48 | /// - line: ログ出力した行数(default = 行数) 49 | public func LLLogForce( _ body:Any?, file:String = #file, function:String = #function, line:Int = #line ) { 50 | if LLLogForceEnabled() && body != nil { 51 | let fn = file.fileUrl.lastPathComponent 52 | print( "[\( fn ):\(line) \(function)] \(body!)" ) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Sources/LilyCore/extensions/CGSize+LilyCore+ext.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | import CoreGraphics 12 | 13 | /// CGSize構造体拡張 14 | public extension CGSize 15 | { 16 | /// CGFloatを用いた実体化 17 | /// - Parameters: 18 | /// - w: 横幅 19 | /// - h: 高さ 20 | init( _ w:CGFloat, _ h:CGFloat ) { 21 | self.init( width:w, height:h ) 22 | } 23 | 24 | /// Doubleを用いた実体化 25 | /// - Parameters: 26 | /// - w: 横幅 27 | /// - h: 高さ 28 | init( _ w:Double, _ h:Double ) { 29 | self.init( width:w.cgf, height:h.cgf ) 30 | } 31 | 32 | /// Floatを用いた実体化 33 | /// - Parameters: 34 | /// - w: 横幅 35 | /// - h: 高さ 36 | init( _ w:Float, _ h:Float ) { 37 | self.init( width:w.cgf, height:h.cgf ) 38 | } 39 | 40 | /// Intを用いた実体化 41 | /// - Parameters: 42 | /// - w: 横幅 43 | /// - h: 高さ 44 | init( _ w:Int, _ h:Int ) { 45 | self.init( width:w, height:h ) 46 | } 47 | 48 | /// LLSizeを用いた実体化 49 | /// - Parameter llsize: 大きさ 50 | init( _ llsize:LLSize ) { 51 | self.init( width:llsize.width.cgf, height:llsize.height.cgf ) 52 | } 53 | 54 | /// LLSizeIntを用いた実体化 55 | /// - Parameter llsize: 大きさ 56 | init( _ llsizei:LLSizeInt ) { 57 | self.init( width:llsizei.width.cgf, height:llsizei.height.cgf ) 58 | } 59 | 60 | /// LLSizeFloatを用いた実体化 61 | /// - Parameter llsize: 大きさ 62 | init( _ llsizef:LLSizeFloat ) { 63 | self.init( width:llsizef.width.cgf, height:llsizef.height.cgf ) 64 | } 65 | 66 | /// LLSizeへの変換 67 | var llSize:LLSize { return LLSize( self ) } 68 | 69 | /// LLSizeへの変換 70 | var llSizeFloat:LLSizeFloat { return LLSizeFloat( self ) } 71 | } 72 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Standard/Shaders/Lily.Stage.MathMatrix.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import 12 | #import 13 | 14 | using namespace metal; 15 | 16 | inline float4x4 rotateZ( float rad ) { 17 | return { 18 | float4( cos( rad ), -sin( rad ), 0, 0 ), 19 | float4( sin( rad ), cos( rad ), 0, 0 ), 20 | float4( 0, 0, 1, 0 ), 21 | float4( 0, 0, 0, 1 ) 22 | }; 23 | } 24 | 25 | inline float4x4 rotateY( float rad ) { 26 | return { 27 | float4( cos( rad ), 0, sin( rad ), 0 ), 28 | float4( 0, 1, 0, 0 ), 29 | float4( -sin( rad ), 0, cos( rad ), 0 ), 30 | float4( 0, 0, 0, 1 ) 31 | }; 32 | } 33 | 34 | inline float4x4 rotateX( float rad ) { 35 | return { 36 | float4( 1, 0, 0, 0 ), 37 | float4( 0, cos( rad ), -sin( rad ), 0 ), 38 | float4( 0, sin( rad ), cos( rad ), 0 ), 39 | float4( 0, 0, 0, 1 ) 40 | }; 41 | } 42 | 43 | inline float4x4 rotate( float3 rad3 ) { 44 | auto Rz = rotateZ( rad3.z ); 45 | auto Ry = rotateY( rad3.y ); 46 | auto Rx = rotateX( rad3.x ); 47 | return Rz * Ry * Rx; 48 | } 49 | 50 | inline float4x4 scale( float3 sc ) { 51 | return { 52 | float4( sc.x, 0, 0, 0 ), 53 | float4( 0, sc.y, 0, 0 ), 54 | float4( 0, 0, sc.z, 0 ), 55 | float4( 0, 0, 0, 1 ) 56 | }; 57 | } 58 | 59 | inline float4x4 translate( float3 pos ) { 60 | return { 61 | float4( 1, 0, 0, 0 ), 62 | float4( 0, 1, 0, 0 ), 63 | float4( 0, 0, 1, 0 ), 64 | float4( pos, 1 ) 65 | }; 66 | } 67 | 68 | inline float4x4 affineTransform( float3 trans, float3 sc, float3 ro ) { 69 | return translate( trans ) * rotate( ro ) * scale( sc ); 70 | } 71 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGShaderTriangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGShaderTriangle : PGShaderActor 18 | { 19 | @discardableResult 20 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 21 | super.init( storage:storage, shaderName:shaderName ) 22 | status?.shapeType = .shaderTriangle 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class PGAddShaderTriangle : PGShaderActor 29 | { 30 | @discardableResult 31 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 32 | super.init( storage:storage, shaderName:shaderName ) 33 | status?.shapeType = .shaderTriangle 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class PGSubShaderTriangle : PGShaderActor 40 | { 41 | @discardableResult 42 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 43 | super.init( storage:storage, shaderName:shaderName ) 44 | status?.shapeType = .shaderTriangle 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Plane/Accessors/Lily.Stage.Playground.PGShaderRectangle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | import Metal 14 | 15 | extension Lily.Stage.Playground.Plane 16 | { 17 | public class PGShaderRectangle : PGShaderActor 18 | { 19 | @discardableResult 20 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 21 | super.init( storage:storage, shaderName:shaderName ) 22 | status?.shapeType = .shaderRectangle 23 | status?.compositeType = .alpha 24 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 25 | } 26 | } 27 | 28 | public class PGAddShaderRectangle : PGShaderActor 29 | { 30 | @discardableResult 31 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 32 | super.init( storage:storage, shaderName:shaderName ) 33 | status?.shapeType = .shaderRectangle 34 | status?.compositeType = .add 35 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 36 | } 37 | } 38 | 39 | public class PGSubShaderRectangle : PGShaderActor 40 | { 41 | @discardableResult 42 | public init( storage:PlaneStorage? = PlaneStorage.current, assetName:String = "", shaderName:String ) { 43 | super.init( storage:storage, shaderName:shaderName ) 44 | status?.shapeType = .shaderRectangle 45 | status?.compositeType = .sub 46 | status?.atlasUV = storage?.textureAtlas.parts( assetName ).atlasUV ?? .zero 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Sources/Lily/apple/LLTextAttribute.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | /// コメント未済 12 | 13 | import Foundation 14 | 15 | /// テキスト属性モジュール 16 | public class LLTextAttribute 17 | { 18 | /// LilyCoreオブジェクト 19 | private(set) var lcAttr:LCTextAttributeSmPtr 20 | 21 | /// テキスト属性オブジェクトを作成 22 | /// - Parameters: 23 | /// - face: フォント名 24 | /// - size: フォントサイズ 25 | /// - color: 文字の色 26 | /// - weight: フォント太さ 27 | /// - Returns: テキスト属性オブジェクト 28 | public init( face:LLString, size:Int, color:LLColor, weight:LLFontWeight ) { 29 | lcAttr = LCTextAttributeMake( face.lcStr, size.i32!, color, weight ) 30 | } 31 | 32 | /// テキスト属性オブジェクトを作成 33 | /// - Parameters: 34 | /// - lcAttr: LilyCoreテキスト属性オブジェクト 35 | /// - Returns: テキスト属性オブジェクト 36 | public convenience init( lcAttr attr:LCTextAttributeSmPtr ) { 37 | self.init( face:LLString( LCTextAttributeFace( attr ) ), 38 | size:LCTextAttributeSize( attr ).i, 39 | color:LCTextAttributeColor( attr ), 40 | weight:LCTextAttributeWeight( attr ) ) 41 | } 42 | 43 | /// テキスト属性のデフォルトオブジェクトを返す 44 | /// - Returns: 標準のテキスト属性オブジェクト 45 | public static var `default`:LLTextAttribute { return LLTextAttribute( lcAttr: LCTextAttributeMakeDefault() ) } 46 | 47 | public var face:LLString { 48 | return LLString( LCTextAttributeFace( lcAttr ) ) 49 | } 50 | 51 | public var size:Int { 52 | return LCTextAttributeSize( lcAttr ).i 53 | } 54 | 55 | public var color:LLColor { 56 | return LCTextAttributeColor( lcAttr ) 57 | } 58 | 59 | public var weight:LLFontWeight { 60 | return LCTextAttributeWeight( lcAttr ) 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Mesh.Vs.metal: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.Mesh.h" 12 | 13 | vertex Model::Mesh::VOut Lily_Stage_Playground_Model_Mesh_Vs 14 | ( 15 | const device Obj::Vertex* in [[ buffer(0) ]], 16 | const device Model::Mesh::UnitStatus* statuses [[ buffer(1) ]], 17 | constant GlobalUniformArray & uniformArray [[ buffer(2) ]], 18 | constant int& modelIndex [[ buffer(3) ]], 19 | ushort amp_id [[ amplification_id ]], 20 | uint vid [[ vertex_id ]], 21 | uint iid [[ instance_id ]] 22 | ) 23 | { 24 | auto uniform = uniformArray.uniforms[amp_id]; 25 | 26 | int idx = iid; 27 | 28 | auto us = statuses[idx]; 29 | 30 | // 一致しないインスタンスは破棄 31 | if( us.modelIndex != modelIndex ) { 32 | Model::Mesh::VOut trush_vout; 33 | trush_vout.position = float4( 0, 0, Model::TOO_FAR, 0 ); 34 | return trush_vout; 35 | } 36 | 37 | float4 base_pos = float4( in[vid].position, 1.0 ); 38 | 39 | // アフィン変換の作成 40 | float3 pos = us.position; 41 | float3 ro = us.rotation; 42 | float3 sc = us.scale; 43 | 44 | float4x4 TRS = affineTransform( pos, sc, ro ); 45 | 46 | float4 world_pos = TRS * base_pos; 47 | 48 | // 表示/非表示の判定( state, enabled, alphaのどれかが非表示を満たしているかを計算. 負の値 = 非表示 ) 49 | float visibility_z = us.state * us.enabled * us.color[3] > 0.00001 ? 0.0 : Model::TOO_FAR; 50 | 51 | Model::Mesh::VOut out; 52 | out.position = uniform.cameraUniform.viewProjectionMatrix * world_pos; 53 | out.position.z += visibility_z; 54 | out.color = pow( in[vid].color, 1.0 / 2.2 ); // sRGB -> linear変換 55 | out.normal = (TRS * float4(in[vid].normal, 0)).xyz; 56 | return out; 57 | } 58 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Audio/Accessors/Lily.Stage.Playground.PGAudioPool.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #if !os(watchOS) 12 | 13 | #if os(macOS) 14 | import AppKit 15 | #else 16 | import UIKit 17 | #endif 18 | import AVFoundation 19 | 20 | extension Lily.Stage.Playground 21 | { 22 | public class PGAudioPool 23 | { 24 | nonisolated(unsafe) public static let shared:PGAudioPool = .init() 25 | private init() {} 26 | 27 | private var soundGroup:[PGAudioStorage:Set] = [:] 28 | 29 | public func sounds( on storage:PGAudioStorage? ) -> Set { 30 | guard let storage = storage else { return [] } 31 | return soundGroup[storage] ?? [] 32 | } 33 | 34 | public func insert( sound:PGSound, to storage:PGAudioStorage? ) { 35 | guard let storage = storage else { return } 36 | if soundGroup[storage] == nil { soundGroup[storage] = [] } 37 | 38 | if sound.channel == -1 { return } 39 | 40 | if let previous_sound = soundGroup[storage]!.filter({ $0.channel == sound.channel }).first { 41 | soundGroup[storage]?.remove( previous_sound ) 42 | } 43 | 44 | soundGroup[storage]?.insert( sound ) 45 | } 46 | 47 | public func remove( sound:PGSound, to storage:PGAudioStorage? ) { 48 | guard let storage = storage else { return } 49 | soundGroup[storage]?.remove( sound ) 50 | } 51 | 52 | public func removeAllSounds( on storage:PGAudioStorage? ) { 53 | guard let storage = storage else { return } 54 | soundGroup[storage]?.forEach { $0.trush() } 55 | } 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Sources/Lily_Stage/Playground/Model/Shaders/Lily.Stage.Playground.Model.Mesh.h: -------------------------------------------------------------------------------- 1 | // 2 | // LilySwift Library Project 3 | // 4 | // Copyright (c) Watanabe-Denki, Inc. and Kengo Watanabe. 5 | // https://wdkk.co.jp/ 6 | // 7 | // This software is released under the MIT License. 8 | // https://opensource.org/licenses/mit-license.php 9 | // 10 | 11 | #import "Lily.Stage.Playground.Model.util.h" 12 | #import "../../../Standard/Shaders/Lily.Stage.MathMatrix.metal" 13 | #import "../../../Standard/Shaders/Lily.Stage.Model.Obj.metal" 14 | 15 | using namespace metal; 16 | using namespace Lily::Stage::Model; 17 | using namespace Lily::Stage::Playground; 18 | 19 | namespace Lily 20 | { 21 | namespace Stage 22 | { 23 | namespace Playground 24 | { 25 | namespace Model 26 | { 27 | namespace Mesh 28 | { 29 | // vertexからfragmentへ渡す値 30 | struct VOut 31 | { 32 | float4 position [[ position ]]; 33 | float3 color; 34 | float3 normal; 35 | }; 36 | 37 | struct UnitStatus 38 | { 39 | float4x4 matrix; 40 | float4 atlasUV; 41 | float4 color; 42 | float4 deltaColor; 43 | float3 position; 44 | float3 deltaPosition; 45 | float3 scale; 46 | float3 deltaScale; 47 | float3 rotation; 48 | float3 deltaRotation; 49 | float life; 50 | float deltaLife; 51 | float enabled; 52 | float state; 53 | int modelIndex; 54 | }; 55 | } 56 | } 57 | } 58 | } 59 | } 60 | --------------------------------------------------------------------------------