diff --git a/src/ObjCRuntime/Protocol.cs b/src/ObjCRuntime/Protocol.cs index 65832a16cb72..b766d4ca3a00 100644 --- a/src/ObjCRuntime/Protocol.cs +++ b/src/ObjCRuntime/Protocol.cs @@ -24,6 +24,19 @@ public Protocol (string name) throw new ArgumentException (String.Format ("'{0}' is an unknown protocol", name)); } + public Protocol (Type type) + { + if (type.IsInterface) { + foreach (var pa in type.GetCustomAttributes (false)) { + handle = objc_getProtocol (pa.Name); + if (handle != IntPtr.Zero) + return; + } + } + if (handle == IntPtr.Zero) + throw new ArgumentException (string.Format ("'{0}' is an unknown protocol", type.FullName)); + } + public Protocol (IntPtr handle) { this.handle = handle; diff --git a/src/modelio.cs b/src/modelio.cs index e1bc9153cb37..a212b21417c0 100644 --- a/src/modelio.cs +++ b/src/modelio.cs @@ -90,6 +90,29 @@ interface MDLAsset : NSCopying [Export ("canExportFileExtension:")] bool CanExportFileExtension (string extension); + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Export ("components", ArgumentSemantic.Copy)] + IMDLComponent[] Components { get; } + + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [EditorBrowsable (EditorBrowsableState.Advanced)] + [Export ("setComponent:forProtocol:")] + void SetComponent (IMDLComponent component, Protocol protocol); + + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Wrap ("SetComponent (component, new Protocol (type))")] + void SetComponent (IMDLComponent component, Type type); + + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [EditorBrowsable (EditorBrowsableState.Advanced)] + [Export ("componentConformingToProtocol:")] + [return: NullAllowed] + IMDLComponent GetComponent (Protocol protocol); + + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Wrap ("GetComponent (new Protocol (type))")] + IMDLComponent GetComponent (Type type); + [iOS (10,0)] [Mac (10,12)] [TV (10,0)] @@ -986,13 +1009,31 @@ interface MDLNormalMapTexture [BaseType (typeof(NSObject))] interface MDLObject : MDLNamed { + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Export ("components", ArgumentSemantic.Copy)] + IMDLComponent[] Components { get; } + [Export ("setComponent:forProtocol:")] void SetComponent (IMDLComponent component, Protocol protocol); + [Wrap ("SetComponent (component, new Protocol (type))")] + void SetComponent (IMDLComponent component, Type type); + +#if XAMCORE_4_0 + [Internal] +#endif + [Obsolete ("Use GetComponent (Type type)")] [Export ("componentConformingToProtocol:")] [return: NullAllowed] IMDLComponent IsComponentConforming (Protocol protocol); + [EditorBrowsable (EditorBrowsableState.Advanced)] + [Wrap ("IsComponentConforming (protocol)")] + IMDLComponent GetComponent (Protocol protocol); + + [Wrap ("GetComponent (new Protocol (type))")] + IMDLComponent GetComponent (Type type); + [NullAllowed, Export ("parent", ArgumentSemantic.Weak)] MDLObject Parent { get; set; } @@ -1068,6 +1109,14 @@ interface MDLObjectContainerComponent : MDLComponent, INSFastEnumeration [Export ("removeObject:")] void RemoveObject (MDLObject @object); + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Export ("objectAtIndexedSubscript:")] + MDLObject GetObject (nuint index); + + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Export ("count")] + nuint Count { get; } + [Abstract] [Export ("objects", ArgumentSemantic.Retain)] MDLObject[] Objects { get; } @@ -1537,6 +1586,11 @@ interface MDLTransform : MDLTransformComponent, NSCopying { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] void SetRotation (Vector3 rotation, double time); + [iOS (10,3), TV (10,2), Mac (10,12,4)] + [Export ("setMatrix:forTime:")] + [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] + void SetMatrix (Matrix4 matrix, double time); + [Export ("shear", ArgumentSemantic.Assign)] Vector3 Shear { [MarshalDirective (NativePrefix = "xamarin_simd__", Library = "__Internal")] diff --git a/tests/monotouch-test/ModelIO/MDLObject.cs b/tests/monotouch-test/ModelIO/MDLObject.cs index e20d4728c47a..fa4274851bfa 100644 --- a/tests/monotouch-test/ModelIO/MDLObject.cs +++ b/tests/monotouch-test/ModelIO/MDLObject.cs @@ -1,5 +1,5 @@ // -// MDLLight Unit Tests +// MDLObject Unit Tests // // Authors: // Rolf Bjarne Kvinge @@ -63,6 +63,16 @@ public void GetBoundingBox () var bb = obj.GetBoundingBox (0); } } + + [Test] + public void ProtocolTest () + { + using (var obj = new MDLObject ()) { + var p = new Protocol (typeof (IMDLComponent)); + obj.SetComponent (new MDLTransform (), p); + Assert.NotNull (obj.IsComponentConforming (p)); + } + } } }