Change origin of node in SceneKit Interface Builder - interface-builder

Does anyone know how to change the origin of a node in SceneKit Interface Builder? The origin is incorrect, but moving it simply moves the model, I want to move the origin so it's in the middle of the object :-/
Maybe I need to re-export my model with a different origin?

Reposition the node's pivot. For example,
truckNode.pivot = SCNMatrix4MakeTranslation(13.4, 12.9, 28.9)
You can also change rotation of the pivot but it appears you are interested in just the translational aspects which the above example satisfies.
Another option is to make your node a child of an otherwise empty "container node". Reposition your node within the container and then do all subsequent translations and rotations on the container node.
Another option using Interface Builder. Select your dae file. At the bottom of the editor window, on the left, is a square button with a bar on its left. Click it to open the Scene Graph. This will show a hierarchical list of the nodes in your file. In the Utilities panel to the right in your Xcode window, select the "box" icon. You can adjust a nodes position numerically there. You can also drag its axes directly in the editor. But this will not change the pivot which I think is what you want to do. You may have to create a new node to act as a container as mentioned above. This can be done by right-clicking on a node in the Scene Graph to bring up a menu. In my opinion, setting the pivot in code is easier. Details below.
BTW, you can get the names of the nodes in your dae scene from the Scene Graph in this editor. Here's how you access dae nodes in code:
guard let theTruck = SCNScene(named: "myTruck") else {
print("Couldn't find molecule in dictionary (myTruck)")
return }
let truck = theTruck.rootNode.childNodeWithName("truckBase", recursively: true)!
truck.pivot = SCNMatrix4MakeTranslation(12.0, 0, 8.0)
In this example: "myTruck" is the name of your dae file without the dae suffix. "truckBase" is the name of your root node within the dae file (you can change the name in the editor Scene Graph if desired). "truck" is a new node to which you've assigned the root node of your file. Manipulate it just as you would, and instead of, the root node of your dae. "theTruck" is a temporary holder for the dae SCNScene, used just to access the nodes within. You can access any other nodes in your dae this same way allowing you to manipulate them in code.

Related

How to render only visible nodes inside a ScrollPane?

I'm using JavaFX to show thousands of nodes inside a ScrollPane. It gets laggy on nodes more than about 50. I'm adding each node by pane.getChilderen.add(myNewNode); and then move them to a specific position on the pane. How to make a pane to only render visible items to optimize the performance? Thanks.

How to select a shape in a subscene to allow me to make transformations

