Obj File Model Not Anchoring Properly

6049
27
04-01-2021 01:52 PM
RobBever
New Contributor III

Using engine v100.6.0, since as far as I know the 3D rendering speed problem introduced in 100.7.0 and worse in 100.8.0 is not yet resolved.

I have a simple .obj file. I simplified it as much as possible to determine why I was getting the behavior I was getting. Here's the .obj file, I'll also attach:

 

# Cube.obj

g Cube

v -1 1 -1
v 1 1 -1
v 1 1 1
v -1 1 1
v -1 -1 -1
v 1 -1 -1
v 1 -1 1
v -1 -1 1

#top
f 1 4 3 2
#front
f 1 2 6 5
#right
f 2 3 7 6
#back
f 4 8 7 3
#left
f 1 5 8 4
#bottom
f 5 6 7 8

 

So just a 2-unit cube centered at 0, 0, 0. I know there's a simple cube that can be generated; I'm just trying to understand the engine's behavior w.r.t. .obj files so I can make my own .obj files dynamically later.

I'm trying to anchor it at the center. This does not appear to work, either by AnchorPositioner.Center or AnchorPosition.Origin.

It seems clear that both Center and Origin should work the same. Here I've added this .obj file to my scene with its AnchorPosition set to Origin; I've also added a text label "0" at the given point and also I have a cone with AnchorPosition.Top which has its top set to the same point. In this case, the SymbolSizeUnits are set to Meters, and width == height == depth.

RobBever_0-1617309308331.png

Obviously this is not correct. The origin is in the center of the cube. Here I'll try AnchorPosition.Center:

RobBever_1-1617309442889.png

This looks right, although I've had problems with this when the points aren't as regular as this. So that looks correct.

Now we'll try SymbolSizeUnits.Dips, AnchorPosition.Center:

RobBever_2-1617309530093.png

Now we're anchoring to the bottom again for some reason. This behavior is different for SymbolSizeUnits.Dips vs. SymbolSizeUnits.Meters, but shouldn't be.

Now I'll try SymbolSizeUnits.Meters, AnchorPosition.Origin:

RobBever_3-1617309644315.png

RobBever_4-1617309752113.png

This is anchored to the bottom too. It doesn't appear that I can do anything to actually anchor at the center in SymbolSizeUnits.Dips mode. It always appears to use AnchorPosition.Bottom instead.

Is there anything I can do differently to be able to anchor at the center?

It would be ideal if I could use AnchorPosition.Origin, since I can control that, but it doesn't appear to work in any of these cases. It appears to replace Origin with Bottom. Perhaps internally it translates .obj vertices so the bottom is placed at a y value of 0?

Also, can you describe the algorithm used to determine the centroid of the object? I was creating another object and it wasn't at all clear where the centroid was considered to be, and it was causing it to rotate the model away from the point I wanted it to center at.

I tried adding additional unused vertices to "balance" it so the center would be the right point, but it was unsuccessful.

Tags (3)
0 Kudos
27 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

For an upcoming release later this year we've made some improvements to the behavior of ModelSceneSymbol in relation to SymbolSizeUnits.DIPs

 

If you're interested in joining the preview program for the purposes of evaluating this change, please contact me at mbranscomb@esri.com.

 

Thanks 

0 Kudos
RobBever
New Contributor III

Sorry I missed your last message. I'd be interested in helping to test if it's not too involved, for example if you have a beta version of your samples application

I tested this in the latest ArcGISRuntime samples in version 100.13 and the problem is the same. I retried all the files I showed previously, and every problem I discussed is still here.

To quickly summarize (these are new examples from 100.13):

1. In Dips mode, nothing is anchored correctly. If you zoom in far enough, the model will always diverge from the actual point in some way. Here you see a Dips cube and a Meters sphere (anchor point is Center). The cube is sticking out the bottom of the sphere when it should be centered in the same place as the sphere.

RobBever_0-1644187382362.png

Here, the anchor point is Bottom, and you can clearly see that the model is not attached to the anchor point, which is given the same point as the Meters-based sphere:

RobBever_3-1644187598914.png

Here it's anchored to Top, and you can see daylight between the actual anchor point and the model:

RobBever_4-1644187763132.png

2. Origin and Bottom appear to be nearly the same in Dips and Meters modes. I have seen them diverge, but rarely, and Origin has nothing to do with the origin of the model under any circumstances in any model format I've tried (and I tried a lot of formats). Here's a cube which is centered at 0,0,0 in Dips:

RobBever_1-1644187482126.png

And here it is in Meters:

RobBever_2-1644187496058.png

Both are incorrect in the same way. No point of origin is respected in any of the tests I did, moving the origin around a cube model. The Origin anchor point definitely does not anchor at the origin, it's still similar to or the same as Bottom, and the Center is still using an algorithm that's difficult to figure out. It seems to be maybe a weighted average of face area, I think. Vertices that aren't part of a face are not considered, I know that much.

3. Much less important, but I can't do your SimpleMarkerSceneSymbols in Dips mode. It would be very nice to be able to create a cone, sphere or cube in Dips mode. I assume this is possible but was missed in the API or something.

