PHP Classes

PHP 3D Model Viewer Class: Render a 3D object from the shapes definitions

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 128 This week: 1All time: 9,371 This week: 89Up
Version License PHP version Categories
model-3d-class 1.0Custom (specified...5PHP 5, Graphics, Physics
Description 

Author

This class can render a 3D object from the shapes definitions

It takes a list of nodes of the edges and lines of the model of a 3D object and renders an image that shows the lines and the edges of the described object. The class can also add lines for the ground plane.

The the rendered image of the 3D model object is stored in a class variable that is set to a image object created by the PHP GD extension.

Picture of Win Aung Cho
  Performance   Level  
Name: Win Aung Cho is available for providing paid consulting. Contact Win Aung Cho .
Classes: 11 packages by
Country: Myanmar Myanmar
Age: 60
All time rank: 25114 in Myanmar Myanmar
Week rank: 53 Up1 in Myanmar Myanmar Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

include("model3d.php");
$model3d = new Model3D();
$model3d->drawGridXY(80, 80);
gen($model3d);
$model3d->drawOrigin();


header("Content-type: image/png");
imagepng($model3d->canvas);
imagedestroy($imgcanvas->canvas);

function
gen($model)
    {
   
// generate nodes and lines for a truss3d
       
$node = array();
       
$line = array();
       
$n = 4; // no of in-scribed polygon sides
       
$m = 2; // no of storey
       
$dh =200; // height of each storey
       
$r = 120; // radius of polygon
       
$dr = -20; // reduce radius per storey
       
$dang = 360/$n;
       
$startang = $dang/2;
       
        for (
$j=0;$j<$m+1;$j++){
            for(
$i=0;$i<$n;$i++){
               
$ang = $startang+$i*$dang;
               
$ang = $ang/180.0*pi();
               
$x = ($r+$dr*$j)*cos($ang);
               
$y = ($r+$dr*$j)*sin($ang);
               
$z = $j*$dh;
               
               
$node[] = array(
                   
"x" => $x,
                   
"y" => $y,
                   
"z" => $z,
                   
"dof" => "000",
                   
"dx" => 0.00,
                   
"dy" => 0.00,
                   
"dz" => 0.0
               
);
               
               
$i1 = ($i+$n*$j)%$n;
               
$j1 = ($i+$n*$j+1)%$n;
                if (
$j < $m){
               
$line[] = array(
                   
"I" => $n*($j+1)+$i1,
                   
"J" => $n*($j+1)+$j1,
                   
"Mat" => 0,
                   
"Sec" => 0
               
);
               
$line[] = array(
                   
"I" => $n*$j+$i1,
                   
"J" => $n*($j+1)+$i1,
                   
"Mat" => 0,
                   
"Sec" => 0
               
);
               
$line[] = array(
                   
"I" => $n*$j+$i1,
                   
"J" => $n*($j+1)+$j1,
                   
"Mat" => 0,
                   
"Sec" => 0
               
);
                }
               
            }
        }
       
       
$model->drawNodesLine($node, $line);
}
?>


Details

PHP-Model3D-Class

3dimensional perspective drawing class

##Model3DClass

* [Model3D] class create 3 dimensional perspective view by projecting 3d coordinate system onto 2d canvas. * Current model provide 2 modes, z axis vertical and y axis vertical. * This simplest first version implement only 3 dimensional line drawing and wire frame that include 3d nodes and connected lines. * 3D object is centeted at PROJECTION_CENTER center point on the canvas view. View rotation is defined with $ROT about vertical axis. * Coordinate system obey right-hand-rule.

##Sample 1. Drawtower1.php is a sample file that use Model3D class and create 3d trustal tower. 2. index.php is a sample for the html file.

##Permission * This class is free for the educational use as long as maintain this header together with this class. Contact author for other uses.

* Author: Win Aung Cho * Contact winaungcho@gmail.com * version 1.0 * Date: 4-11-2020


Screenshots  
  • Screenshot_20201104-052828_Chrome.jpg
  Files folder image Files  
File Role Description
Accessible without login Plain text file drawtower1.php Example Example script
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Plain text file model3d.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:128
This week:1
All time:9,371
This week:89Up