True3D™ Model Demo
This demo shows how to use the 3D Model API.
NOTE: Web Browsers And Cross-Site Scripting
Version 1A — Cow (Direct Rendering To JPEG)
Version 1B — Cow (Export As PDF Document)
▸ 3d-model-cow-b.i
::my.include("../../common/includes/integral/doc-base.i");
::my.include("../../common/includes/integral/doc-pict.i");
local model = CDTModel3D(); // make new 3D model */
local result;
result = model.Load("models/cow.d3d"); // load 3D model in INTEGRAL 3D format
result = model.Save("output/cow-out.stl", DR_3D_SAVE_STL); // save 3D model in STL format
/* set camera */
model.SetPos(1.0, -6.0, 17.0); // (x, y, z) location of camera in model space
model.SetRot(0.0, 66.0, 0.0); // (pitch, yaw, roll) angles in degrees
model.SetMul(1.0, 1.0, 1.0); // (x, y, z) scaling factors
/* set various rendering parameters (all optional) */
model.SetBackgroundRGB(90, 110, 100); // RGB background color value
model.SetRasterizer(0); // render using Extreme rasterizer
model.SetQuality(4); // antialiased quality
model.SetShading(1); // smooth shading
model.SetCulling(0); // no culling
model.SetClipping(1); // precise clipping
model.SetTransformMode(0); // default transform mode
model.SetTranspThreshold(128); // reasonable transparency threshold value
model.SetMaxDepth(16); // reasonable accumulation buffer depth
model.SetMiscBits(0); // perspective projection
local zoom = 1.0;
local page_w = 5100, page_h = 3400, margin_w = 200, margin_h = 200;
local doc = CDTDocumentBasic();
result = model.ToDocument(doc, page_w, page_h, margin_w, margin_h); // embed 3D model in document
::my.app.ReZoom(zoom);
::my.app.Export(DX_FORMAT_PDF_NORMAL, page_w * zoom, page_h * zoom); // export document as PDF
Version 2A — Teapot — Flat Auto-Shading (Direct Rendering To PNG)
▸ 3d-model-teapot-a1.i
local model = CDTModel3D(); // make new 3D model */
local result;
result = model.Load("models/teapot.stl"); // load 3D model in STL format
/* set camera */
model.SetPos(-1.0, -2.0, 20.0); // (x, y, z) location of camera in model space
model.SetRot(40.0, 20.0, 20.0); // (pitch, yaw, roll) angles in degrees
model.SetMul(1.0, 1.0, 1.0); // (x, y, z) scaling factors
/* set various rendering parameters (all optional) */
model.SetBackgroundRGB(220, 220, 220); // RGB background color value
model.SetRasterizer(0); // render using Extreme rasterizer
model.SetQuality(4); // antialiased quality
model.SetShading(0); // flat shading
model.SetCulling(0); // no culling
model.SetClipping(1); // precise clipping
model.SetTransformMode(0); // default transform mode
model.SetTranspThreshold(128); // reasonable transparency threshold value
model.SetMaxDepth(16); // reasonable accumulation buffer depth
model.SetMiscBits(0); // perspective projection
model.ShadeRGBT(DR_3D_ADAPT_SHADE_FLAT, [255, 215, 10, 0], [120, 50, 10, 0], [0.0, 0.0, 1.0]); // shade using a gradient gold-to-brown, position light at (0.0, 0.0, 1.0)
result = model.Render(DR_3D_RENDER_PNG, 600, 400); // export model to PNG image
Version 2A — Teapot — Smooth Auto-Shading (Direct Rendering To PNG)
▸ 3d-model-teapot-a2.i
local model = CDTModel3D(); // make new 3D model */
local result;
result = model.Load("models/teapot.stl"); // load 3D model in STL format
/* set camera */
model.SetPos(-1.0, -2.0, 20.0); // (x, y, z) location of camera in model space
model.SetRot(40.0, 20.0, 20.0); // (pitch, yaw, roll) angles in degrees
model.SetMul(1.0, 1.0, 1.0); // (x, y, z) scaling factors
/* set various rendering parameters (all optional) */
model.SetBackgroundRGB(220, 220, 220); // RGB background color value
model.SetRasterizer(0); // render using Extreme rasterizer
model.SetQuality(4); // antialiased quality
model.SetShading(1); // smooth shading
model.SetCulling(0); // no culling
model.SetClipping(1); // precise clipping
model.SetTransformMode(0); // default transform mode
model.SetTranspThreshold(128); // reasonable transparency threshold value
model.SetMaxDepth(16); // reasonable accumulation buffer depth
model.SetMiscBits(0); // perspective projection
model.ShadeRGBT(DR_3D_ADAPT_SHADE_SMOOTH, [255, 215, 10, 0], [120, 50, 10, 0], [0.0, 0.0, 1.0], [0.001, 0.873]); // shade using a gradient gold-to-brown, position light at (0.0, 0.0, 1.0), set tolerance to 0.001 and split angle to 0.873 radians (50 degrees)
result = model.Render(DR_3D_RENDER_PNG, 600, 400); // export model to PNG image
Version 2B — Teapot — Flat Auto-Shading (Export As PDF Document)
▸ 3d-model-teapot-b1.i
::my.include("../../common/includes/integral/doc-base.i");
::my.include("../../common/includes/integral/doc-pict.i");
local model = CDTModel3D(); // make new 3D model */
local result;
result = model.Load("models/teapot.stl"); // load 3D model in STL format
/* set camera */
model.SetPos(-1.0, -2.0, 20.0); // (x, y, z) location of camera in model space
model.SetRot(40.0, 20.0, 20.0); // (pitch, yaw, roll) angles in degrees
model.SetMul(1.0, 1.0, 1.0); // (x, y, z) scaling factors
/* set various rendering parameters (all optional) */
model.SetBackgroundRGB(220, 220, 220); // RGB background color value
model.SetRasterizer(0); // render using Extreme rasterizer
model.SetQuality(4); // antialiased quality
model.SetShading(0); // flat shading
model.SetCulling(0); // no culling
model.SetClipping(1); // precise clipping
model.SetTransformMode(0); // default transform mode
model.SetTranspThreshold(128); // reasonable transparency threshold value
model.SetMaxDepth(16); // reasonable accumulation buffer depth
model.SetMiscBits(0); // perspective projection
model.ShadeRGBT(DR_3D_ADAPT_SHADE_FLAT, [255, 215, 10, 0], [120, 50, 10, 0], [0.0, 0.0, 1.0]); // shade using a gradient gold-to-brown, position light at (0.0, 0.0, 1.0)
local zoom = 1.0;
local page_w = 5100, page_h = 3400, margin_w = 200, margin_h = 200;
local doc = CDTDocumentBasic();
result = model.ToDocument(doc, page_w, page_h, margin_w, margin_h); // embed 3D model in document
::my.app.ReZoom(zoom);
::my.app.Export(DX_FORMAT_PDF_NORMAL, page_w * zoom, page_h * zoom); // export document as PDF
Version 2B — Teapot — Smooth Auto-Shading (Export As PDF Document)
▸ 3d-model-teapot-b2.i
::my.include("../../common/includes/integral/doc-base.i");
::my.include("../../common/includes/integral/doc-pict.i");
local model = CDTModel3D(); // make new 3D model */
local result;
result = model.Load("models/teapot.stl"); // load 3D model in STL format
/* set camera */
model.SetPos(-1.0, -2.0, 20.0); // (x, y, z) location of camera in model space
model.SetRot(40.0, 20.0, 20.0); // (pitch, yaw, roll) angles in degrees
model.SetMul(1.0, 1.0, 1.0); // (x, y, z) scaling factors
/* set various rendering parameters (all optional) */
model.SetBackgroundRGB(220, 220, 220); // RGB background color value
model.SetRasterizer(0); // render using Extreme rasterizer
model.SetQuality(4); // antialiased quality
model.SetShading(1); // smooth shading
model.SetCulling(0); // no culling
model.SetClipping(1); // precise clipping
model.SetTransformMode(0); // default transform mode
model.SetTranspThreshold(128); // reasonable transparency threshold value
model.SetMaxDepth(16); // reasonable accumulation buffer depth
model.SetMiscBits(0); // perspective projection
model.ShadeRGBT(DR_3D_ADAPT_SHADE_SMOOTH, [255, 215, 10, 0], [120, 50, 10, 0], [0.0, 0.0, 1.0], [0.001, 0.873]); // shade using a gradient gold-to-brown, position light at (0.0, 0.0, 1.0), set tolerance to 0.001 and split angle to 0.873 radians (50 degrees)
model.Save("output/teapot.d3d", DR_3D_SAVE_ONLY_VERT_COLORS); // save 3D model in INTEGRAL 3D format
local zoom = 1.0;
local page_w = 5100, page_h = 3400, margin_w = 200, margin_h = 200;
local doc = CDTDocumentBasic();
result = model.ToDocument(doc, page_w, page_h, margin_w, margin_h); // embed 3D model in document
::my.app.ReZoom(zoom);
::my.app.Export(DX_FORMAT_PDF_NORMAL, page_w * zoom, page_h * zoom); // export document as PDF
For Help With This Demo