]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/proconf/g3d/base/DefaultAppearanceProvider.java
a30359b6335be9b50342f893ed77821d70ed17cf
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / base / DefaultAppearanceProvider.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.base;\r
12 \r
13 import java.util.Collection;\r
14 \r
15 import org.simantics.layer0.utils.IEntity;\r
16 import org.simantics.proconf.g3d.Resources;\r
17 import org.simantics.proconf.g3d.stubs.Appearance;\r
18 \r
19 import com.jme.renderer.Renderer;\r
20 import com.jme.scene.state.RenderState;\r
21 \r
22 public class DefaultAppearanceProvider implements AppearanceProvider {\r
23         \r
24         \r
25 \r
26         @Override\r
27         public boolean canHandle(IEntity instance) {\r
28                 return instance.hasStatement(Resources.g3dResource.HasAppearance);\r
29         }\r
30         \r
31         @Override\r
32         public Collection<RenderState> getAppearanceFromResource(IEntity instance, Renderer renderer) {\r
33                 Collection<IEntity> appearanceResource;\r
34         if ((appearanceResource = instance.getRelatedObjects(Resources.g3dResource.HasAppearance)) != null && appearanceResource.size() > 0) {\r
35             return AppearanceTools.getAppearance(new Appearance(instance.getGraph(),appearanceResource.iterator().next().getResource()), renderer);\r
36         }\r
37         throw new RuntimeException("Given instance does not have Appearance definition!");\r
38         }\r
39 }\r