@scenoco-three/unity 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/package.json +2 -2
- package/unity/PORTING.md +14 -5
- package/unity/SceNoCoImporter.cs +118 -0
package/README.md
CHANGED
|
@@ -45,3 +45,7 @@ cannot be carried across is listed as a warning, with the file and line it was w
|
|
|
45
45
|
|
|
46
46
|
three.js is right-handed and Unity left-handed: the export mirrors Z, and divides light intensities
|
|
47
47
|
by π.
|
|
48
|
+
|
|
49
|
+
SceNoCo is not sponsored by or affiliated with Unity Technologies or its affiliates. Unity is a trademark or
|
|
50
|
+
registered trademark of Unity Technologies or its affiliates in the U.S. and elsewhere. Nor is it affiliated with
|
|
51
|
+
Demigiant, the maker of DOTween.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scenoco-three/unity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Export a SceNoCo game's prefabs, scenes, meshes and materials into a Unity project: nested prefabs, shared materials, behaviours as MonoBehaviours with their fields wired.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"rolldown": "^1.0.3"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@scenoco-three/core": "^1.
|
|
57
|
+
"@scenoco-three/core": "^1.2.0",
|
|
58
58
|
"vite": ">=6"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/unity/PORTING.md
CHANGED
|
@@ -39,6 +39,14 @@ is the rules for that. It is rewritten by every export.
|
|
|
39
39
|
instantiates is a `GameObject` field set to its prefab asset. `findObjectOfType` is
|
|
40
40
|
`FindFirstObjectByType`, `findObjectsOfType` is `FindObjectsByType<T>()` (before Unity 6.6,
|
|
41
41
|
`FindObjectsByType<T>(FindObjectsSortMode.None)`).
|
|
42
|
+
- **Tweens map to DOTween's calls**, once the project has DOTween (Asset Store, free; not part of this export):
|
|
43
|
+
`node.doMove(to, 0.5).setEase(Ease.OutBack)` is `transform.DOMove(to, 0.5f).SetEase(Ease.OutBack)`,
|
|
44
|
+
`Tween.sequence().append(a).join(b)` is `DOTween.Sequence().Append(a).Join(b)`,
|
|
45
|
+
`Tween.delayedCall(s, fn)` is `DOVirtual.DelayedCall(s, fn, false)`, `Tween.float` is `DOVirtual.Float`,
|
|
46
|
+
`Tween.to(get, set, to, d)` is `DOTween.To(get, set, to, d)`, `tween.setLink(this)` is
|
|
47
|
+
`.SetLink(gameObject)`, and `yield tween.waitForCompletion()` is `yield return tween.WaitForCompletion()`.
|
|
48
|
+
A tween on a node ended with the node without being told: add `.SetLink(gameObject)`. A rotation
|
|
49
|
+
given as a `Vector3` is degrees in both; an `Euler` was radians, so convert it.
|
|
42
50
|
- **Coroutines**: a `*generator` is an `IEnumerator`, `this.startCoroutine(this.x())` is
|
|
43
51
|
`StartCoroutine(X())`, `yield new WaitForSeconds(s)` is the same, `yield null` waits a frame.
|
|
44
52
|
- **Events**: an `Event<T>` field is a C# `event Action<T>`; `listen(e, f)` is `e += f`, and its
|
|
@@ -118,12 +126,13 @@ skybox reflections in a scene with no environment. Lights divide by π; fog and
|
|
|
118
126
|
the scene. Cameras draw with no post-processing, as three's default renderer does. What `main.ts` set
|
|
119
127
|
up in code is the port's:
|
|
120
128
|
|
|
121
|
-
- **
|
|
129
|
+
- **A `Volume` in a scene came across**: a URP Volume with its profile in `Assets/Materials`, and Post
|
|
130
|
+
Processing on for each camera. Bloom's and depth of field's settings do not carry over by number:
|
|
131
|
+
tune them against the web game.
|
|
132
|
+
- **Tone mapping and an `EffectComposer` set up by hand** (`renderer.toneMapping`) are a URP Volume too:
|
|
122
133
|
a profile with Tonemapping (ACES), Color Adjustments (post exposure is log₂ of three's
|
|
123
|
-
`toneMappingExposure`) and Bloom, on a GameObject kept across scenes
|
|
124
|
-
|
|
125
|
-
profile made from code needs `EditorUtility.SetDirty` before it is saved, or its list of components
|
|
126
|
-
is lost.
|
|
134
|
+
`toneMappingExposure`) and Bloom, on a GameObject kept across scenes. A profile made from code needs
|
|
135
|
+
`EditorUtility.SetDirty` before it is saved, or its list of components is lost.
|
|
127
136
|
|
|
128
137
|
## Checking the port
|
|
129
138
|
|
package/unity/SceNoCoImporter.cs
CHANGED
|
@@ -286,6 +286,7 @@ namespace SceNoCo
|
|
|
286
286
|
{
|
|
287
287
|
cam.clearFlags = hasBackground ? CameraClearFlags.SolidColor : cam.clearFlags;
|
|
288
288
|
cam.backgroundColor = background;
|
|
289
|
+
Volumes.Enable(cam);
|
|
289
290
|
}
|
|
290
291
|
if (cameras.Count > 0) cameras[0].gameObject.tag = "MainCamera";
|
|
291
292
|
else warnings.Add($"{path}: no camera in the scene.");
|
|
@@ -382,6 +383,7 @@ namespace SceNoCo
|
|
|
382
383
|
}
|
|
383
384
|
else if (type == "ParticleSystem") Particles.Add(go, Obj(comp["fields"]), w => warnings.Add($"{Where(comp, n)}: {w}"));
|
|
384
385
|
else if (type == "UIDocument") MakeDocument(go, Obj(comp["fields"]), Where(comp, n));
|
|
386
|
+
else if (Volumes.Add(go, type, Obj(comp["fields"]))) { }
|
|
385
387
|
else if (!Physics.Add(go, type, Obj(comp["fields"]))) warnings.Add($"{Where(comp, n)}: {type} has no Unity counterpart here — left off.");
|
|
386
388
|
}
|
|
387
389
|
|
|
@@ -392,6 +394,122 @@ namespace SceNoCo
|
|
|
392
394
|
return go;
|
|
393
395
|
}
|
|
394
396
|
|
|
397
|
+
/// <summary>
|
|
398
|
+
/// A game's post effects as a URP Volume and its profile, one per node that has them. By type name and
|
|
399
|
+
/// serialized field, as the project's settings are, so a project without URP still compiles this.
|
|
400
|
+
/// </summary>
|
|
401
|
+
static class Volumes
|
|
402
|
+
{
|
|
403
|
+
const string Rendering = "UnityEngine.Rendering.{0}, Unity.RenderPipelines.Core.Runtime";
|
|
404
|
+
const string Universal = "UnityEngine.Rendering.Universal.{0}, Unity.RenderPipelines.Universal.Runtime";
|
|
405
|
+
static readonly Dictionary<GameObject, ScriptableObject> Profiles = new Dictionary<GameObject, ScriptableObject>();
|
|
406
|
+
static readonly HashSet<string> Written = new HashSet<string>();
|
|
407
|
+
static readonly string[] Effects = { "Bloom", "Tonemapping", "ColorAdjustments", "Vignette", "DepthOfField", "ChromaticAberration", "FilmGrain" };
|
|
408
|
+
|
|
409
|
+
public static bool Add(GameObject go, string type, Dictionary<string, object> f)
|
|
410
|
+
{
|
|
411
|
+
if (type == "Volume")
|
|
412
|
+
{
|
|
413
|
+
Profile(go);
|
|
414
|
+
var volume = new SerializedObject(go.GetComponent(Type.GetType(string.Format(Rendering, "Volume"))));
|
|
415
|
+
volume.FindProperty("priority").floatValue = Num(f, "priority", 0);
|
|
416
|
+
volume.ApplyModifiedPropertiesWithoutUndo();
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
if (!Effects.Contains(type)) return false;
|
|
420
|
+
var effect = Type.GetType(string.Format(Universal, type));
|
|
421
|
+
if (effect == null) return false;
|
|
422
|
+
var profile = Profile(go);
|
|
423
|
+
var added = (ScriptableObject)profile.GetType().GetMethod("Add", new[] { typeof(Type), typeof(bool) }).Invoke(profile, new object[] { effect, false });
|
|
424
|
+
var o = new SerializedObject(added);
|
|
425
|
+
void Float(string name, float value) => Set(o, name, p => p.floatValue = value);
|
|
426
|
+
void Tint(string name, string field, string fallback) => Set(o, name, p => p.colorValue = f.TryGetValue(field, out var c) ? Hex((string)Obj(c)["color"]) : Hex(fallback));
|
|
427
|
+
switch (type)
|
|
428
|
+
{
|
|
429
|
+
case "Bloom":
|
|
430
|
+
Float("threshold", Num(f, "threshold", 0.9f));
|
|
431
|
+
Float("intensity", Num(f, "intensity", 1));
|
|
432
|
+
Float("scatter", Num(f, "scatter", 0.7f));
|
|
433
|
+
Tint("tint", "tint", "#ffffff");
|
|
434
|
+
break;
|
|
435
|
+
case "Tonemapping":
|
|
436
|
+
var mode = f.TryGetValue("mode", out var m) ? (string)m : "ACES";
|
|
437
|
+
Set(o, "mode", p => p.enumValueIndex = mode == "ACES" ? 2 : mode == "Neutral" ? 1 : 0);
|
|
438
|
+
break;
|
|
439
|
+
case "ColorAdjustments":
|
|
440
|
+
Float("postExposure", Num(f, "postExposure", 0));
|
|
441
|
+
Float("contrast", Num(f, "contrast", 0));
|
|
442
|
+
Float("hueShift", Num(f, "hueShift", 0));
|
|
443
|
+
Float("saturation", Num(f, "saturation", 0));
|
|
444
|
+
Tint("colorFilter", "colorFilter", "#ffffff");
|
|
445
|
+
break;
|
|
446
|
+
case "Vignette":
|
|
447
|
+
Float("intensity", Num(f, "intensity", 0.3f));
|
|
448
|
+
Float("smoothness", Num(f, "smoothness", 0.2f));
|
|
449
|
+
Tint("color", "color", "#000000");
|
|
450
|
+
if (f.TryGetValue("center", out var c))
|
|
451
|
+
{
|
|
452
|
+
var at = Floats(Obj(c)["v2"]);
|
|
453
|
+
Set(o, "center", p => p.vector2Value = new Vector2(at[0], at[1]));
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
case "DepthOfField":
|
|
457
|
+
Set(o, "mode", p => p.enumValueIndex = 2); // Bokeh
|
|
458
|
+
Float("focusDistance", Num(f, "focusDistance", 10));
|
|
459
|
+
Float("focalLength", Num(f, "focalLength", 50));
|
|
460
|
+
Float("aperture", Num(f, "aperture", 5.6f));
|
|
461
|
+
break;
|
|
462
|
+
default:
|
|
463
|
+
Float("intensity", Num(f, "intensity", 0.3f));
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
o.ApplyModifiedPropertiesWithoutUndo();
|
|
467
|
+
// Each is an object of its own in the profile's file, and its list is lost at save unless marked.
|
|
468
|
+
AssetDatabase.AddObjectToAsset(added, profile);
|
|
469
|
+
EditorUtility.SetDirty(added);
|
|
470
|
+
EditorUtility.SetDirty(profile);
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/// <summary>Post Processing on for a camera, in a game with a Volume in any scene: one kept across loads shapes every level's camera.</summary>
|
|
475
|
+
public static void Enable(Camera camera)
|
|
476
|
+
{
|
|
477
|
+
if (Profiles.Count == 0 && !File.ReadAllText(DataPath).Contains("\"Volume\"")) return;
|
|
478
|
+
var data = Type.GetType(string.Format(Universal, "UniversalAdditionalCameraData"));
|
|
479
|
+
if (data == null) return;
|
|
480
|
+
var extra = camera.GetComponent(data) ?? camera.gameObject.AddComponent(data);
|
|
481
|
+
var o = new SerializedObject(extra);
|
|
482
|
+
o.FindProperty("m_RenderPostProcessing").boolValue = true;
|
|
483
|
+
o.ApplyModifiedPropertiesWithoutUndo();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
static ScriptableObject Profile(GameObject go)
|
|
487
|
+
{
|
|
488
|
+
if (Profiles.TryGetValue(go, out var made)) return made;
|
|
489
|
+
var profileType = Type.GetType(string.Format(Rendering, "VolumeProfile"));
|
|
490
|
+
var path = $"Assets/Materials/Volume-{go.name}.asset";
|
|
491
|
+
for (var i = 2; !Written.Add(path); i++) path = $"Assets/Materials/Volume-{go.name}-{i}.asset";
|
|
492
|
+
Directory.CreateDirectory("Assets/Materials");
|
|
493
|
+
AssetDatabase.DeleteAsset(path);
|
|
494
|
+
var profile = ScriptableObject.CreateInstance(profileType);
|
|
495
|
+
AssetDatabase.CreateAsset(profile, path);
|
|
496
|
+
var volume = go.GetComponent(Type.GetType(string.Format(Rendering, "Volume"))) ?? go.AddComponent(Type.GetType(string.Format(Rendering, "Volume")));
|
|
497
|
+
var o = new SerializedObject(volume);
|
|
498
|
+
o.FindProperty("sharedProfile").objectReferenceValue = profile;
|
|
499
|
+
o.FindProperty("m_IsGlobal").boolValue = true;
|
|
500
|
+
o.ApplyModifiedPropertiesWithoutUndo();
|
|
501
|
+
Profiles[go] = profile;
|
|
502
|
+
return profile;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
static void Set(SerializedObject o, string name, Action<SerializedProperty> value)
|
|
506
|
+
{
|
|
507
|
+
var parameter = o.FindProperty(name);
|
|
508
|
+
parameter.FindPropertyRelative("m_OverrideState").boolValue = true;
|
|
509
|
+
value(parameter.FindPropertyRelative("m_Value"));
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
395
513
|
/** Set the fields of a node's game components, walking the data and the built objects together. */
|
|
396
514
|
static void Wire(Dictionary<string, object> n, GameObject go, GameObject root)
|
|
397
515
|
{
|