True3D™ Texture Demo
This demo shows how to build 3D models with a 2D texture.
NOTE: Web Browsers And Cross-Site Scripting
Version 1 — Semi-Transparent RGB Texture (Direct Rendering To PNG)
Version 2 — Semi-Transparent Grayscale Texture (Direct Rendering To PNG)
▸ 3d-texture-b.i
::my.include("../../common/includes/integral/doc-base.i");
function CDTDocumentBasic::Make()
{
/* lambda shortcuts */
local o = @(label = "") CDTObj(this, label); /* to make object */
local s = @(id, str) CDTPropStr(id, str); /* to add property - string */
local i = @(id, num) CDTPropInt(id, num); /* to add property - integer */
local l = @(id, obj) CDTLink(id, obj); /* to add link */
/* objects and their properties */
local o00 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o01 = o("Ellipse Body Color") + s(pdRGBT, "FFFF0000");
local o02 = o("Ellipse Shadow Color") + s(pdRGBT, "80808078");
local o03 = o("Ellipse Outline") + l(pdStylePtr, o00) + i(pdLineThickness, 340);
local o04 = o("Ellipse Shadow") + l(pdStylePtr, o02) + i(pdShadowDx, 5) + i(pdShadowDy, 5);
local o05 = o("Ellipse") + i(pdDw, 480) + i(pdDh, 480) + l(pdBodyPtr, o01) + l(pdOutlinePtr, o03) + l(pdShadowPtr, o04);
local o06 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o07 = o("Ellipse Body Color") + s(pdRGBT, "FFFFFF00");
local o08 = o("Ellipse Outline") + i(pdLineThickness, 340) + l(pdStylePtr, o06);
local o09 = o("Ellipse") + l(pdOutlinePtr, o08) + l(pdBodyPtr, o07) + i(pdDw, 140) + i(pdDh, 140);
local o10 = o("Arc Color") + s(pdRGBT, "50641400");
local o11 = o("Arc Line Width") + l(pdStylePtr, o10) + i(pdLineThickness, 1700);
local o12 = o("Arc") + l(pdLinePtr, o11) + i(pdAngleTheta, 120) + i(pdAngleAlpha, 30) + i(pdRadiusHor, 160) + i(pdRadiusVer, 160);
local o13 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o14 = o("Ellipse Body Color") + s(pdRGBT, "FFC01400");
local o15 = o("Ellipse Outline") + i(pdLineThickness, 240) + l(pdStylePtr, o13);
local o16 = o("Ellipse") + l(pdOutlinePtr, o15) + l(pdBodyPtr, o14) + i(pdDh, 130) + i(pdDw, 160);
local o17 = o("Ellipse Body Color") + s(pdRGBT, "50641400");
local o18 = o("Ellipse") + l(pdBodyPtr, o17) + i(pdDw, 70) + i(pdDh, 70);
local o19 = o("TextLine Typography") + s(pdFontUniqueID, "F0011_STIX1__NS0") + i(pdFontDw, 70) + i(pdFontDh, 100) + l(pdBodyPtr, o17);
local o20 = o("TextLine Layout") + i(pdAlignEnd, 1);
local o21 = o("TextLine") + s(pdTextString_08, "Hello INTEGRAL!") + l(pdTypographyPtr, o19) + l(pdTextLayoutPtr, o20);
/* image placement */
o05.Pin(0, 100, 170, pdDrawEllipse);
o09.Pin(0, 180, 250, pdDrawEllipse);
o12.Pin(0, 340, 410, pdDrawArc);
o18.Pin(0, 205, 260, pdDrawEllipse);
o09.Pin(0, 360, 250, pdDrawEllipse);
o18.Pin(0, 385, 260, pdDrawEllipse);
o16.Pin(0, 260, 340, pdDrawEllipse);
o21.Pin(0, 340, 120, pdDrawTextLine);
}
function CDTModel3D::TransformedVertex(v, default_color = 0)
{
return CDTVertex3D(8.0 * v.X, -8.0 * v.Z, 8.0 * v.Y, ((v.Color == null) ? default_color : v.Color), v.U, v.V);
}
function CDTModel3D::AddTriangle(v0, v1, v2, default_color = 0, texture_id = 0, texture_quality = DR_3D_TEXTUREQUALITY_SMOOTH_B)
{
AddElement(TransformedVertex(v0, default_color), TransformedVertex(v1, default_color), TransformedVertex(v2, default_color), default_color, texture_id, texture_quality);
}
function CDTModel3D::AddPyramid(transp_base = 0, transp_side = 0)
{
local v = @(x, y, z, rgbt = null) CDTVertex3D(x, y, z, rgbt); // a small labmda shortcut
local d = 1.7; // length of the pyramid side in model space
/* base of the pyramid */
AddTriangle(v(-d, -d, d), v( d, -d, d), v( d, d, d), ColorRGBT(128, 128, 0, transp_base));
AddTriangle(v(-d, -d, d), v( d, d, d), v(-d, d, d), ColorRGBT(128, 128, 0, transp_base));
/* 4 sides of the pyramid */
AddTriangle(v( d, -d, d), v( 0, 0, -d), v( d, d, d), ColorRGBT( 64, 128, 0, transp_side));
AddTriangle(v( 0, 0, -d), v(-d, -d, d), v(-d, d, d), ColorRGBT( 0, 128, 128, transp_side));
AddTriangle(v(-d, d, d), v( d, d, d), v( 0, 0, -d), ColorRGBT( 0, 128, 64, transp_side));
AddTriangle(v( d, -d, d), v(-d, -d, d), v( 0, 0, -d), ColorRGBT( 0, 128, 0, transp_side));
}
function CDTModel3D::AddCube(texture_id, transp = 0)
{
local v = @(x, y, z, rgbt = null, u = 0, v = 0) CDTVertex3D(x, y, z, rgbt, u, v); // a small labmda shortcut
local d = 1.0; // length of the cube d in model space
local color_unused = ColorRGBT(192, 192, 192, 0);
/* side #1 of the cube */
AddTriangle(v(-d, -d, d), v(d, -d, d), v( d, d, d), ColorRGBT(128, 255, 0, transp));
AddTriangle(v(-d, -d, d), v(d, d, d), v(-d, d, d), ColorRGBT(128, 255, 0, transp));
/* side #2 of the cube */
AddTriangle(v( d, -d, -d), v(-d, -d, -d), v(-d, d, -d), ColorRGBT( 0, 128, 255, transp));
AddTriangle(v( d, -d, -d), v(-d, d, -d), v( d, d, -d), ColorRGBT( 0, 128, 255, transp));
/* side #3 of the cube */
AddTriangle(v( d, -d, d), v( d, -d, -d), v( d, d, -d), ColorRGBT( 0, 255, 128, transp));
AddTriangle(v( d, -d, d), v( d, d, -d), v( d, d, d), ColorRGBT( 0, 255, 128, transp));
/* side #4 of the cube */
AddTriangle(v(-d, -d, -d), v(-d, -d, d), v(-d, d, d), ColorRGBT(255, 255, 0, transp));
AddTriangle(v(-d, -d, -d), v(-d, d, d), v(-d, d, -d), ColorRGBT(255, 255, 0, transp));
/* side #5 of the cube (facing front) */
AddTriangle(v(-d, d, d, null, 0, 0), v( d, d, d, null, 65535, 0), v( d, d, -d, null, 65535, 65535), color_unused, texture_id);
AddTriangle(v(-d, d, d, null, 0, 0), v( d, d, -d, null, 65535, 65535), v(-d, d, -d, null, 0, 65535), color_unused, texture_id);
/* side #6 of the cube */
AddTriangle(v( d, -d, d), v(-d, -d, -d), v( d, -d, -d), ColorRGBT( 0, 255, 0, transp));
AddTriangle(v( d, -d, d), v(-d, -d, d), v(-d, -d, -d), ColorRGBT( 0, 255, 0, transp));
}
local doc_texture = CDTDocumentBasic(null, DV_DOC_TEMP); // first make a temporary INTEGRAL document that will hold a texture for our 3D model */
doc_texture.Make();
doc_texture.Cleanup();
local model = CDTModel3D(); // now make a new 3D model */
/* add a new texture to our 3D model */
local texture_alpha = 20;
local texture_w = 680;
local texture_h = 700
local doc_scale = 1.0;
local doc_page = 0;
local doc_x = 0;
local doc_y = 0;
local texture_1 = model.AddTextureRGBT(DR_3D_TEXTURETYPE_MIPMAP, DR_3D_TEXTUREFORMAT_1BPP_P, texture_alpha, texture_w, texture_h, doc_texture, doc_scale, doc_page, doc_x, doc_y, [0, 0, 80, 0], [255, 128, 0, 0]);
/* our 3D model will consist of two intersecting objects: 1) a partially transparent pyramid; 2) a cube with a texture */
model.AddPyramid(20, 40);
model.AddCube(texture_1, 0);
/* set camera */
model.SetPos(1.0, 4.5, 42.0); // (x, y, z) location of camera in model space
model.SetRot(-30.0, 30.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(64, 64, 64); // 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 result = model.Render(DR_3D_RENDER_PNG, 900, 600); // export model to PNG image
Version 3 — Semi-Transparent Grayscale Texture (Export As PDF Document)
▸ 3d-texture-c.i
::my.include("../../common/includes/integral/doc-base.i");
::my.include("../../common/includes/integral/doc-pict.i");
function CDTDocumentBasic::Make()
{
/* lambda shortcuts */
local o = @(label = "") CDTObj(this, label); /* to make object */
local s = @(id, str) CDTPropStr(id, str); /* to add property - string */
local i = @(id, num) CDTPropInt(id, num); /* to add property - integer */
local l = @(id, obj) CDTLink(id, obj); /* to add link */
/* objects and their properties */
local o00 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o01 = o("Ellipse Body Color") + s(pdRGBT, "FFFF0000");
local o02 = o("Ellipse Shadow Color") + s(pdRGBT, "80808078");
local o03 = o("Ellipse Outline") + l(pdStylePtr, o00) + i(pdLineThickness, 340);
local o04 = o("Ellipse Shadow") + l(pdStylePtr, o02) + i(pdShadowDx, 5) + i(pdShadowDy, 5);
local o05 = o("Ellipse") + i(pdDw, 480) + i(pdDh, 480) + l(pdBodyPtr, o01) + l(pdOutlinePtr, o03) + l(pdShadowPtr, o04);
local o06 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o07 = o("Ellipse Body Color") + s(pdRGBT, "FFFFFF00");
local o08 = o("Ellipse Outline") + i(pdLineThickness, 340) + l(pdStylePtr, o06);
local o09 = o("Ellipse") + l(pdOutlinePtr, o08) + l(pdBodyPtr, o07) + i(pdDw, 140) + i(pdDh, 140);
local o10 = o("Arc Color") + s(pdRGBT, "50641400");
local o11 = o("Arc Line Width") + l(pdStylePtr, o10) + i(pdLineThickness, 1700);
local o12 = o("Arc") + l(pdLinePtr, o11) + i(pdAngleTheta, 120) + i(pdAngleAlpha, 30) + i(pdRadiusHor, 160) + i(pdRadiusVer, 160);
local o13 = o("Ellipse Outline Color") + s(pdRGBT, "50641400");
local o14 = o("Ellipse Body Color") + s(pdRGBT, "FFC01400");
local o15 = o("Ellipse Outline") + i(pdLineThickness, 240) + l(pdStylePtr, o13);
local o16 = o("Ellipse") + l(pdOutlinePtr, o15) + l(pdBodyPtr, o14) + i(pdDh, 130) + i(pdDw, 160);
local o17 = o("Ellipse Body Color") + s(pdRGBT, "50641400");
local o18 = o("Ellipse") + l(pdBodyPtr, o17) + i(pdDw, 70) + i(pdDh, 70);
local o19 = o("TextLine Typography") + s(pdFontUniqueID, "F0011_STIX1__NS0") + i(pdFontDw, 70) + i(pdFontDh, 100) + l(pdBodyPtr, o17);
local o20 = o("TextLine Layout") + i(pdAlignEnd, 1);
local o21 = o("TextLine") + s(pdTextString_08, "Hello INTEGRAL!") + l(pdTypographyPtr, o19) + l(pdTextLayoutPtr, o20);
/* image placement */
o05.Pin(0, 100, 170, pdDrawEllipse);
o09.Pin(0, 180, 250, pdDrawEllipse);
o12.Pin(0, 340, 410, pdDrawArc);
o18.Pin(0, 205, 260, pdDrawEllipse);
o09.Pin(0, 360, 250, pdDrawEllipse);
o18.Pin(0, 385, 260, pdDrawEllipse);
o16.Pin(0, 260, 340, pdDrawEllipse);
o21.Pin(0, 340, 120, pdDrawTextLine);
}
function CDTModel3D::TransformedVertex(v, default_color = 0)
{
return CDTVertex3D(8.0 * v.X, -8.0 * v.Z, 8.0 * v.Y, ((v.Color == null) ? default_color : v.Color), v.U, v.V);
}
function CDTModel3D::AddTriangle(v0, v1, v2, default_color = 0, texture_id = 0, texture_quality = DR_3D_TEXTUREQUALITY_SMOOTH_B)
{
AddElement(TransformedVertex(v0, default_color), TransformedVertex(v1, default_color), TransformedVertex(v2, default_color), default_color, texture_id, texture_quality);
}
function CDTModel3D::AddPyramid(transp_base = 0, transp_side = 0)
{
local v = @(x, y, z, rgbt = null) CDTVertex3D(x, y, z, rgbt); // a small labmda shortcut
local d = 1.7; // length of the pyramid side in model space
/* base of the pyramid */
AddTriangle(v(-d, -d, d), v( d, -d, d), v( d, d, d), ColorRGBT(128, 128, 0, transp_base));
AddTriangle(v(-d, -d, d), v( d, d, d), v(-d, d, d), ColorRGBT(128, 128, 0, transp_base));
/* 4 sides of the pyramid */
AddTriangle(v( d, -d, d), v( 0, 0, -d), v( d, d, d), ColorRGBT( 64, 128, 0, transp_side));
AddTriangle(v( 0, 0, -d), v(-d, -d, d), v(-d, d, d), ColorRGBT( 0, 128, 128, transp_side));
AddTriangle(v(-d, d, d), v( d, d, d), v( 0, 0, -d), ColorRGBT( 0, 128, 64, transp_side));
AddTriangle(v( d, -d, d), v(-d, -d, d), v( 0, 0, -d), ColorRGBT( 0, 128, 0, transp_side));
}
function CDTModel3D::AddCube(texture_id, transp = 0)
{
local v = @(x, y, z, rgbt = null, u = 0, v = 0) CDTVertex3D(x, y, z, rgbt, u, v); // a small labmda shortcut
local d = 1.0; // length of the cube d in model space
local color_unused = ColorRGBT(192, 192, 192, 0);
/* side #1 of the cube */
AddTriangle(v(-d, -d, d), v(d, -d, d), v( d, d, d), ColorRGBT(128, 255, 0, transp));
AddTriangle(v(-d, -d, d), v(d, d, d), v(-d, d, d), ColorRGBT(128, 255, 0, transp));
/* side #2 of the cube */
AddTriangle(v( d, -d, -d), v(-d, -d, -d), v(-d, d, -d), ColorRGBT( 0, 128, 255, transp));
AddTriangle(v( d, -d, -d), v(-d, d, -d), v( d, d, -d), ColorRGBT( 0, 128, 255, transp));
/* side #3 of the cube */
AddTriangle(v( d, -d, d), v( d, -d, -d), v( d, d, -d), ColorRGBT( 0, 255, 128, transp));
AddTriangle(v( d, -d, d), v( d, d, -d), v( d, d, d), ColorRGBT( 0, 255, 128, transp));
/* side #4 of the cube */
AddTriangle(v(-d, -d, -d), v(-d, -d, d), v(-d, d, d), ColorRGBT(255, 255, 0, transp));
AddTriangle(v(-d, -d, -d), v(-d, d, d), v(-d, d, -d), ColorRGBT(255, 255, 0, transp));
/* side #5 of the cube (facing front) */
AddTriangle(v(-d, d, d, null, 0, 0), v( d, d, d, null, 65535, 0), v( d, d, -d, null, 65535, 65535), color_unused, texture_id);
AddTriangle(v(-d, d, d, null, 0, 0), v( d, d, -d, null, 65535, 65535), v(-d, d, -d, null, 0, 65535), color_unused, texture_id);
/* side #6 of the cube */
AddTriangle(v( d, -d, d), v(-d, -d, -d), v( d, -d, -d), ColorRGBT( 0, 255, 0, transp));
AddTriangle(v( d, -d, d), v(-d, -d, d), v(-d, -d, -d), ColorRGBT( 0, 255, 0, transp));
}
local doc_texture = CDTDocumentBasic(null, DV_DOC_TEMP); // first make a temporary INTEGRAL document that will hold a texture for our 3D model */
doc_texture.Make();
doc_texture.Cleanup();
local model = CDTModel3D(); // now make a new 3D model */
/* add a new texture to our 3D model */
local texture_alpha = 20;
local texture_w = 680;
local texture_h = 700
local doc_scale = 1.0;
local doc_page = 0;
local doc_x = 0;
local doc_y = 0;
local texture_1 = model.AddTextureRGBT(DR_3D_TEXTURETYPE_MIPMAP, DR_3D_TEXTUREFORMAT_1BPP_P, texture_alpha, texture_w, texture_h, doc_texture, doc_scale, doc_page, doc_x, doc_y, [0, 0, 80, 0], [255, 128, 0, 0]);
/* our 3D model will consist of two intersecting objects: 1) a partially transparent pyramid; 2) a cube with a texture */
model.AddPyramid(20, 40);
model.AddCube(texture_1, 0);
/* set camera */
model.SetPos(1.0, 4.5, 42.0); // (x, y, z) location of camera in model space
model.SetRot(-30.0, 30.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(64, 64, 64); // 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();
local result = model.ToDocument(doc, page_w, page_h, margin_w, margin_h); // embed 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