Jump to content

sable

Members
  • Content Count

    88
  • Joined

  • Last visited

Posts posted by sable

  1. Was mainly just copied from a project I've been working on which faced similar performance issues with picking sphere particles from a sps, with corrections for the pivot point changing.

    I''ll try and take a look at sorting out the jumping in the next few days, but post back if you get it sorted before then.

  2. The reason it was quite slow is that spheres have a lot of faces, and the pick function has to iterate over each one to find the picked point.

    The fastPick version doesn't behave in the same way as the original, as it generally is just stopping at the ground/wall intersection, so is not putting the mouse sphere on the SPS.

    You can implement your own picking for the sps, and do ray sphere tests, https://www.babylonjs-playground.com/debug.html#8PY6X5#18, which is much, much, faster.

    If the particles aren't spheres, then you could do the above using spheres as bounding spheres, and then get the actual picked point from an intersection test with just the closest particle.

    I'm not sure the zooming in is quite working as intended, as if you move the mouse once already zoomed in, and then zoom out or in, the sps jumps to a new position. Probably need to do some sort of correction given the current pivot point.

     

     

  3. I removed the offsetX check as I was finding it jarring for the camera to pan a little sometimes while rotating if the x offset happened to be zero (while the y offset was not).

    Where's the screenCoordinatesToWorldCoordinates function from? It sounds like the start of firing a ray from the camera and then using it to pick a point.

    Regarding picking a pivot point, if you're just dealing with a flat 2d plane, then doing an intersection test against that (BABYLON.Plane) will be a bit cheaper than doing one against a mesh (especially if you're wanting to test on mouse move when dragging to maintain position under the cursor).

    Edit: Just stumbled across https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/shiftKey which you might also find of use

  4. I was looking at the pg in the above post, and noticed that the near plane is positioned incorrectly.

    It seems that passing in a source plane to meshBuilder's createPlane function translates the plane in the wrong direction, and also rotates it so that it is facing the wrong way.

    For a plane with normal (0,0,1), and a point on the plane (0,0,10), meshBuilder will position the plane at (0,0,-10) and face it looking along the -ve Z axis.

    Example pg, with what I believe are fixes here.

  5. https://github.com/BabylonJS/Babylon.js/blob/4b63e18d3dbd31d400fff1cba68de2981f8ba2ee/src/Materials/Textures/babylon.baseTexture.ts#L16
    

    https://github.com/BabylonJS/Babylon.js/blob/4b63e18d3dbd31d400fff1cba68de2981f8ba2ee/src/babylon.scene.ts#L6001

    Setting has alpha seems to mark all materials in the scene as dirty. So in this case it's calling markAllMaterialsAsDirty a thousand times, each time with a larger materials array to loop over.

    You could get a compromise of behaviour by just setting the private _hasAlpha and then calling markAllMaterialsAsDirty after the loop.

    http://www.babylonjs-playground.com/#R8QY81#1

  6. https://www.babylonjs-playground.com/#DD2IDJ

    The above pg implements controls that are similar to most mapping solutions (panning keeps mouse in same position, as does zooming), and is basically a stripped down version of the control system I used here (though there the camera was also heavily modified so as to allow both rotation around the globe and about the surface target. The 2d mode available through the tools menu could have been done using the control scene from the pg and the standard camera however. Touch controls are also implemented there but not in the above pg). There may be a more idiomatic way of implementing custom controls though.

    I'm not sure if this is entirely what you're looking for (2d plane navigation), though I think it could be extended to work in 3d zooming in to a plane parallel to the viewport. Let me know if anything in there is unclear.

  7. Yeah my use case is loading a model (.babylon format), and then applying a customMaterial to it (so I can modify the shaders). I was trying to just attach the texture from the original material to this new material and just update the sampling mode when I ran across the issue (after discovering that setting the sampling mode in the .babylon file was also didn't work).

    My workaround was to just extract the url and make a new texture, which I'll continue to do for now, as even waiting for the texture to load doesn't seem to always work.

    Thanks for looking into this.

  8. It seems like texture.updateSamplingMode() doesn't actually work (though looking through the code, it looks like it should, as it's making the right gl calls).

    http://www.babylonjs-playground.com/#Q9RDM0

    I noticed this as loading a .babylon file with sampling mode set wasn't working (though the samplingMode property on the texture would be correct, it was not rendering in that mode).

    (And assuming that it should work, https://doc.babylonjs.com/resources/file_format_map_(.babylon)#textures should probably be updated to include the samplingMode property)

  9. Actually pretty sure it's your sort function, needs to return a  -ve number, +ve number, or 0, not true or false. https://www.babylonjs-playground.com/#BTU1J7#5

    If you log out the position.z of each mesh after sorting the way it was you'll see that they're not in the correct order.

    It would be less work just using the pos.z - campos directly as the alpha index though, unless there is some other reason you need to sort them.

  10. I've just done something similar for 3ds files, which while not removing a dependency on blender,  makes it really easy to batch convert models using the babylonjs blender exporter. I'm sure other formats could be converted using a similar method.

    import os
    import bpy
    import sys
    
    # see https://blender.stackexchange.com/questions/46990/how-to-completely-remove-all-loaded-data-from-blender?noredirect=1&lq=1
    # make sure scene is empty
    bpy.ops.wm.read_homefile(use_empty=True)
    
    path_to_3ds = sys.argv[5]
    
    file_list = sorted(os.listdir(path_to_3ds))
    
    autodesk_list = [item for item in file_list if item.endswith('.3ds')]
    
    for item in autodesk_list:
        bpy.ops.wm.addon_enable(module="babylon-js")
        path_to_files = os.path.join(path_to_3ds, item)
        bpy.ops.import_scene.autodesk_3ds(filepath = path_to_files)
    
        bpy.ops.bjs.main(filepath= os.path.join(path_to_3ds, item.replace("3ds", "babylon")))
        # bpy.ops.export_scene.obj(filepath= os.path.join(path_to_3ds, item.replace("3ds", "obj")))
    
        bpy.ops.wm.read_homefile(use_empty=True)

    And then call this using:

    "$BLENDER_LOCATION" --background --python ./convert.py -- "$PATH_TO_MODELS"

    Some fixing up afterwards (due to 3ds models not having a diffuse colour, and a few other things) is done using sed  on the .babylon files after this, but what (if anything) needs fixing would depend on the input format.

    For the models I've been converting, it's been taking less than a second for each one.

×
×
  • Create New...