1 /* 2 Inochi2D Mesh Effects 3 4 Copyright © 2020-2025, Inochi2D Project 5 Distributed under the 2-Clause BSD License, see LICENSE file. 6 7 Authors: Luna Nielsen 8 */ 9 module inochi2d.effect; 10 import inochi2d.core.math.deform; 11 import inochi2d.nodes.visual.part; 12 import inochi2d.core; 13 import inochi2d.common; 14 import inp.format; 15 import numem; 16 17 /** 18 The public effect registry. 19 */ 20 __gshared TypeRegistry!(MeshEffect, Part) in_effect_registry; 21 22 /** 23 Base class of effects that modify meshes. 24 */ 25 @TypeId("MeshEffect", 0x0000) 26 class MeshEffect : NuRefCounted, IDeserializable!ModelState { 27 private: 28 @nogc: 29 Part parent_; 30 31 protected: 32 33 /** 34 Serializes this MeshEffect to a DataNode. 35 36 Params: 37 object = The DataNode to serialize to. 38 */ 39 void onSerialize(ref DataNode object) { 40 object["type"] = in_effect_registry.lookup(this).sid; 41 } 42 43 /** 44 Deserializes this node from a DataNode. 45 46 Params: 47 object = The DataNode to deserialize from. 48 state = The state of the deserializer. 49 */ 50 void onDeserialize(ref DataNode object, ref ModelState state) { 51 } 52 53 /** 54 Called when the Effect is to be finalized during loading. 55 56 Params: 57 state = The state of the deserializer. 58 */ 59 void onFinalize(ref ModelState state) @nogc { 60 } 61 62 /** 63 Called after the full node update cycle. 64 65 Params: 66 drawList = The drawlist for the active scene. 67 */ 68 void onApply(DrawList drawList) { 69 } 70 71 public: 72 73 /** 74 The target of the effect. 75 */ 76 @property Part parent() => parent_; 77 78 /** 79 Constructs a new mesh effect. 80 81 Params: 82 parent = The parent of the mesh effect. 83 */ 84 this(Part parent) { 85 this.parent_ = parent; 86 } 87 88 /** 89 Serializes this mesh effect to a DataNode. 90 91 Params: 92 object = The DataNode to serialize to. 93 */ 94 final void serialize(ref DataNode object) @nogc { 95 object = DataNode.createObject(); 96 this.onSerialize(object); 97 } 98 99 /** 100 Deserializes this mesh effect from a DataNode. 101 102 Params: 103 object = The DataNode to deserialize from. 104 state = The state of the deserializer. 105 */ 106 final void deserialize(ref DataNode object, ref ModelState state) @nogc { 107 this.onDeserialize(object, state); 108 } 109 110 /** 111 Finalizes this mesh effect. 112 113 Params: 114 state = The state of the deserializer. 115 */ 116 final void finalize(ref ModelState state) @nogc { 117 this.onFinalize(state); 118 } 119 120 /** 121 Applies the late mesh effect, should be called after all of the 122 normal node updates have completed. 123 124 Params: 125 drawList = The drawlist for the active scene. 126 */ 127 final void apply(DrawList drawList) { 128 this.onApply(drawList); 129 } 130 } 131 132 mixin Register!(MeshEffect, in_effect_registry);