jdurrant

Members
  • Content count

    39
  • Joined

  • Last visited

  1. @JohnK , you had the right idea. @RaananW , I see now that visibility wasn't the right tool. I was thinking that two meshes, each with 0.5 transparency, should not let any background through when viewed aligned, since 0.5 + 0.5 = 1.0. But it makes sense that it would be multiplicative rather than additive. 0.5 * 0.5 = 0.25, so 25% of the background should go through. Perhaps the effect I was looking for is like Photoshop's "overlay" filter. Not sure... @JohnK , your solution wasn't perfect for my actual case because, unlike the playground scene I created, my actual scene involves transparent meshes. The mesh in front has a transparent region through which you can see the mesh in back. Inspired by your idea, though, I ended up sequentially fading the mesh in back completely in, and then fading the mesh in front completely out. I'd hoped to do the fading of both meshes simultaneously, but that's pretty close to what I was looking for. Thanks, guys! Great game engine, by the way!
  2. I want to seemlessly fade between two meshes with very similar materials. My thinking was that if the sum of the visibility values on each was always 1.0, there would be no transparency visible through the both of them together. But in practice that's not the case. I made this playground to illustrate: https://playground.babylonjs.com/#69K17Z#2 Note that the visibility on one of the grass planes goes down exactly as the visibility on the other plane goes up, such that the two visibilities always sum to 1.0. However, during the transition, the fire plane in the background can briefly be seen through the two grass textures. Does anyone know how to fade between two meshes without briefly revealing what's in the background? Thanks! ~Jacob
  3. Video textures not respecting UVs?

    I was too quick to post my question... I found the answer here: For reasons I don't understand, BABYLON.VideoTexture includes a parameter to flip the video across the Y axis. I had that value set to true. So my line: let videoTexture = new BABYLON.VideoTexture("video", ["baked.mp4"], scene, true, true); should have been: let videoTexture = new BABYLON.VideoTexture("video", ["baked.mp4"], scene, true); Hope this helps someone else!
  4. I'm struggling with video textures. I created a simple icosphere in Blender, unwrapped it, and exported it to a babylon file. I then loaded that babylon file in the browser and positioned the camera directly at the center of the sphere. I added a video texture to the sphere's emissive texture, but it doesn't render correctly. It's almost as if it's not respecting the UVs: I naturally thought the UVs must have gotten messed up somehow, but when I create a regular texture using a single frame from the video, it looks perfect: Here's my TypeScript code: declare var BABYLON; declare var jQuery; if (BABYLON.Engine.isSupported()) { // Get the canvas element from our HTML above var canvas = document.getElementById("renderCanvas"); // Load the BABYLON 3D engine var engine = new BABYLON.Engine(canvas, true); BABYLON.SceneLoader.Load("scene/", "babylon.babylon", engine, function (scene) { // Wait for textures and shaders to be ready scene.executeWhenReady(function () { // Attach camera to canvas inputs scene.activeCamera.attachControl(canvas); // Start rendering video texture let sphere = scene.meshes[0]; scene.activeCamera.position = sphere.position; scene.activeCamera.rotation = {x: 0.312831706486495, y: -1.1043217385267734, z: 0.0142} var mat = new BABYLON.StandardMaterial("mat", scene); mat.diffuseColor = new BABYLON.Color3(0, 0, 0); mat.specularColor = new BABYLON.Color3(0, 0, 0); mat.backFaceCulling = true; mat.diffuseTexture = null; let videoTexture = new BABYLON.VideoTexture("video", ["baked.mp4"], scene, true, true); let nonVideoTexture = new BABYLON.Texture("baked_texture34.png", scene); let useVideoTexture = true; mat.emissiveTexture = videoTexture; sphere.material = mat; // Because sphere is only thing in scene. // Once the scene is loaded, just register a render loop to render it engine.runRenderLoop(function() { scene.render(); }); // On click, switch textures jQuery("body").click(function() { this.useVideoTexture = !this.useVideoTexture; if (this.useVideoTexture) { mat.emissiveTexture = this.videoTexture; } else { mat.emissiveTexture = this.nonVideoTexture; } this.sphere.material = mat; }.bind({ sphere: sphere, mat: mat, videoTexture: videoTexture, nonVideoTexture: nonVideoTexture, useVideoTexture: useVideoTexture })); }); }, function (progress) { // To do: give progress feedback to user }); // Watch for browser/canvas resize events window.addEventListener("resize", function () { engine.resize(); }); } Thanks for your help with this!
  5. Blender shape keys and MorphTargetManager

    Thanks for your help, JCPalmer. Just to clarify, you mean I should save the different shape keys as separate meshes (in blender) and then programmatically create a morphTargetManager? Can you provide a code outline? Also, would you mind pointing me in the direction of your implementation of shapekeys? It seems the one I'm using now isn't ready for prime time. Thanks.
  6. I'm using the preview release of Babylon (3.0. alpha) and the 5.3.-1 exporter in Blender. The Blender scene includes shape keys attached to a mesh called "Cloth": When I export to a babylon file, this information appears to be saved correctly. There is a "MorphTargetManager" entry in the file JSON that looks like this: "MorphTargetManager": { "id": "Cloth", "targets": [ { "name": "Draped", "position": [lots of numbers...], "influence": 0 }, { "name": "testtest", "position": [lots of numbers...], "influence": 0 } ] } I then load the babylon file with BABYLON in the browser, but I can't for the life of me figure out how to access this saved MorphTargetManager. Here are some things I tried: BABYLON.scene.morphTargetManagers; ==> [] BABYLON.scene.getMorphTargetManagerById("Cloth"); ==> null BABYLON.scene.getMorphTargetManagerById(0); ==> null (After setting the "Cloth" mesh to clothMesh...) clothMesh.morphTargetManager; ==> undefined (but present when I inspect the mesh object...) I feel like all the parts are there, I just can't figure out how to access the MorphTargetManager that I think should be present when I import the babylon file. Any help you can offer would be appreciated! Thanks!
  7. Very handy function! But it seems it has to be called early in the load process. See https://www.babylonjs-playground.com/#H52JTC#7 In that example, the first resize works great, but when I try to resize the textures again later (on click), it doesn't work. I show a settings page when the user starts my app. The scene begins to load immediately in the background. One of the options on the settings page is to use low-res textures. But by the time the user presses "Start" on that page, the load process in the background has progressed to the point that the texture resize doesn't work. Does that make sense? Hopefully the PG example shows what I mean... Thanks!
  8. Blender exporter needlessly dividing meshes

    Hi all. I was able to resolve this problem by unwrapping the mesh manually (marking seams, etc.). I also divided the mesh into four separate meshes, which may have contributed to the solution. I'm still not certain why it happened on the other version of the mesh, though. For what it's worth, with the new manual unwrapping the mesh did not have to be divided on export. I suspect that's where the problem lies. With low-res shadow map:
  9. Blender exporter needlessly dividing meshes

    Also, for what it's worth, I tried different backFaceCulling settings on the material (true and both), but that didn't fix the problem either. Thanks!
  10. Blender exporter needlessly dividing meshes

    Hi V!nc3r. Just to be clear, I was using Blender to show that the textures do render correctly in that context. I'm not using the diffuse texture that Blender would export. Though I am using the baked shadow texture. Here it is:
  11. Thanks for your help. Here's the PG: https://www.babylonjs-playground.com/#H52JTC
  12. Seems silly to be following up two years after this question was originally posted, but I once again need to resize textures in babylonjs. If scale() does not apply to standard textures, then how is BABYLON.TextureOptimization able to scale all the textures in the scene? I'd now like to be able to create a function that resizes all the textures on the fly, independent of scene optimization. Something like resizeAllTextures(scene, maxWidth). Is it possible? This doesn't work: for (var index = 0; index < scene.textures.length; index++) { var texture = scene.textures[index]; var currentSize = texture.getSize(); var maxDimension = Math.max(currentSize.width, currentSize.height); var scale = 128.0 / maxDimension; if (scale < 1.0) { texture.scale(scale); } }
  13. Blender exporter needlessly dividing meshes

    Thanks for your help, guys. So re. the vertex count, I'm guessing it's because of the mesh's complexity. Different UV coordinates had to be assigned to the same vertices. What a mess! Do you agree that that's the culprit, then? Re. the material, it is the standard material with an ambient texture. Here's the gist: var mat = new BABYLON.StandardMaterial("some_name", scene); mat.diffuseColor = new BABYLON.Color3(0, 0, 0); // to make shadeless mat.emissiveColor = new BABYLON.Color3({some_val}, {some_val}, {some_val}); mat.specularColor = new BABYLON.Color3({some_val}, {some_val}, {some_val}); mat.ambientTexture = new BABYLON.Texture("shadow.png", scene); mesh.material = mat; When I use the texture in Blender, it looks great: Thanks! Great community you've got here.
  14. I have a Blender test scene with two objects. One is a complex "tube," and the other is a high-resolution test cube. Both have UVs. The test cube has 58,984 verts, and the tube has 62,808 verts. So both come in under the ~65,500 limit for exporting as a single mesh. When I export using the Babylon.js ver 5.2.1 exporter, the test cube is exported as a single mesh, but the tube is divided into multiple meshes. The log file suggests there are far more tube verts that Blender reports: Exporter version: 5.2.1, Blender version: 2.78 (sub 0) ========= Conversion from Blender to Babylon.js ========= Scene settings used: selected layers only: false flat shading entire scene: false inline textures: false texture directory: /Users/jdurrant/Documents/Work/durrant_git/protein-vr/webapp/scenes/influenza/ Python World class constructor completed processing begun of mesh: Cube processing begun of Standard material: Material num positions : 63245 num normals : 63245 num uvs : 126490 num uvs2 : 0 num colors : 0 num indices : 353892 processing begun of mesh: NA_patch_single_tube processing begun of Standard material: Material.003 num positions : 65534 num normals : 65534 num uvs : 131068 num uvs2 : 0 num colors : 0 num indices : 107769 WARNING: The following mesh has exceeded the maximum # of vertex elements & will be broken into multiple Babylon meshes: NA_patch_single_tube processing begun of mesh: NA_patch_single_tube1 registered as also a user of material: Material.003 num positions : 65535 num normals : 65535 num uvs : 131070 num uvs2 : 0 num colors : 0 num indices : 107043 processing begun of mesh: NA_patch_single_tube2 registered as also a user of material: Material.003 num positions : 65533 num normals : 65533 num uvs : 131066 num uvs2 : 0 num colors : 0 num indices : 125214 processing begun of mesh: NA_patch_single_tube3 registered as also a user of material: Material.003 num positions : 21593 num normals : 21593 num uvs : 43186 num uvs2 : 0 num colors : 0 num indices : 29625 processing begun of camera (FreeCamera): cmra ========= Writing of scene file started ========= ========= Writing of scene file completed ========= ========= end of processing ========= elapsed time: 0 min, 16.3766 secs When I view the scene in the browser, it ends up looking checkered (perhaps related): Thanks so much for your help!
  15. Dynamically changing LOD distances

    Seems to work! The code is pretty trivial, but in case it helps others: function adjustLODDistances(dist1: number, dist2: number, dist3ForNull: number) { for (let i = 0; i < scene.meshes.length; i++) { let m =scene.meshes[i]; if (m.hasLODLevels === true) { // Get the current LOD levels let CurLODDist1 = m._LODLevels[0].distance; let CurLODDist2 = m._LODLevels[1].distance; let CurLODDist3 = m._LODLevels[2].distance; // Get the LOD meshes at those levels. let lodMesh1 = m.getLODLevelAtDistance(CurLODDist1); let lodMesh2 = m.getLODLevelAtDistance(CurLODDist2); let lodMesh3 = m.getLODLevelAtDistance(CurLODDist3); // Remove those levels from the mesh m.removeLODLevel(lodMesh1); m.removeLODLevel(lodMesh2); m.removeLODLevel(lodMesh3); // Add them back in, with new distances m.addLODLevel(dist1, lodMesh1); m.addLODLevel(dist2, lodMesh2); m.addLODLevel(dist3ForNull, lodMesh3); } } }