Generally speaking the SimpleMarkerSceneSymbols make sense in terms of how they work (though I'm still confused about how Center is calculated). Here I plotted them in a similar way to the other models:

RobBever_5-1644189168514.png

Their anchor points seem to work as desired, generally speaking. Their Origin anchor points clearly work differently than all other loaded models, since they seem to actually be in the center of the models, and I haven't seen any other case where I could get that to happen. If I could get the same behavior for loaded models I'd be very happy, though I can't test their behavior in Dips mode.

4. Minor issue, I wish I could load models from a pack Uri. If it doesn't work for some reason, that's fine, it's just strange using Uris but not being able to do it the same as I would in XAML to load a local resource file, I have to write the file to disk and load it that way.

 

The runtime performance of 3D appears to be better in 100.13, but from a quick test it still seemed slower than in 100.6. I haven't benchmarked it though, and it definitely appears to be improved from other versions between 100.6 and 100.13.

I just realized I could orient my meshes vertically, since Top and Bottom are more consistent in their behavior, so I'm going to go try that, but it isn't a real solution for models that aren't symmetrical (since I don't know how the other axes are averaged), and even in Top and Bottom mode for Dips, the models don't really stay attached to the anchor point.

Let me know if you may be able to fix this or if you can at least tell me how the centers are calculated. I can give you the sample code and models I used to do this testing if it would help you, it's similar to what I already provided in this thread.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Thanks for the update and for re-testing. This issue is still in our backlog and we would like to resolve in a future release, but unfortunately the first candidate fix we considered caused a rendering regression on certain Android devices.

I've emailed you regarding the preview program.

Thanks

0 Kudos
RobBever
New Contributor III

Hey Michael, I didn't get a chance to test out the preview. Is the stuff from the preview in 200.0?

Looking at this in the latest 200.0, it seems the behavior has changed, which is mostly good, but I still don't see how I can use this consistently.

RobBever_0-1676667317086.png

This is better in that the top and bottom stay attached to the point now in DIPS mode:

RobBever_1-1676667357527.png

But the origin point is still not respected, which makes it basically impossible to put a non-symmetrical model where I want it, unless your algorithm happens to pick the center I want.

This is a cube from a .obj file where the origin is in the center. The sphere is centered on the anchor point, and the SceneSymbolAnchorPositions are, from left to right, Center, Origin, Bottom, Top:

RobBever_2-1676667443132.png

This is a cube where the origin is at one of the corners, same deal, SceneSymbolAnchorPositions are, from left to right, Center, Origin, Bottom, Top:

RobBever_3-1676667484935.png

Here's an arrow model:

RobBever_4-1676667534174.png

So it's not centered w.r.t. the front to the back, and I can't use the origin to set the center point, so I'm back to being stuck because I don't know what algorithm you use to decide what the "center," "top" and "bottom" of the shape are, and Origin seems to be the same as Bottom.

Even if I orient my model vertically, I still don't know how Bottom decides the anchor point from the model, so I'm not sure if I can get it to anchor where I want. For example, the arrow model has multiple points that would be at the lowest Y value; does it average them? If I make one point the very lowest point, will it consistently pick that point as the anchor point, or will it average it against other points?

Is there any intention to make the Origin SceneSymbolAnchorPosition use the actual origin point from the model? Origin would be by far the most useful of the four modes, and the only one that guarantees me that I can put the model where I want it.

0 Kudos
RobBever
New Contributor III

Here's an example of the problem. I modified my CubeEdge.obj file to have one highest point. So when I do Top as my SceneSymbolAnchorPosition, it looks like this:

RobBever_5-1676668323187.png

So I can't control where the anchor point will be. The Y value is set to the max Y value, but for the X and Z values the engine is doing some kind of average of the other points, and not using the topmost point as the actual anchor point. That means I have no direct control of where the anchor point actually is, since Origin doesn't respect the model's origin and is just Bottom.

I really hope you can make Origin respect the origin point of the model file. That would solve most of the problems I have with this.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi Rob,

Thanks for retesting. I'll discuss with the team and follow up. It's possible the same issue(s) as:

BUG-000152187 The anchor position of a symmetric 3D Collada model is not honored on the z-axis, when it is set to Origin.

BUG-000152190 The anchor position of an Asymmetric 3D Collada model is not honored on the X, Y, and Z-axis when it is set to 'Origin'.

 

Thanks

Mike

0 Kudos
RobBever
New Contributor III

I'm sure it's related. I haven't found any model format where the origin point is honored. I tried lots of formats, .obj, .dae, .fbx, etc.

Is there any model format where the origin is actually used when the anchor point is set to Origin? Even if it isn't the most convenient format like .obj, I might be able to work with it.

Also, would it be possible to load models from memory or from project resources? It's a real pain to have to write a model file out to disk just so the engine can read it back in again. Uris can do references to project resources or memory, but the ArcGIS engine doesn't support Uris of that kind, even though it takes in a Uri to read the model.

The way the anchoring works makes it impossible to know where anything will be anchored. At best I've had to rig up prefab models that I can dynamically modify where I've been able to trick the engine into anchoring where I wanted. If the model was, say, a building or a tank, there's no way to work with the unknown averaging algorithm in play. Anything that isn't symmetrical gets a set of anchor points that are, from the user's perspective, basically random and which he has no control over.

I've had users ask me to put an RF pattern 3D model into the scene, or the scan area of a camera, and I can't do it, because it would be asymmetrical, and while I can generate the model, I can't anchor it where it needs to be.

0 Kudos
RobBever
New Contributor III

Is there any hope of ever having a way to create 3D models in memory without using model files? I have lots of use cases for that, to the point where I rigged up a way to automatically build different colored .obj/.mtl files so they can be loaded in. But since I can't use a local Uri in memory, I have to write all of them to disk and load them that way.

Supporting a Uri to load data from memory and from project resources would be a great improvement, but even better would be some way for me to define a model in memory with the ArcGIS engine API, since that's what I really want to do.

0 Kudos