By Ha_Loe
#350850
Hi,

the question is Rhino related so this may or may not be the right forum, if not, feel free to move the topic.

I am baking colors to generic Rhino materials but would like to generate light emitting materials and generally use the Maxwell material options to their full extend.
As the plugin is a .NET assembly it might be possible to hook into it. Obviously there is no official or supported way to do this. I was hoping to at least get permission to access the plugins functions and hopefully get some help on the way.

Best regards
Hannes
#350862
The plugin actually consists of six or seven .NET assemblies, depending on the install scenario. While it would be technically possible to work with the system from arbitrary .NET code, I am just going to state that that this is neither supported nor encouraged. I have such scenarios in mind going forward with the plugin rewrite necessitated by Rhino OSX, but as for the current plugin, it is simply not designed to be used from external code.
#352545
Hi Jeremy

I have a question, which I'm afraid could be directly related to the above...
I've been having a look into python for rhino recently, and have found it fun, inspiring (and even useful).

So the inevitable question is: is there a possibility to adress the the maxwell-plugin via python for rhino (a maxwell-library?). I do realize that you wrote in the above reply, that the current build is not designed to work with outside code, but I didn't want to leave this unattempted... :)

It would be just so amazing, for example to create series or arrays of materials for testing purposes and automatically render previews of them for example, or change environment or camera settings.
Scripted animations....

So, in case it's not yet possible, do you think it might be in the future?

Thanks for your great work already - we use the maxwell-plugin for rhino every day, and we love it.

Cheers

Lutz
By JDHill
#352546
Technically, as I hint above, you can get your hands on the plugin's runtime environment from python, if you know what you're doing. However, this not only requires knowledge that is undocumented, but the access itself is also completely subject to change, so I do not put this forth as a supported practice; any code you might write, I might break in the next update. So at least for now, it is just not supported.

For what it's worth, though, you mention environment, and here (and for most values contained in the Scene Manager, besides cameras & materials), you do have supported access via the plugin's commands and/or RhinoScript.
#352553
just to give this some more weight...
we are also starting to think & test in this direction...

grasshopper + rhino = animation toolbox

it is something that is very.. very promising in the future, if mcneel ever stops this sisyphus rhino5 thing...
By Ha_Loe
#352740
Not all is lost as the Maxwell plugin translates standard rhino materials. Rhino5 materials now have an "emission color" field. Any chance that there will be an update supporting this feature?

I've been further looking into the subject and managed to create maxwell materials in Grasshopper.
Baking materials is another thing altogether. Maxwell plugin relies on the "old" Rhino.NET framework and Grasshopper is based on RhinoCommon. I could not find a way to set the UserString property that Maxwell uses to attach maxwell material information to Rhino objects in RhinoCommon.

Just recently the whole topic of emissive materials popped up on the grasshopper forums. For VRay in this case, still there is a demand to use the full power of render materials in Grasshopper. Might be a great argument to sell Maxwell :wink:

@polynurb: maybe we could get in touch on this matter
By JDHill
#352744
Yes, I noticed that when I was playing around with python. A Maxwell material ID is indeed stored as a string on Rhino materials with which it is associated, but there appears to be no RhinoCommon accessor for getting/setting strings on Rhino materials. I can check into the emission parameter and see if we can make use of that, since it does exist in Rhino 4, even if it is not used.
#352755
RhinoCommon exposes a UserDictionary and a UserData which might or might not be a way to get access to the UserStrings. I can see that the rhino material attached has attached UserData but I cannot retrieve it. You have to request the data by type and the type has to be inherited from UserData. So requesting a type of String will obviously fail.
The UserDictionary, which would be the obvoius guess for String key-value pairs turns out to be empty.

btw: The corresponding Rhino material of a (manually added) Maxwell material seems to be lingering after I (manally) delete the material form the scene manager. The material shows up valid und not deleted. Reloading the material adds up one more copy of the Rhino material table.
#352886
I attach the Maxwell material ID to OnMaterials using OnObject::SetUserString; apparently, you cannot retrieve this string via the UserDictionary or UserData of a RhinoCommon CommonObject. I don't know if that's the intended behavior or not. And yes, removing a Maxwell material from the scene does not result in the removal of any Rhino materials.
By Ha_Loe
#353259
JDHill wrote:What have you done? :mrgreen:

