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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.base;
\r
13 import javax.vecmath.AxisAngle4d;
\r
14 import javax.vecmath.Tuple3d;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.layer0.utils.IEntity;
\r
18 import org.simantics.proconf.g3d.Resources;
\r
21 * Set of methods that make scene-graph handling easier.
\r
24 * @author Marko Luukkainen <Marko.Luukkainen@vtt.fi>
\r
27 public class G3DAPI {
\r
30 public static void setWorldPosition(IEntity node, Tuple3d position) {
\r
31 G3DTools.setTuple3(node.getSingleRelatedObject(Resources.g3dResource.HasWorldPosition), position);
\r
32 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
33 G3DTools.propagateWorldTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
36 public static void setLocalPosition(IEntity node, Tuple3d position) {
\r
37 G3DTools.setTuple3(node.getSingleRelatedObject(Resources.g3dResource.HasLocalPosition), position);
\r
38 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
39 G3DTools.propagateLocalTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
43 public static void setWorldOrientation(IEntity node, AxisAngle4d orientation) {
\r
44 G3DTools.setOrientation(node.getSingleRelatedObject(Resources.g3dResource.HasWorldOrientation), orientation);
\r
45 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
46 G3DTools.propagateWorldTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
50 public static void setLocalOrientation(IEntity node, AxisAngle4d orientation) {
\r
51 G3DTools.setOrientation(node.getSingleRelatedObject(Resources.g3dResource.HasLocalOrientation), orientation);
\r
52 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
53 G3DTools.propagateLocalTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
58 public static void setWorldTransformation(IEntity node, Tuple3d position, AxisAngle4d orientation) {
\r
59 G3DTools.setTuple3(node.getSingleRelatedObject(Resources.g3dResource.HasWorldPosition), position);
\r
60 G3DTools.setOrientation(node.getSingleRelatedObject(Resources.g3dResource.HasWorldOrientation), orientation);
\r
61 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
62 G3DTools.propagateWorldTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
66 public static void setLocalTransformation(IEntity node, Tuple3d position, AxisAngle4d orientation) {
\r
67 G3DTools.setTuple3(node.getSingleRelatedObject(Resources.g3dResource.HasLocalPosition), position);
\r
68 G3DTools.setOrientation(node.getSingleRelatedObject(Resources.g3dResource.HasLocalOrientation), orientation);
\r
69 //G3DTools.transformationUpdate(node.getGraph(), node.getResource());
\r
70 G3DTools.propagateLocalTransformChange(node.getSingleRelatedObject(Resources.g3dResource.HasParent), node);
\r
73 public static void addNodeWorld(IEntity parent, IEntity node) {
\r
74 parent.addStatement(Resources.g3dResource.HasChild, node);
\r
75 G3DTools.propagateWorldTransformChange(parent,node);
\r
78 public static void addNodeLocal(IEntity parent, IEntity node) {
\r
79 parent.addStatement(Resources.g3dResource.HasChild, node);
\r
80 G3DTools.propagateLocalTransformChange(parent,node);
\r
83 public static void addNodeWorld(IEntity parent, Resource relation, IEntity node) {
\r
84 assert(parent.getGraph().isSubrelationOf(relation, Resources.g3dResource.HasChild));
\r
85 parent.addStatement(relation, node);
\r
86 G3DTools.propagateWorldTransformChange(parent,node);
\r
89 public static void addNodeLocal(IEntity parent, Resource relation, IEntity node) {
\r
90 assert(parent.getGraph().isSubrelationOf(relation, Resources.g3dResource.HasChild));
\r
91 parent.addStatement(relation, node);
\r
92 G3DTools.propagateLocalTransformChange(parent,node);
\r
95 public static void removeNode(IEntity node) {
\r
96 node.removeRelatedStatements(Resources.g3dResource.HasParent);
\r
99 public static void moveNode(IEntity node, IEntity newParent) {
\r
100 node.removeRelatedStatements(Resources.g3dResource.HasParent);
\r
101 newParent.addStatement(Resources.g3dResource.HasChild, node);
\r
102 G3DTools.propagateWorldTransformChange(newParent,node);
\r