Java Code Examples for com.jme3.material.Material#getAdditionalRenderState()

The following examples show how to use com.jme3.material.Material#getAdditionalRenderState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Create collision plane.
 */
@FromAnyThread
private void createCollisionPlane() {

    final AssetManager assetManager = EditorUtil.getAssetManager();

    final Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    final RenderState renderState = material.getAdditionalRenderState();
    renderState.setFaceCullMode(RenderState.FaceCullMode.Off);
    renderState.setWireframe(true);

    final float size = 20000;

    final Geometry geometry = new Geometry("plane", new Quad(size, size));
    geometry.setMaterial(material);
    geometry.setLocalTranslation(-size / 2, -size / 2, 0);

    collisionPlane = new Node();
    collisionPlane.attachChild(geometry);
}
 
Example 2
Source File: MaterialUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update the first material to the second material.
 *
 * @param toUpdate the material for updating.
 * @param material the target material.
 */
@JmeThread
private static void updateTo(@NotNull Material toUpdate, @NotNull Material material) {

    var oldParams = new ArrayList<MatParam>(toUpdate.getParams());
    oldParams.forEach(matParam -> {
        var param = material.getParam(matParam.getName());
        if (param == null || param.getValue() == null) {
            toUpdate.clearParam(matParam.getName());
        }
    });

    var actualParams = material.getParams();
    actualParams.forEach(matParam -> {
        var varType = matParam.getVarType();
        var value = matParam.getValue();
        toUpdate.setParam(matParam.getName(), varType, value);
    });

    var additionalRenderState = toUpdate.getAdditionalRenderState();
    additionalRenderState.set(material.getAdditionalRenderState());
}
 
Example 3
Source File: MaterialUtils.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Migrate the material to second material.
 *
 * @param target the target migrating.
 * @param source the source material.
 */
@JmeThread
public static void migrateTo(@NotNull Material target, @NotNull Material source) {

    var materialDef = target.getMaterialDef();
    var actualParams = source.getParams();

    actualParams.forEach(matParam -> {

        var param = materialDef.getMaterialParam(matParam.getName());

        if (param == null || param.getVarType() != matParam.getVarType()) {
            return;
        }

        target.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
    });

    var additionalRenderState = target.getAdditionalRenderState();
    additionalRenderState.set(source.getAdditionalRenderState());

    target.setKey(source.getKey());
}
 
Example 4
Source File: TestIssue1125.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure materials during startup.
 */
private void configureMaterials() {
    quadMaterial = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    quadMaterial.setColor("Color", ColorRGBA.Green.clone());
    RenderState ars = quadMaterial.getAdditionalRenderState();
    ars.setWireframe(true);
}
 
Example 5
Source File: MaterialSettingsPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected @Nullable List<EditableProperty<?, ?>> getProperties(@NotNull final Object object) {

    if (!(object instanceof MaterialSettings) || object instanceof RootMaterialSettings) {
        return null;
    }

    final MaterialSettings settings = (MaterialSettings) object;
    final Material material = settings.getMaterial();

    if(object instanceof RenderSettings) {

        final RenderState renderState = material.getAdditionalRenderState();

        final List<EditableProperty<?, ?>> result = new ArrayList<>();
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_COLOR_WRITE, settings,
                sett -> renderState.isColorWrite(),
                (sett, property) -> renderState.setColorWrite(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_DEPTH_WRITE, settings,
                sett -> renderState.isDepthWrite(),
                (sett, property) -> renderState.setDepthWrite(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_DEPTH_TEST, settings,
                sett -> renderState.isDepthTest(),
                (sett, property) -> renderState.setDepthTest(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_WIREFRAME, settings,
                sett -> renderState.isWireframe(),
                (sett, property) -> renderState.setWireframe(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_FACE_CULL_MODE, settings,
                sett -> renderState.getFaceCullMode(),
                (sett, property) -> renderState.setFaceCullMode(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_MODE, settings,
                sett -> renderState.getBlendMode(),
                (sett, property) -> renderState.setBlendMode(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_EQUATION, settings,
                sett -> renderState.getBlendEquation(),
                (sett, property) -> renderState.setBlendEquation(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_EQUATION_ALPHA, settings,
                sett -> renderState.getBlendEquationAlpha(),
                (sett, property) -> renderState.setBlendEquationAlpha(property)));
        result.add(new SimpleProperty<>(FLOAT,  Messages.MATERIAL_RENDER_STATE_POLY_OFFSET_FACTOR, 0.1F, settings,
                sett -> renderState.getPolyOffsetFactor(),
                (sett, property) -> renderState.setPolyOffset(property, renderState.getPolyOffsetUnits())));
        result.add(new SimpleProperty<>(FLOAT,  Messages.MATERIAL_RENDER_STATE_POLY_OFFSET_UNITS, 0.1F, settings,
                sett -> renderState.getPolyOffsetUnits(),
                (sett, property) -> renderState.setPolyOffset(renderState.getPolyOffsetFactor(), property)));

        return result;
    }

    final MaterialDef materialDef = material.getMaterialDef();

    return materialDef.getMaterialParams()
            .stream()
            .filter(param -> filter(param, object))
            .sorted(MAT_PARAM_NAME_COMPARATOR)
            .map(param -> convert(param, material, settings))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}
 
Example 6
Source File: MaterialSerializer.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
/**
 * Serialize to string string.
 *
 * @param material the material
 * @return the string
 */
@FromAnyThread
public static @NotNull String serializeToString(@NotNull Material material) {

    var materialDef = material.getMaterialDef();
    var params = material.getParams();

    var builder = new StringBuilder();
    builder.append("Material MyMaterial : ").append(materialDef.getAssetName()).append(" {\n");
    builder.append("    MaterialParameters {\n");
    params.forEach(matParam -> addMaterialParameter(builder, matParam));
    builder.append("    }\n");
    builder.append("    AdditionalRenderState {\n");

    var renderState = material.getAdditionalRenderState();
    var blendMode = renderState.getBlendMode();
    var faceCullMode = renderState.getFaceCullMode();

    if (blendMode != RenderState.BlendMode.Off) {
        builder.append("      Blend ").append(blendMode.name()).append('\n');
    }

    if (faceCullMode != RenderState.FaceCullMode.Back) {
        builder.append("      FaceCull ").append(faceCullMode.name()).append('\n');
    }

    if (renderState.isWireframe()) builder.append("      Wireframe On\n");
    if (!renderState.isDepthTest()) builder.append("      DepthTest Off\n");
    if (!renderState.isDepthWrite()) builder.append("      DepthWrite Off\n");
    if (!renderState.isColorWrite()) builder.append("      ColorWrite Off\n");

    var polyOffsetFactor = renderState.getPolyOffsetFactor();
    var polyOffsetUnits = renderState.getPolyOffsetUnits();

    if (polyOffsetFactor != 0 || polyOffsetUnits != 0) {
        builder.append("      PolyOffset ")
                .append(polyOffsetFactor)
                .append(' ')
                .append(polyOffsetUnits)
                .append('\n');
    }

    builder.append("    }\n");
    builder.append("}");

    return builder.toString();
}