MCPcopy Create free account
hub / github.com/assimp/assimp / WriteCamera

Method WriteCamera

code/Pbrt/PbrtExporter.cpp:308–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306}
307
308void PbrtExporter::WriteCamera(int i) {
309 auto camera = mScene->mCameras[i];
310 bool cameraActive = i == 0;
311
312 mOutput << "# - Camera " << i+1 << ": "
313 << camera->mName.C_Str() << "\n";
314
315 // Get camera aspect ratio
316 float aspect = camera->mAspect;
317 if (aspect == 0) {
318 aspect = 4.f/3.f;
319 mOutput << "# - Aspect ratio : 1.33333 (no aspect found, defaulting to 4/3)\n";
320 } else {
321 mOutput << "# - Aspect ratio : " << aspect << "\n";
322 }
323
324 // Get Film xres and yres
325 int xres = 1920;
326 int yres = (int)round(xres/aspect);
327
328 // Print Film for this camera
329 if (!cameraActive)
330 mOutput << "# ";
331 mOutput << "Film \"rgb\" \"string filename\" \"" << mFile << ".exr\"\n";
332 if (!cameraActive)
333 mOutput << "# ";
334 mOutput << " \"integer xresolution\" [" << xres << "]\n";
335 if (!cameraActive)
336 mOutput << "# ";
337 mOutput << " \"integer yresolution\" [" << yres << "]\n";
338
339 // Get camera fov
340 float hfov = AI_RAD_TO_DEG(camera->mHorizontalFOV);
341 float fov = (aspect >= 1.0) ? hfov : (hfov / aspect);
342 if (fov < 5) {
343 std::cerr << fov << ": suspiciously low field of view specified by camera. Setting to 45 degrees.\n";
344 fov = 45;
345 }
346
347 // Get camera transform
348 aiMatrix4x4 worldFromCamera = GetNodeTransform(camera->mName);
349
350 // Print Camera LookAt
351 auto position = worldFromCamera * camera->mPosition;
352 auto lookAt = worldFromCamera * (camera->mPosition + camera->mLookAt);
353 aiMatrix3x3 worldFromCamera3(worldFromCamera);
354 auto up = worldFromCamera3 * camera->mUp;
355 up.Normalize();
356
357 if (!cameraActive)
358 mOutput << "# ";
359 mOutput << "Scale 1 1 1\n";
360 if (!cameraActive)
361 mOutput << "# ";
362 mOutput << "LookAt "
363 << position.x << " " << position.y << " " << position.z << "\n";
364 if (!cameraActive)
365 mOutput << "# ";

Callers

nothing calls this directly

Calls 3

GetNodeTransformFunction · 0.85
C_StrMethod · 0.80
NormalizeMethod · 0.45

Tested by

no test coverage detected