Search in sources :

Example 1 with Modifier

use of org.sunflow.core.Modifier in project joons-renderer by joonhyublee.

the class SunflowAPI method modifier.

@Override
public final void modifier(String name, String modifierType) {
    if (!isIncremental(modifierType)) {
        // we are declaring a shader for the first time
        if (renderObjects.has(name)) {
            UI.printError(Module.API, "Unable to declare modifier \"%s\", name is already in use", name);
            parameterList.clear(true);
            return;
        }
        Modifier modifier = PluginRegistry.modifierPlugins.createObject(modifierType);
        if (modifier == null) {
            UI.printError(Module.API, "Unable to create modifier of type \"%s\"", modifierType);
            return;
        }
        renderObjects.put(name, modifier);
    }
    // update existing shader (only if it is valid)
    if (lookupModifier(name) != null) {
        update(name);
    } else {
        UI.printError(Module.API, "Unable to update modifier \"%s\" - modifier object was not found", name);
        parameterList.clear(true);
    }
}
Also used : Modifier(org.sunflow.core.Modifier)

Example 2 with Modifier

use of org.sunflow.core.Modifier in project joons-renderer by joonhyublee.

the class RenderObjectMap method remove.

final void remove(String name) {
    RenderObjectHandle obj = renderObjects.get(name);
    if (obj == null) {
        UI.printWarning(Module.API, "Unable to remove \"%s\" - object was not defined yet");
        return;
    }
    UI.printDetailed(Module.API, "Removing object \"%s\"", name);
    renderObjects.remove(name);
    // references to the old object still around
    switch(obj.type) {
        case SHADER:
            Shader s = obj.getShader();
            for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                Instance i = e.getValue().getInstance();
                if (i != null) {
                    UI.printWarning(Module.API, "Removing shader \"%s\" from instance \"%s\"", name, e.getKey());
                    i.removeShader(s);
                }
            }
            break;
        case MODIFIER:
            Modifier m = obj.getModifier();
            for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                Instance i = e.getValue().getInstance();
                if (i != null) {
                    UI.printWarning(Module.API, "Removing modifier \"%s\" from instance \"%s\"", name, e.getKey());
                    i.removeModifier(m);
                }
            }
            break;
        case GEOMETRY:
            {
                Geometry g = obj.getGeometry();
                for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
                    Instance i = e.getValue().getInstance();
                    if (i != null && i.hasGeometry(g)) {
                        UI.printWarning(Module.API, "Removing instance \"%s\" because it referenced geometry \"%s\"", e.getKey(), name);
                        remove(e.getKey());
                    }
                }
                break;
            }
        case INSTANCE:
            rebuildInstanceList = true;
            break;
        case LIGHT:
            rebuildLightList = true;
            break;
        default:
            // no dependencies
            break;
    }
}
Also used : Geometry(org.sunflow.core.Geometry) Instance(org.sunflow.core.Instance) Shader(org.sunflow.core.Shader) FastHashMap(org.sunflow.util.FastHashMap) Modifier(org.sunflow.core.Modifier)

Aggregations

Modifier (org.sunflow.core.Modifier)2 Geometry (org.sunflow.core.Geometry)1 Instance (org.sunflow.core.Instance)1 Shader (org.sunflow.core.Shader)1 FastHashMap (org.sunflow.util.FastHashMap)1