TransWikia.com

UnityLink called from wolframscript seems to work, but

Mathematica Asked by rlj on May 25, 2021

I’ve tried to use UnityLink with Mathematica 12.1.1 on OS X 10.15.7.
I found that code running ok in Mathematica FrontEnd does not run correctly if used in wolframscript.

When exporting the notebook code to wls all lines containing Unity functions are surrounded by comments.
After removing the comments this happens:

  1. creates a bunch of error messages
raytrace/unity > ./tstHull.wls

Syntax::com: Warning: comma encountered with no adjacent expression. The expression will be treated as Null.  (line 469 of "/Users/_/Library/Mathematica/Paclets/Repository/UnityLink-2020.02.02/Kernel/UnityAssets.m").

UnityLink`Developer`$UnityIcons::shdw: Symbol $UnityIcons appears in multiple contexts {UnityLink`Developer`, UnityLink`}; definitions in context UnityLink`Developer` may shadow or be shadowed by other definitions.

UnityLink`Developer`$UnityIconSizes::shdw: Symbol $UnityIconSizes appears in multiple contexts {UnityLink`Developer`, UnityLink`}; definitions in context UnityLink`Developer` may shadow or be shadowed by other definitions.

Table::iterb: Iterator {target, $UnityNETBuildTargets} does not have appropriate bounds.

Table::iterb: Iterator {group, $UnityNETBuildTargetGroups} does not have appropriate bounds.

Get::noopen: Cannot open /Users/_/Library/Mathematica/Paclets/Repository/UnityLink-2020.02.02/Kernel/UnityNETComponents.m.

RuleDelayed::rhs: Pattern net_ appears on the right-hand side of rule saveUnityScene[(net_)?NETObjectQ, file_File] :> saveUnityScene[net_, First[file]].

Get::noopen: Cannot open /Users/_/Library/Mathematica/Paclets/Repository/UnityLink-2020.02.02/Kernel/UnityEditor.m.

  1. image quality is much worse than if same code is called from Mathematica FrontEnd

image created by wolfrsmscript

as opposed to

image created from frontEnd

  1. wolframscript code:
#!/usr/bin/env wolframscript

SetDirectory@".";
Get@"../../HyperPlatonics.m";
Get@"../../PlatonicSymmetries.m";
Get@"../../Util.m";



Needs["UnityLink`"];



UnityOpen["Sym3Hull"];
CreateUnityAssetDirectory[{"Scenes","Meshes","Materials"}];
CreateUnityScene[File["Scenes/Sym3Hull"]];



glassHull=CreateUnityGameObject[
    "glassHull",
    Graphics3D[Map[22#&,GeneralizedHyperbolicPlato["Hexahedron",[email protected],3,7,.9,.8,{}][[1,-1]],{-1}]]
];
hullMat=CreateUnityMaterial[
    File["Materials/Mat_glassHull"],
    Properties->{
        "RenderQueue"->3000,
        "Color"->RGBColor[0.529405,0.807794,0.980407,0.4],
        "_Glossiness"->1,
        "_GlossMapScale"->0.8,
        "_Metallic"->0.1,
        "ShaderKeywords"->{"_ALPHAPREMULTIPLY_ON","_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"},
        "_Mode"->3,
        "_DstBlend"->10,
        "_ZWrite"->1.}
];
SetProperty[glassHull,"SharedMaterial"->hullMat];
CreateUnityReflectionProbe[glassHull];



sym3cube=CreateUnityGameObject[
    "sym3cube",
    Graphics3D[threeSymCube[MakeGCPolygons,40,{},.8,4.5][[1,-1]]]
];
symMat=CreateUnityMaterial[
    File["Materials/Mat_sym3cube"],
    Properties->{
        "RenderQueue"->3000,
        "Color"->RGBColor[00.829997,0.099994,0.119999,0.4],
        "_Glossiness"->1,
        "_GlossMapScale"->0.8,
        "_Metallic"->0.1,
        "ShaderKeywords"->{"_ALPHAPREMULTIPLY_ON","_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"},
        "_Mode"->3,
        "_DstBlend"->10,
        "_ZWrite"->1.}
];
SetProperty[sym3cube,"SharedMaterial"->symMat];
CreateUnityReflectionProbe[sym3cube];



camera=FindUnityComponent["Main Camera"];
camera[["Position"]] = {12, .0, 0};
camera[["EulerAngles"]] = {0, -90, 0};
Export["tstHull.png", UnityCameraImage[]]

(*CloseUnity[]*)

So, is it not (yet) possible to use UnityLink from wolframscript?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP