Rendertarget is needed to generate the preview image for model/material… However, it seems that I need to wait for the next frame to get the texture ready. Is there a way to get the render result immediately? (Maybe engine->Update/engine->Render will work, which I haven’t tryied. But they cannot be called from script) If so, we could add such a function to the View3D.
Edit: BTW, Constructing a Scene object in ResourceBackgroundLoaded event handler will result addref related crash which is very strange…
// called from HandleResourceBackgroundLoaded
Texture@ TakePhoto(Model@ model)
{
Scene@ previewScene = Scene("previewScene"); // crash happens, I cannot create Scene here
// this can work, previewScenes are pre-created in initialization phase
//Scene@ previewScene = previewScenes[scene_index++];
// ...
}
/// Template function for registering a named constructor for a class derived from Object.
template <class T> void RegisterNamedObjectConstructor(asIScriptEngine* engine, const char* className)
{
String declFactoryWithName(String(className) + "@+ f(const String&in)");
engine->RegisterObjectBehaviour(className, asBEHAVE_FACTORY, declFactoryWithName.CString(), asFUNCTION(ConstructNamedObject<T>), asCALL_CDECL);
}