Seriously, I'd like to see what you're doing there.
Actually it was way simpler than I thought. The plugin already has all the necessary methods in place and legally exported. I'll send you the zipped VC2008 project.

I'm referencing Maxwell.dll and Maxwell.UI.dll from the GAC. Not sure if this will work on any other machine than mine. I'd love to see the component run on other machines. Anything that speaks against me releasing the component to the grasshopper comunity?
By JDHill
#353272
Maxwell.dll and Maxwell.UI.dll are in the GAC on every install (shared by the Rhino & SolidWorks plugins, if both are installed), but the location of Maxwell.Rhino.rhp is arbitrarily decided by the user during install, so you would need to locate that yourself at runtime (just like Rhino does, you could use the registry). However, you should not need that reference in many cases (more on this later).

As far as distributing something like this, as I wrote above, it is simply and completely unsupported; I commonly have to make changes that might arbitrarily break your code (for example, there were a lot of internal changes required when Maxwell Fire was added, or when I added support for Extrusion objects, etc, etc). Understanding that, though, I am not going to stop you playing around with this stuff.

All that aside, I see a couple of changes you could make to help it work a bit better. First, calling Init() is not going to be a good plan -- that will clear everything out, but it also resets the internal ID of the object. This is why your grasshopper component is creating superfluous materials sometimes. A way around it is to take a slightly different approach -- rather than always clearing out the material, only create the Layers & Bsdfs when they don't previously exist. Here is some code that does it that way:
Maxwell.Helpers.zip
If you use this code, you can remove the reference to Maxwell.Rhino.rhp, firstly because it accesses the scene through Scene.CurrentInstance instead of the plugin's mxGlobal, which at this point is just a redirect to CurrentInstance, and secondly because it adds materials using mxObjectServer. The plugin is always listening to the server, and if it hears about a new material being added, it will perform the necessary fixups. Thirdly, you have here a GetFirstRhinoMaterialIndexFor(Maxwell.Material) method that either finds the first matching Rhino material, or adds a new one and returns the index for that. Put together, these allow you to drop the reference to the actual plugin rhp.

On leaving existing Layers & BSDFs alone, in most cases, your user has probably not messed around with your created material, but in the case that they have, you are not screwing around with any changes they may have made. So, if I have put a bump map into the BSDF, it is still there after you update the refl0, refl90 and roughness. This also results in fewer events, and therefore, less throttling for Maxwell Fire (and the material preview). It might not be your intention to allow that, though, in which case, once you have your reference to the material, just loop through and remove unnecessary Layers and Bsdfs.

So, using these methods, your GH_MaxwellMaterial::MaterialIndex becomes:
Code: Select all
public int MaterialIndex
{
    get {  return Maxwell.Helpers.GetFirstRhinoMaterialIndexFor(Value); }
}
MaterialList::ApplyMaterialToObject becomes:
Code: Select all
private Material ApplyMaterialToObject(RhinoDoc doc, RhinoObject obj, Maxwell.Materials.Material mat)
{
    Material result = null;
    int materialIndex = Maxwell.Helpers.GetFirstRhinoMaterialIndexFor(mat);

    if (materialIndex > -1)
    {
        result = doc.Materials[materialIndex];
        obj.Attributes.MaterialSource = ObjectMaterialSource.MaterialFromObject;
        obj.Attributes.MaterialIndex = materialIndex;
        obj.CommitChanges();
    }

    return result;
}
And, for example, MaxwellDiffuseMaterial::SolveInstance uses this call:
Code: Select all
mxMaterial = Maxwell.Helpers.EnsureRgbMaterial(name, diff0, diff90);
So play around with that and let me know how it goes.
You do not have the required permissions to view the files attached to this post.
Sketchup 2025 Released

Thank you Fernando!!!!!!!!!!!!!!!!!!!!!!!!!!! hwol[…]

I've noticed that "export all" creates l[…]

hmmm can you elaborate a bit about the the use of […]

render engines and Maxwell

Funny, I think, that when I check CG sites they ar[…]