<?eclipse version="3.2"?>\r
<plugin>\r
<extension-point id="geometry" name="Geometry" schema="schema/geometry.exsd"/>\r
+ <extension-point id="appearance" name="Appearance" schema="schema/appearance.exsd"/>\r
<extension\r
point="org.eclipse.ui.preferencePages">\r
<page\r
type="org.eclipse.jface.viewers.IStructuredSelection">\r
</propertyTester>\r
</extension>\r
+ <extension\r
+ point="org.simantics.proconf.g3d.appearance">\r
+ <Appearance\r
+ class="org.simantics.proconf.g3d.base.DefaultAppearanceProvider"\r
+ id="org.simantics.proconf.g3d.Appearance1">\r
+ </Appearance>\r
+ </extension>\r
</plugin>\r
--- /dev/null
+<?xml version='1.0' encoding='UTF-8'?>\r
+<!-- Schema file written by PDE -->\r
+<schema targetNamespace="org.simantics.proconf.g3d" xmlns="http://www.w3.org/2001/XMLSchema">\r
+<annotation>\r
+ <appinfo>\r
+ <meta.schema plugin="org.simantics.proconf.g3d" id="appearance" name="appearance"/>\r
+ </appinfo>\r
+ <documentation>\r
+ [Enter description of this extension point.]\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <element name="extension">\r
+ <annotation>\r
+ <appinfo>\r
+ <meta.element />\r
+ </appinfo>\r
+ </annotation>\r
+ <complexType>\r
+ <sequence>\r
+ <element ref="Appearance" minOccurs="0" maxOccurs="unbounded"/>\r
+ </sequence>\r
+ <attribute name="point" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="id" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="name" type="string">\r
+ <annotation>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ <appinfo>\r
+ <meta.attribute translatable="true"/>\r
+ </appinfo>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <element name="Appearance">\r
+ <complexType>\r
+ <attribute name="id" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ </annotation>\r
+ </attribute>\r
+ <attribute name="class" type="string" use="required">\r
+ <annotation>\r
+ <documentation>\r
+ \r
+ </documentation>\r
+ <appinfo>\r
+ <meta.attribute kind="java" basedOn=":org.simantics.proconf.g3d.base.AppearanceProvider"/>\r
+ </appinfo>\r
+ </annotation>\r
+ </attribute>\r
+ </complexType>\r
+ </element>\r
+\r
+ <annotation>\r
+ <appinfo>\r
+ <meta.section type="since"/>\r
+ </appinfo>\r
+ <documentation>\r
+ [Enter the first release in which this extension point appears.]\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appinfo>\r
+ <meta.section type="examples"/>\r
+ </appinfo>\r
+ <documentation>\r
+ [Enter extension point usage example here.]\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appinfo>\r
+ <meta.section type="apiinfo"/>\r
+ </appinfo>\r
+ <documentation>\r
+ [Enter API information here.]\r
+ </documentation>\r
+ </annotation>\r
+\r
+ <annotation>\r
+ <appinfo>\r
+ <meta.section type="implementation"/>\r
+ </appinfo>\r
+ <documentation>\r
+ [Enter information about supplied implementation of this extension point.]\r
+ </documentation>\r
+ </annotation>\r
+\r
+\r
+</schema>\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.proconf.g3d.base;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.layer0.utils.IEntity;\r
+\r
+import com.jme.renderer.Renderer;\r
+import com.jme.scene.state.RenderState;\r
+\r
+\r
+/**\r
+ * Interface for Appearance / Material\r
+ * \r
+ * \r
+ * @author Marko Luukkainen\r
+ *\r
+ */\r
+public interface AppearanceProvider {\r
+ \r
+ /**\r
+ * Used to check if GeometryProvider can generate mesh\r
+ * @param instance\r
+ * @return\r
+ */\r
+ public boolean canHandle(IEntity instance);\r
+ \r
+ /**\r
+ * Generates mesh\r
+ * @param instance\r
+ * @param transform\r
+ * @return\r
+ */\r
+ public Collection<RenderState> getAppearanceFromResource(IEntity instance, Renderer renderer);\r
+ \r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.proconf.g3d.base;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.eclipse.core.runtime.CoreException;\r
+import org.eclipse.core.runtime.IConfigurationElement;\r
+import org.eclipse.core.runtime.IExtension;\r
+import org.eclipse.core.runtime.IExtensionPoint;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.dynamichelpers.ExtensionTracker;\r
+import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;\r
+import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;\r
+import org.eclipse.core.runtime.dynamichelpers.IFilter;\r
+import org.simantics.db.Resource;\r
+import org.simantics.layer0.utils.IEntity;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+\r
+import com.jme.renderer.Renderer;\r
+import com.jme.scene.state.RenderState;\r
+\r
+public class AppearanceProviderRegistry implements IExtensionChangeHandler {\r
+ private static AppearanceProviderRegistry instance;\r
+ //public final static String ELEMENT_NAME = "Appearance";\r
+ public final static String NAMESPACE = "org.simantics.proconf.g3d";\r
+ public final static String EP_NAME = "appearance";\r
+ \r
+ private ExtensionTracker tracker;\r
+ \r
+ private List<AppearanceProviderExtension> extensions = new ArrayList<AppearanceProviderExtension>();\r
+ private Map<Resource,AppearanceProvider> providers;\r
+ \r
+ private AppearanceProviderRegistry() {\r
+ providers = new HashMap<Resource,AppearanceProvider>();\r
+ \r
+ tracker = new ExtensionTracker();\r
+ \r
+ IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(NAMESPACE,EP_NAME);\r
+ loadExtensions(ep.getConfigurationElements());\r
+ \r
+ IFilter filter = ExtensionTracker.createExtensionPointFilter(ep);\r
+ tracker.registerHandler(this, filter);\r
+ }\r
+ \r
+ private void close() {\r
+ tracker.close();\r
+ tracker = null;\r
+ extensions = new ArrayList<AppearanceProviderExtension>();\r
+ }\r
+ \r
+ public static synchronized AppearanceProviderRegistry getInstance() {\r
+ if (instance==null) instance = new AppearanceProviderRegistry();\r
+ return instance;\r
+ }\r
+ \r
+ public static synchronized void dispose() {\r
+ if (instance != null) {\r
+ instance.close();\r
+ instance = null;\r
+ } \r
+ }\r
+ \r
+ public synchronized List<AppearanceProviderExtension> getExtensions() {\r
+ return Collections.unmodifiableList(extensions);\r
+ }\r
+ \r
+ private synchronized void loadExtensions(IConfigurationElement[] elements) {\r
+ for (IConfigurationElement el : elements) {\r
+ String id = el.getAttribute("id");\r
+ try {\r
+ Object o = el.createExecutableExtension("class");\r
+ AppearanceProviderExtension ext = new AppearanceProviderExtension(id,(AppearanceProvider)o);\r
+ tracker.registerObject(el.getDeclaringExtension(), ext, IExtensionTracker.REF_STRONG);\r
+ extensions.add(ext);\r
+ } catch (CoreException e) {\r
+ ErrorLogger.defaultLogError("Cannot create java interface for GeometryProvider " + id, e);\r
+ }\r
+ }\r
+ }\r
+ \r
+ private Map<Resource,AppearanceProvider> getProviderMap() {\r
+ return providers;\r
+ }\r
+ \r
+ public static Collection<RenderState> getAppearance(IEntity thing, Renderer renderer) {\r
+ AppearanceProvider provider = getAppearanceProvider(thing);\r
+ return provider.getAppearanceFromResource(thing, renderer);\r
+ }\r
+ \r
+ public static AppearanceProvider getAppearanceProvider(IEntity thing) {\r
+ Collection<IEntity> types = thing.getRelatedObjects(thing.getGraph().getBuiltins().InstanceOf);\r
+ \r
+ //Resource types[] = OntologyUtils.getTypes(resource);\r
+ for (IEntity t : types) {\r
+ AppearanceProvider provider = getInstance().getProviderMap().get(t.getResource());\r
+ if (provider == null) {\r
+ //for (Extension<GeometryProvider> e : getInstance().getExtensions()) {\r
+ for (AppearanceProviderExtension e : getInstance().getExtensions()) {\r
+ if (e.provider.canHandle(thing)) {\r
+ getInstance().getProviderMap().put(t.getResource(), e.provider);\r
+ return e.provider;\r
+ }\r
+ }\r
+ \r
+ } else {\r
+ return provider;\r
+ }\r
+ }\r
+ \r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public void addExtension(IExtensionTracker tracker, IExtension extension) {\r
+ loadExtensions(extension.getConfigurationElements());\r
+ }\r
+ \r
+ @Override\r
+ public synchronized void removeExtension(IExtension extension, Object[] objects) {\r
+ for (Object o : objects) {\r
+ AppearanceProviderExtension ext = (AppearanceProviderExtension) o;\r
+ tracker.unregisterObject(extension, ext);\r
+ extensions.remove(ext);\r
+ }\r
+ }\r
+ \r
+ public class AppearanceProviderExtension {\r
+ public String id;\r
+ public AppearanceProvider provider;\r
+ \r
+ public AppearanceProviderExtension(String id, AppearanceProvider provider) {\r
+ this.id = id;\r
+ this.provider = provider;\r
+ }\r
+ }\r
+}\r
import org.simantics.proconf.g3d.Resources;\r
import org.simantics.proconf.g3d.stubs.Appearance;\r
import org.simantics.proconf.g3d.stubs.Color;\r
-import org.simantics.proconf.g3d.stubs.G3DResource;\r
import org.simantics.proconf.g3d.stubs.ImageTexture;\r
import org.simantics.proconf.g3d.stubs.Material;\r
import org.simantics.proconf.g3d.stubs.MultiTexture;\r
--- /dev/null
+package org.simantics.proconf.g3d.base;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.layer0.utils.IEntity;\r
+import org.simantics.proconf.g3d.Resources;\r
+import org.simantics.proconf.g3d.stubs.Appearance;\r
+\r
+import com.jme.renderer.Renderer;\r
+import com.jme.scene.state.RenderState;\r
+\r
+public class DefaultAppearanceProvider implements AppearanceProvider {\r
+ \r
+ \r
+\r
+ @Override\r
+ public boolean canHandle(IEntity instance) {\r
+ return instance.hasStatement(Resources.g3dResource.HasAppearance);\r
+ }\r
+ \r
+ @Override\r
+ public Collection<RenderState> getAppearanceFromResource(IEntity instance, Renderer renderer) {\r
+ Collection<IEntity> appearanceResource;\r
+ if ((appearanceResource = instance.getRelatedObjects(Resources.g3dResource.HasAppearance)) != null && appearanceResource.size() > 0) {\r
+ return AppearanceTools.getAppearance(new Appearance(instance.getGraph(),appearanceResource.iterator().next().getResource()), renderer);\r
+ }\r
+ throw new RuntimeException("Given instance does not have Appearance definition!");\r
+ }\r
+}\r
\r
import com.jme.image.Image;\r
import com.jme.image.Texture;\r
-import com.jme.util.TextureManager;\r
\r
/**\r
* Caches resource based textures.\r
* TODO : either use shared context or use separate cache for each editor\r
* TODO : ShapeNode implementation won't use release texture yet\r
* TODO : Texture is released when reference count goes to zero; we probably want to wait for a while before texture is released because it might be used again.\r
+ * TODO : Support for other types of textures (not just pattern texture, preferably extensible interface)\r
* \r
* @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>\r
*\r
ImageTexture it = new ImageTexture(g,res);\r
org.simantics.image.stubs.Image pattern = it.getImage();\r
Image image = loadImage(g, pattern.getResource());\r
-// image.getData().rewind();\r
-// while (image.getData().hasRemaining())\r
-// image.getData().put((byte)(Math.random()*256.0 - 127.0));\r
+\r
if (image == null) {\r
return null;\r
}\r
t = new Texture();\r
t.setImage(image);\r
\r
- //t = TextureManager.loadTexture(image, Texture.MM_LINEAR, Texture.FM_LINEAR);\r
-// t.setImageLocation(res.toString());\r
-// URL url = FileLocator.find(com.jme.eclipse.Activator.getDefault().getBundle(),new Path("data/texture/clouds.png"),null);\r
-// t = TextureManager.loadTexture(url, Texture.MM_LINEAR, Texture.FM_LINEAR);\r
\r
t.setFilter(com.jme.image.Texture.FM_LINEAR);\r
t.setMipmapState(com.jme.image.Texture.MM_LINEAR);\r
return instance;\r
}\r
\r
- private static Image getImage(ImageData imageData) {\r
+ public static Image getImage(ImageData imageData) {\r
int width = imageData.width;\r
int height = imageData.height;\r
int type = 0;\r
import org.simantics.proconf.g3d.animation.ScalarInterpolator;\r
import org.simantics.proconf.g3d.animation.SlerpInterpolator;\r
import org.simantics.proconf.g3d.animation.TCBInterpolator;\r
+import org.simantics.proconf.g3d.base.AppearanceProvider;\r
+import org.simantics.proconf.g3d.base.AppearanceProviderRegistry;\r
import org.simantics.proconf.g3d.base.AppearanceTools;\r
import org.simantics.proconf.g3d.base.G3DTools;\r
import org.simantics.proconf.g3d.base.GeometryProvider;\r
\r
\r
G3DNode shape = getG3DNode(graph);\r
- if (renderStates == null)\r
+ //if (renderStates == null)\r
updateAppearance(shape);\r
\r
if (isVisible()) {\r
}\r
\r
protected void updateAppearance(IEntity shape) {\r
- Collection<IEntity> appearanceResource;\r
- if ((appearanceResource = shape.getRelatedObjects(Resources.g3dResource.HasAppearance)) != null && appearanceResource.size() > 0) {\r
- renderStates = AppearanceTools.getAppearance(new Appearance(shape.getGraph(),appearanceResource.iterator().next().getResource()), editor.getRenderingComponent().getDisplaySystem().getRenderer());\r
+ AppearanceProvider provider = AppearanceProviderRegistry.getAppearanceProvider(shape);\r
+ if (provider != null) {\r
+ renderStates = provider.getAppearanceFromResource(shape, editor.getRenderingComponent().getDisplaySystem().getRenderer());\r
} else {\r
renderStates = getMaterial();\r
}\r