mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.97k stars 35.33k forks source link

r76 blender exporter camera #8820

Closed pontiffpublishing closed 6 years ago

pontiffpublishing commented 8 years ago
Description of the problem

Hi, Thank you for this great framework.

I upgrade to r76 to fix another problem and all my exported blender scenes no longer rendered right.

From the same blender file, a camera exported with the r76 addon gives this:

        "name":"Camera",
        "uuid":"DE0714B3-5D16-30EF-9A0A-6C5D6DD394B9",
        "matrix":[-1,0,0,0,0,0,1,0,0,1,0,0,0,5,0,1],
        "visible":true,
        "type":"PerspectiveCamera",
        "far":100,
        "near":0.1,
        "aspect":1.77778,
        "fov":35

While the r75 exporter addon gives this definition

        "name":"Camera",
        "uuid":"DE0714B3-5D16-30EF-9A0A-6C5D6DD394B9",
        "matrix":[1,0,0,0,0,1,0,0,0,0,1,0,0,0,5,1],
        "visible":true,
        "type":"PerspectiveCamera",
        "far":100,
        "near":0.1,
        "aspect":1.77778,
        "fov":35

to get the camera to work right, I have to replace the r76 "matrix" definition with the r75 definition.

Hope this helps.

...

Three.js version
mrdoob commented 8 years ago

/ping @daniel-nth

pontiffpublishing commented 8 years ago

Um, switch that. The r75 camera data I gave came from the r76 output, and the r76 data belongs to the r75 output.

BenCidPerez commented 8 years ago

I upgrade to r76 to fix another problem and all my exported blender scenes no longer rendered right.

Hi! Could you include a screenshot of the "right" and "wrong" scene? Could make it easier to reproduce what is going wrong.

pontiffpublishing commented 8 years ago

Very sorry for such an unhelpful problem statement.

I use blender 2.77a and currently run r77 of three.js.

If you look at the camera tab in the properties panel of blender, there is an input field with a corresponding toggle button that switches between a focal length/mm(s) and fov/degrees settings. I guess fov and focal length are just the two values that express essentially the same thing but with different units.

What I found is that the blender to three.js exporter takes the value for focal-length/mm from blender and exports it as the FOV value for the corresponding three.js camera. So, for example, if I set fov = 60 in blender, that corresponds (if I toggle from fov to focal length for that field) to a 34mm value, and what I get if I export to three.js is a camera with a 34 FOV. So, to see the scene as I make it in blender, I have to manually reset the FOV of the blender-created camera to 60 when I get it into three.js and update the projection matrix.

Cheers.

On Tue, Jul 5, 2016 at 5:32 AM, Benjamin Cid Pérez <notifications@github.com

wrote:

I upgrade to r76 to fix another problem and all my exported blender scenes no longer rendered right.

Hi! Could you include a screenshot of the "right" and "wrong" scene? Could make it easier to reproduce what is going wrong.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mrdoob/three.js/issues/8820#issuecomment-230464848, or mute the thread https://github.com/notifications/unsubscribe/AL3GMwzLQ2EiB6aYls33mInJdslmzbl-ks5qSk7FgaJpZM4IYg1M .

BenCidPerez commented 8 years ago

@pontiffpublishing Gotcha! Found the bug in the blender exporter. In the "camera.py"-file, line 77, there is a reference to the blender property "camera.lens", that should be "camera.angle" - right now the exporter uses the focal length of the camera, instead of the FOV-angle, that is actually required by Three.js.

@mrdoob Should I put up a pull-request for that line of code?

Cheerio!

BenCidPerez commented 8 years ago

@pontiffpublishing the more I think about it, are you sure your first and last post relate to the same bug? Because I think the FOV-bug may actually be pretty old and not related to your matrix-mixup you discribed in your first post.

pontiffpublishing commented 8 years ago

Oops. I should have read back to the beginning.

If you import a three.js scene from blender, the camera's matrix changes to impose a coordinate system where Positive Z is UP and Positive X is LEFT. So if I setup a camera, in blender at XYZ <0 0 10> with no rotation applied, it imports into THREE.js at position XYZ <0 10 0> with a rotation applied on import to point the camera from its new position on the Y axis back toward the origin, I guess.

My guess is that you guys decided to import Blender's right-hand coordinate system directly instead of remapping everything to THREE.js's left-hand coordinate system. But that means that, if I use Blender in my workflow, I am committing to using two coordinate systems--one for Blender and one for THREE.js--and translating between them. So, for example, whenever I create an object in THREE.js and add it to a scene imported from blender, I have to be sure to position, rotate, and translate the new object, in THREE's left-hand coordinate system, so that it is picked up by the camera reflecting a left-hand coordinate system and so it aligns with all the other objects imported from Blender. The same goes for objects created for your super-cool CSS3d renderer. I have to create them and then 3d transform them if I want them to align with Webgl objects imported from blender.

So I thought this was a bug, at first. But maybe it is just a feature request. Let me know if I need to change my request.

Thanks.

On Tue, Jul 5, 2016 at 9:52 AM, Benjamin Cid Pérez <notifications@github.com

wrote:

@pontiffpublishing https://github.com/pontiffpublishing the more I think about it, are you sure your first and last post relate to the same bug? Because I think the FOV-bug may actually be pretty old and not related to your matrix-mixup you discribed in your first post.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mrdoob/three.js/issues/8820#issuecomment-230535803, or mute the thread https://github.com/notifications/unsubscribe/AL3GMxF0aZwPGcYhnap9M3lBb4r1fHM3ks5qSou5gaJpZM4IYg1M .

mrdoob commented 8 years ago

@mrdoob Should I put up a pull-request for that line of code?

Sounds good!

mrdoob commented 8 years ago

So I thought this was a bug, at first. But maybe it is just a feature request. Let me know if I need to change my request.

I think it's a bug. Unfortunately seems like no one wants to maintain the exporter...

BenCidPerez commented 8 years ago

Hi all, created a pull request for the camera FOV bug. Sorry for the delay! Right now we are still in the middle of a project, that has been going on for a few weeks, but @daniel-nth and I will be be taking a closer look at the exporter beginning next week and hopefully fix some issues.

inear commented 6 years ago

Old topic, but just a comment on this since I experienced some issues in Blender 2.76 (stuck in that version because of long term project and custom version of three.js). Only changing from camera.lens to camera.angle will export fov as radians, so you need to transform inte degrees after importing to three.js. Or change the exporter. And I had trouble matching the cameras anyways. What seem to work for me was to set the sensor-size values vertical/horizontal to the same value and disable "auto". Then my cameras end up the same in both blender and three.js. screen shot 2018-04-04 at 09 48 25

Mugen87 commented 6 years ago

The JSON Blender exporter has been removed with R93 (#14117).

Also see: https://threejs.org/docs/#manual/introduction/Loading-3D-models