Author Topic: Objects close to the camera completely disappear  (Read 311 times)

Jan Drabner   «   on: July 04, 2012, 06:38:07 AM »
Hey,

I have the problem that objects that are close to the camera are disappearing completely. I know this happens because of the boundings, so I tried setting them to null.

Like this:
for each (var mesh:Pivot3D in _weapon.children)
{
  if (mesh is Mesh3D)
  {
    Mesh3D(mesh).bounds = null;
  }
}
_scene.addChild(_weapon);

However, the item still disappears when close to the camera. The "= null" line is definitely reached, but in the debugger the meshes seem to have the same boundings even AFTER I set them to null. Doesn't make any sense to me.

So how can I force objects to always be rendered, no matter their clipping/radius/etc.? Performance is not a problem, as this applies only to very few objects.

Jan Drabner   «   Reply #1 on: July 04, 2012, 06:47:02 AM »
Okay, it seems that the problem was that I was using this part of the code too late.

I am also changing/adding shaders on that _weapon object and change position/rotation, etc. Now when I do that shader/transformation stuff before removing the boundings, it doesn't work.

If I do the shader/transformation stuff after removing the boundings, it does work and isn't clipped any more.

Maybe that is a bug? or a feature? I'm not sure :D

Jan Drabner   «   Reply #2 on: July 04, 2012, 06:50:06 AM »
That was a false positive. Now it sometimes doesn't even appear when far away. What the heck? o.O

Here is the complete function:
public function KillAnimation(p_scene:Scene3D, p_weapon:Pivot3D, p_source:Avatar3D, p_target:Avatar3D)
        {
            _scene = p_scene;
            _weapon = p_weapon;
            _source = p_source;
            _target = p_target;
           
           
            // Remove bounding box for this one to disable clipping
            for each (var mesh:Pivot3D in _weapon.children)
            {
                if (mesh is Mesh3D)
                {
                    Mesh3D(mesh).bounds = null;
                }
            }
            _scene.addChild(_weapon);
           
            // Add specular & normal textures
                // Splash
            var texture :Texture3D = new Texture3D(new SplashSpec().bitmapData);
            var shader :Shader3D = Shader3D(Mesh3D(_weapon.getChildByName("splash_geometry1")).surfaces[0].material);
            shader.filters.push(new SpecularMapFilter(texture, 50, 6));
            shader.build();
            Mesh3D(_weapon.getChildByName("splash_geometry1")).surfaces[0].material = shader;
                // Hammer
            texture = new Texture3D(new HammerSpec().bitmapData);
            shader = Shader3D(Mesh3D(_weapon.getChildByName("hammer")).surfaces[0].material);
            shader.filters.push(new SpecularMapFilter(texture, 50, 1));
            texture = new Texture3D(new HammerNormal().bitmapData);
            shader.filters.push(new NormalMapFilter(texture));
            shader.build();
            Mesh3D(_weapon.getChildByName("hammer")).surfaces[0].material = shader;
           
            // Set orientation and position of weapon
            var posSource :Vector3D = p_source.getModel().getPosition();
            var posTarget :Vector3D = p_target.getModel().getPosition();
            var dir :Vector3D = Vector3DUtils.sub(posSource, posTarget);
            dir.y = 0;
            dir.z += 1.0;
            _weapon.setOrientation(dir.clone());
            dir.z -= 1.0;
            _weapon.setPosition(posTarget.x, posTarget.y, posTarget.z);
           
            // Set source position for best distance
            Vector3DUtils.setLength(dir, 5.5);
            posTarget = Vector3DUtils.add(posTarget, dir);
            p_source.moveTo(posTarget, true);
           
            // Disable movement
            _source.allowMovement(false);
            _target.allowMovement(false);
           
            // Start anim
            _weapon.children[0].addEventListener(Pivot3D.ANIMATION_COMPLETE_EVENT, handleF3DAnimComplete);
            _weapon.addLabel(new Label3D("hammer", 0, 32));
            _weapon.gotoAndPlay("hammer", 0, Pivot3D.ANIMATION_STOP_MODE);
}

Jan Drabner   «   Reply #3 on: July 04, 2012, 06:54:09 AM »
Could the problem be that the _weapon object is a clone() of one original object?

Ivan Vodopiviz   «   Reply #4 on: July 04, 2012, 10:30:56 AM »
It's a very weird issue... would it be possible for you to send us a minimal example showing this issue? You can send us stuff to info AT flare3d DOT com.

Thanks!



Jan Drabner   «   Reply #5 on: July 04, 2012, 11:19:40 AM »
I did find the issue. Well, more or less...

The problem is indeed that the _weapon object is a clone(). This is how the above class constructor is called:

var killAnim :KillAnimation = new KillAnimation(_scene, _killAnim.clone(), p_source, p_target);

_killAnim is a Pivot3D object that was loaded from an embedded *.f3d file. But that original _killAnim is never used anywhere except that one .clone() call.

If I instead load the f3d file every single time I want to use the animation, inside the KillAnimation class, (it is a full mesh with an animation, actually), and then do all that boundings removal, etc. it works and is always visible. So this must be a problem when using a clone(). Unfortunately I really can't load the whole mesh every time I want to use the animation.

As you can probably see, this whole process is a bit too complicated to strip down to a minimal example.

Jan Drabner   «   Reply #6 on: July 04, 2012, 11:21:37 AM »
Oh, "that one .clone() call" is probably a wrong statement. It is only one call, but that is called everytime I want the animation to be played.

I already tried doing all that boundings removal and shader changing stuff on the original _killAnim before using any .clone(), but it made no difference.

Ivan Vodopiviz   «   Reply #7 on: July 04, 2012, 11:44:18 AM »
Have you tried performing the bounds removal on the cloned object? It might be an issue within the clone method that isn't cloning bounding information accordingly.

Jan Drabner   «   Reply #8 on: July 04, 2012, 11:52:15 AM »
Yep, also tried that. That is what's written in the above function.
The KillAnimation class gets a clone as its parameter.

Zayen Chagra   «   Reply #9 on: July 05, 2012, 09:01:59 AM »
I had the issue, and I just scaled the model ( made it bigger ) and it worked. it's a parameter that you can not modify in the camera like the angle of view. 

Jan Drabner   «   Reply #10 on: July 05, 2012, 09:12:48 AM »
I can try that, but that can hardly be the solution as it would make the model bigger or smaller, which of course will look wrong.

georgefloros floros   «   Reply #11 on: July 05, 2012, 09:57:25 AM »
Hi Jan,

Instead of Mesh3D(mesh).bounds = null  try Mesh3D(mesh).bounds.reset() ,that solved a similar problem of mine.