I currently am working on a program in javafx that asks the user for radius and height of a cylinder and once the user hits add, it creates a cylinder in the subscene. I was wondering how I can combine the setonmouseclicked event handler with the cylinder so that way I can choose that one cylinder and make edits like scaling it, rotating it, etc. and then i can go to the next shape and click on that one and then i can do stuff like scale, rotate, etc to the next one. Currently this is what happens when i ask a user and they add the cylinder.
Button addCyl=new Button("Add Cylinder");
addCyl.setOnAction(event -> {
String cylRadius=cylRadiusInput.getText();
String cylHeight=cylHeightInput.getText();
Double Radius=Double.parseDouble(cylRadius);
Double Height=Double.parseDouble(cylHeight);
Cylinder cylinder=new Cylinder(Radius, Height);
shapeGroup.getChildren().add(cylinder);
});
How to pick a node
"how do i differentiate between which cylinder im clicking on so i can make changes to that specific one?"
You don't, the JavaFX node picking implementation will do that for you. When you set a click handler on an object, it will be invoked when the object is clicked on, so when it is invoked, you know that the user has clicked on the object.
How to save a selection
When you create the shape, create a click handler for it, and, when the node is clicked, set a field for the selected node.
private Group shapeGroup = new Group():
private Cylinder selectedNode;
// omitted ... add shapeGroup to sub-scene
private void addNode() {
Cylinder cylinder = new Cylinder(radius, height);
cylinder.setOnMouseClicked(e -> {
selectedNode = cylinder;
});
shapeGroup.getChildren().add(cylinder);
}
How to modify a selected item
To define what happens you want to take an action on the selected node, say change the radius, then you can do something like below:
private Slider radius = new Slider(10, 100, 20);
// omitted ... add radius control to scene
radius.valueProperty().addListener(
(observable, oldValue, newValue) -> {
if (selectedNode != null) {
selectedNode.setRadius(newValue);
}
}
);
How to set values from a selected node to your controls
If you wish, when a node is selected, you can set the value of your controls to the current value for the selected node, e.g.
cylinder.setOnMouseClicked(e -> {
selectedNode = cylinder;
radius.setValue(selectedNode.getRadius());
});
Sample node selection app
An example of the concepts discussed here is demoed in the following sample app:
JavaFX application demoing placing text in adjustable boxes.
Even though the demo example is in 2D, the concepts for node selection and subsequent modification of item properties by controls are no different for 2D and 3D.
How to handle multiple selections
If you wish to add multiple selection where multiple nodes may be selected at once, then it is a bit more complex. You can use some of the concepts defined in the answers below (linked question is for 2D, but 3D isn't really different in this regards).
How to implement selection of Nodes in JavaFX
What to do about depth sorting and obscured nodes
Because it is 3D, the objects can have z-depth, and are subject to depth sorting. If one object is behind another object, to allow the obscured object to be selected by mouse, you will need to have a mechanism to allow the user to move the obscuring objects out of the way (e.g. by selecting and dragging them to move them), or to rotate the scene to another viewpoint where the object the user wishes to click is no longer obscured (info on how to accomplish these kind of things is out of scope for this answer).
Getting detailed pick info
If you needed more info about the thing being picked, e.g. the point (in 3D space) on the node which was picked, or what face or texture co-ordinate of the node was picked then you can use the pickResult API. A tutorial for this is provided:
https://docs.oracle.com/javase/8/javafx/graphics-tutorial/picking.htm
However, for your purposes, a simple click handler for the node which does not query the pick result is all that is really needed.

Is there a way to add multiple properties in the Unity 3d animation window at once?

In Unity you can animate an object (such as a character) with the animation window:
And you can select properties of the object that you want to animate:
My problem is that it seems you can only add a single property at a time and then the whole list closes:
This causes a big problem when you want to animate every part of a full human (or any type of complex) 3d model:
My Question: Is there some way I can add more than one property at the same time? Or atleast not have the window of properties close, that way I can just keep choosing them?
Worth mentioning as well that if you right click on the transform instead of hitting the plus sign you can just add an entire group of transforms and the menu does not close. Should speed things up
The animation window will close after adding the property but their is a way to do this . Open animation window and inspector in separate tabs so that both can be seen at same time and animation must be in recording mode . After that select your game object in hirarchy and you can directly change its properties from inspector for each selected frame for example you can set position rotation and scale directly from inspector and this will make your animation in a fly :) Reference to unity documentation http://docs.unity3d.com/Manual/animeditor-MultipleParts.html
Yes! I've tested this method on Unity 2020.3.29f1, but it may work in earlier versions too.
In your hierarchy tab, select which bones you want to add properties for*. If you want to include all bones, select the parent bone and right click -> Select Children.
In your inspector tab, go to the Transform component and right click on Position, then select Add Key
Repeat step 2 for Rotation and Scale, if desired.
*: If you want to select multiple bones but not every bone, you can expand your list of bones and the use shift-click and ctrl-click (cmd-click) to select various bones.

How to hide outer bounded parent rectangle in GEF figure

I am trying to create a circle or an ellipse in GEF framework. We are setting constraints/bounds as a rectangle within which the circle/ellipse sits.
My problem is that I am not able to hide/suppress outer Rectangle when I do drag drop or I just click on the circle. Is there any way we can remove this outer Rectangle ? any tip idea would help. thanks
This rectangle is created by the NonResizableEditPolicy (or ResizableEditPolicy if your figure is resizable). This policy is added automatically to children of some layout policies, for example children of ConstrainedLayoutEditPolicy. What you need to do is find which layout policy you are using in your container, and override it to use a different edit policy to decorate the children of the container. This can be done by overriding the NonResizableEditPolicy (or ResizableEditPolicy) and then modify how this policy provides feedback when the Figure is selected, clicked on, etc.

Swap children's depth

I am using canvas and createjs. I have a container that has an eventListener attached to it so that any child in that container can be selected. When a child is selected I can drag it around on the stage but it is relative to its index so it is above some children and below others. I would like to move the above child to the top index. In flash I was able to swap the depth of that child and I was wondering if there is something similar in Javascript?
Thx.
All you gotta do is:
yourContainer.addChild(selectedChild);
this will pull your object to the top of your display list.

Resources