/******************************************************************************* * Copyright (c) 2007- VTT Technical Research Centre of Finland. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.proconf.g3d.shapeeditor.actions; import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.FileDialog; import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase; import org.simantics.proconf.g3d.occ.geometry.OccTriangulator; import com.jme.renderer.ColorRGBA; import com.jme.scene.Geometry; import com.jme.scene.state.MaterialState; public class LoadFileAction extends Action { private ThreeDimensionalEditorBase editor; public LoadFileAction(ThreeDimensionalEditorBase editor) { super("Load file"); this.editor = editor; } public void run() { FileDialog loadDialog = new FileDialog(editor.getRenderingComposite().getShell(), SWT.OPEN); String exts[] = { "*.stp;*.step", "*.iges", "*.brep", "*.ply" }; //$NON-NLS-1$ String names[] = { "STEP (AP214/AP203)", "IGES", "BREP", "PLY" }; //$NON-NLS-1$ loadDialog.setFilterNames(names); loadDialog.setFilterExtensions(exts); loadDialog.setText("Load model"); String filename = loadDialog.open(); if (filename != null) { Geometry g = OccTriangulator.getGeometryFromFile(filename)[0]; MaterialState ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState(); ms.setAmbient(new ColorRGBA(0.f,0.f,0.f,0.f)); ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f)); ms.setShininess(128.f); ms.setDiffuse(new ColorRGBA(0.8f,0.8f,0.8f,0.f)); ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,0.f)); ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK); if (g.getColorBuffer(0) != null) { ms.setColorMaterial(MaterialState.CM_DIFFUSE); } g.setRenderState(ms); editor.getRenderingComponent().getShadowRoot().attachChild(g); // mo.setGeometry(mesh, filename); // xithComposite.getScene().compile(); } } }