예제 #1
0
        /// <summary>
        /// Call this method once from your plug-ins OnLoad override for each
        /// assembly containing a custom mesh provider.  Only publicly exported
        /// classes derived from CustomRenderMeshProvider with a public constructor
        /// that has no parameters will get registered.
        /// </summary>
        /// <param name="assembly">
        /// Assembly to search for valid CustomRenderMeshProvider derived classes.
        /// </param>
        /// <param name="pluginId">
        /// The plug-in that owns the custom mesh providers.
        /// </param>
        public static void RegisterProviders(System.Reflection.Assembly assembly, Guid pluginId)
        {
            var plugin = PlugIns.PlugIn.GetLoadedPlugIn(pluginId);

            if (plugin == null)
            {
                return;
            }

            var exported_types = assembly.GetExportedTypes();
            var provider_types = new List <Type>();
            var custom_type    = typeof(CustomRenderMeshProvider);
            var options        = new Type[] {};

            foreach (var type in exported_types)
            {
                if (!type.IsAbstract && type.IsSubclassOf(custom_type) && type.GetConstructor(options) != null)
                {
                    provider_types.Add(type);
                }
            }

            if (provider_types.Count == 0)
            {
                return;
            }

            var rdk_plugin = RdkPlugIn.GetRdkPlugIn(plugin);

            if (rdk_plugin == null)
            {
                return;
            }

            foreach (var type in provider_types)
            {
                var provider = Activator.CreateInstance(type) as CustomRenderMeshProvider;
                if (provider == null)
                {
                    continue;
                }
                var cpp_object = provider.CreateCppObject(pluginId);
                if (cpp_object == IntPtr.Zero)
                {
                    continue;
                }
                g_all_providers.Add(provider.m_runtime_serial_number, provider);
                UnsafeNativeMethods.Rdk_RegisterCRMProvider(cpp_object);
            }
        }
예제 #2
0
 /// <summary>
 /// Create a new C++ runtime RDK plug-in object then create a RhinoCommon
 /// RdkPlugIn, attach the C++ pointer to it and set the C++ callback
 /// function pointers to the RckPlugIn.
 /// </summary>
 /// <param name="rhinoPlugIn">
 /// The C++ pointer to the native CRhinoPlugIn that is causing this RDK
 /// plug-in to get added.
 /// </param>
 /// <param name="rhinoPlugInId">The plug-in Id</param>
 /// <param name="serialNumber">Plug-in C++ pointer serial number</param>
 /// <returns></returns>
 static private RdkPlugIn AddPlugInToDictionary(IntPtr rhinoPlugIn, Guid rhinoPlugInId, int serialNumber)
 {
     if (rhinoPlugIn != IntPtr.Zero)
     {
         var ptr_rdk_plugin = UnsafeNativeMethods.CRhCmnRdkPlugIn_New(rhinoPlugIn, serialNumber);
         if (ptr_rdk_plugin != IntPtr.Zero)
         {
             SetRdkCallbackFunctions(true);
             var plugin = new RdkPlugIn(ptr_rdk_plugin, rhinoPlugInId);
             g_rdk_plugin_dictionary.Add(rhinoPlugInId, plugin);
             return(plugin);
         }
     }
     return(null);
 }
예제 #3
0
        public static Type[] RegisterContentIo(System.Reflection.Assembly assembly, System.Guid pluginId)
        {
            Rhino.PlugIns.PlugIn plugin = Rhino.PlugIns.PlugIn.GetLoadedPlugIn(pluginId);
            if (plugin == null)
            {
                return(null);
            }

            //Find all public types exported in the plug-in that we're dealing with
            Type[] exported_types = assembly.GetExportedTypes();
            if (exported_types != null)
            {
                List <Type> contentio_types = new List <Type>();
                for (int i = 0; i < exported_types.Length; i++)
                {
                    //If the type is a Render.IOPlugIn, add it to the "to register" list.
                    Type t = exported_types[i];
                    if (!t.IsAbstract && t.IsSubclassOf(typeof(Rhino.Render.IOPlugIn)) && t.GetConstructor(new Type[] { }) != null)
                    {
                        contentio_types.Add(t);
                    }
                }

                // make sure that content types have not already been registered
                for (int i = 0; i < contentio_types.Count; i++)
                {
                    Type t = contentio_types[i];

                    if (!RdkPlugIn.RenderContentIoTypeIsRegistered(t))
                    {
                        //The object registers itself in a static array
                        IOPlugIn pi = System.Activator.CreateInstance(t) as IOPlugIn;
                        pi.Construct(pluginId);
                    }
                }

                return(contentio_types.ToArray());
            }
            return(null);
        }
예제 #4
0
 /// <summary>
 /// Create a new C++ runtime RDK plug-in object then create a RhinoCommon
 /// RdkPlugIn, attach the C++ pointer to it and set the C++ callback
 /// function pointers to the RckPlugIn.
 /// </summary>
 /// <param name="rhinoPlugIn">
 /// The C++ pointer to the native CRhinoPlugIn that is causing this RDK
 /// plug-in to get added.
 /// </param>
 /// <param name="rhinoPlugInId">The plug-in Id</param>
 /// <param name="serialNumber">Plug-in C++ pointer serial number</param>
 /// <returns></returns>
 static private RdkPlugIn AddPlugInToDictionary(IntPtr rhinoPlugIn, Guid rhinoPlugInId, int serialNumber)
 {
   if (rhinoPlugIn != IntPtr.Zero)
   {
     var ptr_rdk_plugin = UnsafeNativeMethods.CRhCmnRdkPlugIn_New(rhinoPlugIn, serialNumber);
     if (ptr_rdk_plugin != IntPtr.Zero)
     {
       SetRdkCallbackFunctions(true);
       var plugin = new RdkPlugIn(ptr_rdk_plugin, rhinoPlugInId);
       g_rdk_plugin_dictionary.Add(rhinoPlugInId, plugin);
       return plugin;
     }
   }
   return null;
 }
예제 #5
0
 static RdkPlugIn GetRdkPlugInHelper(IntPtr pRhinoPlugIn, Guid rhinoPlugInId, int serial_number)
 {
   if (pRhinoPlugIn != IntPtr.Zero)
   {
     IntPtr pRdkPlugIn = UnsafeNativeMethods.CRhCmnRdkPlugIn_New(pRhinoPlugIn, serial_number);
     if (pRdkPlugIn != IntPtr.Zero)
     {
       SetRdkCallbackFunctions(true);
       RdkPlugIn rc = new RdkPlugIn(pRdkPlugIn, rhinoPlugInId);
       m_all_rdk_plugins.Add(rc);
       return rc;
     }
   }
   return null;
 }