Probably an asset or similar. Else it’s like putting a mesh in a component, eh?
1 Like
I see, thanks for your response.
Will put them in client side.
Maybe inform of a j3o file (as string in User Data) to be able to load it with asset manager out of the box. Or maybe as a plain text file with a specific loader registered in asset manager.
Paul I managed to make it work with a custom loader.
I registered a TweenLoader in asset manager
public class TweenLoader implements AssetLoader {
private static Gson gson;
static {
gson = new GsonBuilder()
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(TweenBuilder.class, "cType")
.registerSubtype(SequenceTweenBuilder.class)
.registerSubtype(ParallelTweenBuilder.class)
.registerSubtype(AnimTweenBuilder.class)
.registerSubtype(SoundTweenBuilder.class)
.registerSubtype(DelayTweenBuilder.class)
.registerSubtype(StretchTweenBuilder.class))
.create();
}
public static Gson getGson() {
return gson;
}
@Override
public Object load(AssetInfo assetInfo) throws IOException {
return loadFromStream(assetInfo, assetInfo.openStream());
}
private Object loadFromStream(AssetInfo assetInfo, InputStream stream) throws IOException {
try {
return gson.fromJson(new JsonReader(new InputStreamReader(stream)), TweenBuilder.class);
} catch (Exception e) {
throw new AssetLoadException("An error occurred loading tween " + assetInfo.getKey().getName(), e);
} finally {
stream.close();
}
}
}
now I save it like this in the editor :
try (FileWriter writer = new FileWriter(filePath)) {
TweenLoader.getGson().toJson(tween.getModel(), TweenBuilder.class, writer);
} catch (IOException ex) {
getState(OptionPanelState.class, true).showError("Error Saving !", ex);
}
and here is an example TweenBuilder exporeted to a file “test.tween”.
//
{"cType":"SequenceTweenBuilder","delegates":[{"cType":"DelayTweenBuilder","length":0.0},{"cType":"SoundTweenBuilder","dataType":"Stream","volume":1.0,"refDistance":10.0,"maxDistance":200.0,"loop":false,"positional":true,"directional":false,"reverbEnabled":false,"innerAngle":360.0,"outerAngle":360.0,"instanced":false,"velocityFromTranslation":false,"length":0.0}],"length":0.0}
//
Now after call to build() method of this TweenBuilder at runtime, it will create a Sequence tween consists of a Delay tween and a CallMethod tween which calls “play” method on an AudioNode.