Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ObjCRuntime/Protocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ public Protocol (string name)
throw new ArgumentException (String.Format ("'{0}' is an unknown protocol", name));
}

public Protocol (Type type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

{
if (type.IsInterface) {
foreach (var pa in type.GetCustomAttributes<ProtocolAttribute> (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;
Expand Down
54 changes: 54 additions & 0 deletions src/modelio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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; }

Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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")]
Expand Down
12 changes: 11 additions & 1 deletion tests/monotouch-test/ModelIO/MDLObject.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// MDLLight Unit Tests
// MDLObject Unit Tests
//
// Authors:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
Expand Down Expand Up @@ -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));
}
}
}
}

Expand Down