
SuperPudding
Members-
Posts
42 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
SuperPudding's Achievements
-
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
If anyone still checks this thread, I want to let you know that I haven't been able to make this work. The due date for submitting the project came recently and I had to submit and present it without collisions. Fortunately it was good enough to grant me a 100 (the highest score) despite that. I would still like to know how to solve it if anyone has a suggestion... Thanks everyone here that helped me along the way, especially @RaananW, @Deltakosh and @Steffen. -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
Hello again! I haven't had much time lately to work on this (had lots of exams, I'm finishing school soon), but now I'm back and I would really appreciate any help you guys can provide. I still have the exact same problems (it's a shame code can't fix itself...) I'm attaching here a solution (.sln file) with the relevant files from my project. Keep in mind that I did not put the database files and the web service I have, so trying to access those may cause runtime errors, although the website is supposed to treat you as a 'guest' and not allow access in the first place. The code is a bit messy since it's my first time building something of this size and complexity, but you should not need to work with all of it. I marked the place that I believe to be the problem, inside the "Body()" prototype function in the "Graphics.js" file. The problems are definitely related to the implimentation of the cannon physics engine, so I'll write about the other places where it's interacted with in the same file: In the top of the code, right after creating the scene, the cannon plugin is created. In the "play" and "playback" functions (those are click events for buttons) the time step and gravity vector are set. In the "FrameForward" function impostors are set to sleep and to wake up, and there are get and set actions for their velocities. In the "Body" prototype function (as I wrote above) impostiors are created and are put to sleep. This is where the program gets first while running, hence where problems appear. I will now provide some basic instructions for how to use the project as a client: There is only one html page called "Workshop". In the middle of the page there's a canvas element, on which the simulations appear. You can move the camera with the mouse: left button and drag is left-right and up-down translation. right button and drag is yaw and pitch rotation. scrolling the wheel is forward-backwards translation. both buttons (left and right pressed together) and drag is roll rotation Under the canvas there are radio buttons, each opens a menu. These should be pretty obvious. The one you need is "Create Body". Here you enter the properties of the body you want to create (mass, position etc..). After creating the body there should be an exception in the "babylon,js" file, which is my problem. Lastly, right to the canvas there is a "play" button. If the error still exists, the created bodies should appear on the screen but not move when you press "play". If they do move then you got something different then me. I know that's a lot of information for one post, but it's actually not that complicated. I tried making it pretty intuitive to use. If you have any problems please let me know (both to help you help me and to make my project better). Looking forward for your reply. Thanks in advance @Deltakosh @RaananW @Steffen PhysicsProjectSolution.sln Workshop.aspx.cs Workshop.aspx Web.config Graphics.js cannon.js babylon.js babylon.d.ts FormSheet.css Edit: I just realiezed it wouldn't let me upload it as a folder, so I'll explain how to organize all this: You should have a main folder in which all files will be. Inside it you should have a "PhysicsProject" folder, and the "PhysicsProjectSolution.sln" file Inside "PhysicsProject" you should have a "CSS" folder and a "js" folder. It's important to have those names exactly because my code searches in them. inside the "CSS" folder you should put "FormSheet.css" inside the "js" folder you should put "babylon.js", "cannon.js", "Graphics.js" and "babylon.d.ts" files. All other files should be in the "PhysicsProject" folder without any other sub folders. -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@Deltakosh How can I share it? can I attach aspx files here? If not, where should I share it? -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@Steffen I did try using the links directly from the playground and I got the same problem. The run-time error is now not in my script file but in the babylon.js file itself. I wrote about in a previous comment: At that point I got stuck, I've dealt with errors on my script before but I have never gotten an error form the babylon.js file. I just don't know what exactly is undefined and where is the problem... By the way the result of "alert(b)" is 'Object object', but other than knowing it's not null or undefined it doesn't help me much. I put it in its own variable mostly for inspecting it using the new debugging methods I learned here (with the browser inspect options). -
SuperPudding reacted to a post in a topic: Can't get Cannon.js to work in my Babylon.js scene
-
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW In the folder with the files for babylon there are some files I have never used and I don't know what they're for: babylon.core.js, babylon.max.js, babylon.noworker.js and besides that basically everything outside of the 'dist' folder (do I need any files from 'src' for example?) Can you tell me what their use is and if there's a possibility that my problems are arising from the fact they're not in my project? -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW @Steffen Whenever I create an impostor it is supposed to automatically be added to the active physics engine. right? this.mesh = mesh; this.centerOfMass = BABYLON.Mesh.CreateBox(mesh.name + "CenterOfMass", 1, mesh.getScene()); this.centerOfMass.visibility = 0; this.mesh.parent = this.centerOfMass; this.centerOfMass.translate(centerOfMass, 1, BABYLON.Space.WORLD); this.mesh.translate(geometricCenter.subtract(centerOfMass), 1, BABYLON.Space.WORLD); this.mass = mass; this.velocity = velocity; this.angularVelocity = angularVelocity; this.elasticity = elasticity; this.inertiaTensor = inertiaTensor; this.colliding = false; alert("impostor1") this.mesh.physicsImpostor = new BABYLON.PhysicsImpostor(this.mesh, BABYLON.PhysicsImpostor.MeshImpostor, { mass: this.mass, restitution: this.elasticity }, mesh.getScene()); alert("impostor2"); var b = this.mesh.physicsImpostor; alert(b); this.mesh.physicsImpostor.sleep(); alert("impostor3"); I tried pausing between the alerts "impostor2" and "impostor3" (after the impostor was created). I then checked the properties of the physics engine and its impostor array was empty (had length 0). I feel like all these errors are caused by a single problem but I don't know what it is... I really need to wrap this up today, this is the very last thing left to implement in my project and it's due Sunday (it's a school final project). -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW @Steffen Ok, I think I'm starting to somewhat understand what's going on. I tried using the chrome inspector debugging like you guys suggested here. I discovered that: Some of the functions are missing (for instance the compiler is not aware of the function "scene.getPhysicsEngine().sleepBody(impostor)", but does recognize "impostor.sleep()"). Some objects and properties of objects are undefined (probably because of the missing functions). I tried changing the "scene.getPhysicsEngine().sleepBody(impostor)" to "impostor.sleep()". The run-time error in this line did not happen this time, but there was an error later on in the babylon.js file itself. The exception stated "cannot read property 'sleep' of udefined at t.sleepBody", which I suspect is again because of missing functions. Another thing I noticed is that in my constructor (prototype function) "new Body(...)", when I highlight 'this' in the debugger it shows the properties of physicsPlugin, which is very very wrong and has no logical reason for happening. Edit: Checked again, it works fine. It probably showed it since it was already in another function (where 'this' is physicsPlugin) and when I highligted 'this' it referred to the current 'this' in the other function... -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW I downloaded the files from GitHub and used the ones in the "preview release" folder in dist. I added "babylon.js", "babylon.d.ts" and "cannon.js" and it still has the same problems. In my javascript file I have a reference to "babylon.d.ts" and in the html page I have sripts with "babylon.js" and "cannon.js". Am I missing any files? Another thing, I noticed that when I had the call "physicsPlugin.isSupported()" it worked fine, but now that I changed it to "scene.getPhysicsEngine().isSupported()" it crashed. I checked and it returns 'undefined' although the call was after "scene,enablePhysics(g, physicsPlugin)". I think I'm missing a reference to a file or something -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW I'm using the cannon.js file from the folder "preview release" that came with my download of babylon.js. My babylon.js file and babylon.d.ts file are also from there. About interacting with the plugin... is there a difference between "physicsPlugin.setTimeStep()" and "scene.getPhysicsEngine().setTimeStep()"? If not, then how am I supposed to set the time step and do similar stuff? And again I don't really know how to get the type of exception but I'll try looking into it. I think this might be a problem of outdated files, maybe when I downloaded babylon those functions were not yet integrated fully (you said yourself they are new in 2.4). I'm going to try to download it again and see if it makes any difference. -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@Steffen I looked at the files you uploaded. My babylon.js file definintely has much less in it than the one here. Maybe I have an outdated one? (I downloaded it about two months ago I think). Edit: Checked again, when I open my file in Visual Studio it looks shorter but its layout is just different (it goes horizontally). It isn't too short but it's different (I looked at the start and the end and there are some differences). -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW In the beginning of the javascript file I have this: var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(0.1, 0.1, 0.25); var g = new BABYLON.Vector3(0, 0, 0); var dt = 0.01; var physicsPlugin = new BABYLON.CannonJSPlugin(); alert(physicsPlugin.isSupported()); alert(physicsPlugin); scene.enablePhysics(g, physicsPlugin); physicsPlugin.setTimeStep(dt); The alerts are for debugging. This goes without run-time errors. Later on I create objects with user input. They are of type "Body" that I defined myself: function Body(mesh, geometricCenter, mass, centerOfMass, velocity, angularVelocity, elasticity, inertiaTensor) { this.mesh = mesh; this.centerOfMass = BABYLON.Mesh.CreateBox(mesh.name + "CenterOfMass", 1, mesh.getScene()); this.centerOfMass.visibility = 0; this.mesh.parent = this.centerOfMass; this.centerOfMass.translate(centerOfMass, 1, BABYLON.Space.WORLD); this.mesh.translate(geometricCenter.subtract(centerOfMass), 1, BABYLON.Space.WORLD); this.mass = mass; this.velocity = velocity; this.angularVelocity = angularVelocity; this.elasticity = elasticity; this.inertiaTensor = inertiaTensor; this.colliding = false; alert("impostor1") this.mesh.physicsImpostor = new BABYLON.PhysicsImpostor(this.mesh, BABYLON.PhysicsImpostor.MeshImpostor, { mass: this.mass, restitution: this.elasticity }, mesh.getScene()); alert("impostor2"); physicsPlugin.sleepBody(this.mesh.physicsImpostor); alert("impostor3"); } Again, the alerts are for debugging, and "impostor3" never shows up... Edit: If for some reson you can't see the end of the long line in the second snippet try highlighting it. It says: this.mesh.physicsImpostor = new BABYLON.PhysicsImpostor(this.mesh, BABYLON.PhysicsImpostor.MeshImpostor, { mass: this.mass, restitution: this.elasticity }, mesh.getScene()); -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@Steffen I haven't noticed the playground you posted. When I said I checked and it worked I meant that I didn't get a run-time error (like it did do in my non-playground application before I used 2.4). I looked at your playground and you are right, it needs to be set after I enable the physics. -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@RaananW I switched to 2.4 already. The functions of the plugin itself seem to work but I get exceptions when I try calling functions of "BABYLON.PhysicsImpostor" (like setLinearVelocity) or when I try referencing impostors (for example "CannonJSPlugin.sleepBody(impostor)"). About the type of exceptions, I don't know how to check (never learned how to debug in javascript other than alerts). -
RaananW reacted to a post in a topic: How to go about collisions in Babylon
-
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
@Steffen I actually checked it in the playground and it works both after and before "enablePhysics". About the exception, I don't know that kind it was. All I know is that it stopped at this line. I'm not really familiar with debugging in javascript and have never tried dealing with exceptions (I debug mostly using alerts). About publishing the whole code, that may be problematic because most of it is irrelevant and some very chaotic. If I publish more I should probably make it more understandable before... Another thing I found out is when I use "scene.enablePhysics" and then "scene.getPhysicsEngine()" it returns "undefined" (which is different, before I switched to 2.4 it returned null). -
Can't get Cannon.js to work in my Babylon.js scene
SuperPudding replied to SuperPudding's topic in Questions & Answers
New Update: I tried babylon version 2.4 and it solved some of the problems, but not all. the physicsEngine functions like "setTimeStep()" now work, but impostors functions like "setLinearVelocity(vector)" still throw exceptions. I'll keep updating. If anyone has an idea what to do now I'll be very grateful.