<?php require_once __DIR__ . '/../../vendor/autoload.php'; // resize image according to this factor $factor = 5; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light = $world->createLight('Light', array(-4 * $factor, -4 * $factor, 0)); $light->setColor(new Image_3D_Color(255, 255, 255, 100)); $lightSphere = $world->createObject('sphere', array('r' => $factor, 'detail' => 0)); $lightSphere->transform($world->createMatrix('Move', array(-4 * $factor, -4 * $factor, 0))); $lightSphere->setColor(new Image_3D_Color(255, 255, 255, 100)); $light = $world->createLight('Light', array(4 * $factor, -4 * $factor, 0)); $light->setColor(new Image_3D_Color(255, 255, 255, 100)); $lightSphere = $world->createObject('sphere', array('r' => $factor, 'detail' => 0)); $lightSphere->transform($world->createMatrix('Move', array(4 * $factor, -4 * $factor, 0))); $lightSphere->setColor(new Image_3D_Color(255, 255, 255, 100)); $p = array(); $bottom = $world->createObject('polygon', array(new Image_3D_Point(-5 * $factor, 3 * $factor, 5 * $factor), new Image_3D_Point(-5 * $factor, 3 * $factor, -5 * $factor), new Image_3D_Point(5 * $factor, 3 * $factor, -5 * $factor), new Image_3D_Point(5 * $factor, 3 * $factor, 5 * $factor))); $bottom->setColor(new Image_3D_Color(200, 200, 200, 0, 0.6)); $top = $world->createObject('polygon', array(new Image_3D_Point(-5 * $factor, 5 * $factor, 5 * $factor), new Image_3D_Point(5 * $factor, 5 * $factor, 5 * $factor), new Image_3D_Point(5 * $factor, -5 * $factor, 5 * $factor), new Image_3D_Point(-5 * $factor, -5 * $factor, 5 * $factor))); $top->setColor(new Image_3D_Color(200, 200, 200, 0, 0.5)); $redPlane = $world->createObject('polygon', array(new Image_3D_Point(-5 * $factor, 1 * $factor, 2 * $factor), new Image_3D_Point(-5 * $factor, 1 * $factor, -2 * $factor), new Image_3D_Point(-1 * $factor, -1 * $factor, -2 * $factor), new Image_3D_Point(-1 * $factor, -1 * $factor, 2 * $factor))); $redPlane->setColor(new Image_3D_Color(255, 0, 0, 100, 0)); $bluePlane = $world->createObject('polygon', array(new Image_3D_Point(5 * $factor, 1 * $factor, 2 * $factor), new Image_3D_Point(5 * $factor, 1 * $factor, -2 * $factor), new Image_3D_Point(1 * $factor, -1 * $factor, -2 * $factor), new Image_3D_Point(1 * $factor, -1 * $factor, 2 * $factor))); $bluePlane->setColor(new Image_3D_Color(100, 100, 255, 0, 0)); $world->transform($world->createMatrix('Rotation', array(10, 0, 0))); if (!@$argv[1]) { // Create normal GD picture with projection echo "Render with projection.\n"; $renderer = $world->createRenderer('perspectively');
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(0, 0, 0)); $light1 = $world->createLight('Light', array(-300, 0, -300)); $light1->setColor(new Image_3D_Color(252, 175, 62)); $light2 = $world->createLight('Light', array(300, -300, -300)); $light2->setColor(new Image_3D_Color(164, 0, 0)); $count = 3; $size = 20; $offset = 10; for ($x = -($count - 1) / 2; $x <= ($count - 1) / 2; ++$x) { for ($y = -($count - 1) / 2; $y <= ($count - 1) / 2; ++$y) { for ($z = -($count - 1) / 2; $z <= ($count - 1) / 2; ++$z) { // if (max(abs($x), abs($y), abs($z)) < ($count - 1) / 2) continue; if (max($x, $y, $z) <= 0) { continue; } $cube = $world->createObject('quadcube', array($size, $size, $size)); $cube->setColor(new Image_3D_Color(255, 255, 255, 75)); $cube->transform($world->createMatrix('Move', array($x * ($size + $offset), $y * ($size + $offset), $z * ($size + $offset)))); } } } $world->transform($world->createMatrix('Rotation', array(220, 50, 0))); $world->transform($world->createMatrix('Scale', array(2, 2, 2))); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, true); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $world->createRenderer('perspectively');
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light = $world->createLight('Light', array(-2000, -2000, -2000)); $light->setColor(new Image_3D_Color(255, 255, 255)); $redSpot = $world->createLight('Spotlight', array(0, 0, -200, 'aim' => array(0, -25, 0), 'angle' => 30, 'float' => 2)); $redSpot->setColor(new Image_3D_Color(255, 0, 0)); $blueSpot = $world->createLight('Spotlight', array(0, 0, -200, 'aim' => array(-35, 25, 0), 'angle' => 30, 'float' => 2)); $blueSpot->setColor(new Image_3D_Color(0, 0, 255)); $greenSpot = $world->createLight('Spotlight', array(0, 0, -200, 'aim' => array(35, 25, 0), 'angle' => 30, 'float' => 2)); $greenSpot->setColor(new Image_3D_Color(0, 255, 0)); $map = $world->createObject('map'); $detail = 80; $size = 200; $height = 40; $raster = 1 / $detail; for ($x = -1; $x <= 1; $x += $raster) { $row = array(); for ($y = -1; $y <= 1; $y += $raster) { $row[] = new Image_3D_Point($x * $size, $y * $size, sin($x * pi()) * sin($y * 2 * pi()) * $height); } $map->addRow($row); } $map->setColor(new Image_3D_Color(150, 150, 150, 0)); $world->transform($world->createMatrix('Rotation', array(-20, 10, -10))); $world->createRenderer('perspectively'); $world->createDriver('GD'); $world->render(400, 400, 'Image_3D_Spotlights.png');
<?php $images = 'php://output'; $iterations = 50; set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(0, 0, 0)); $light1 = $world->createLight('Light', array(-500, -500, -500)); $light1->setColor(new Image_3D_Color(255, 255, 255)); $light2 = $world->createLight('Light', array(0, 500, -550)); $light2->setColor(new Image_3D_Color(0, 255, 0)); $p1 = $world->createObject('cube', array(80, 80, 80)); $p1->setColor(new Image_3D_Color(200, 200, 200)); $p1->transform($world->createMatrix('Rotation', array(45, 45, 0))); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $rotation = $world->createMatrix('Rotation', array(2, 5, 0)); $renderer = $world->createRenderer('perspectively'); $driver = $world->createDriver('ASCII'); $world->render(2 * 80, 6 * 30, $images); $start = microtime(true); $i = 0; while ($i++ < $iterations) { $p1->transform($rotation); $driver->reset(); $renderer->render($images); } $time = microtime(true) - $start; printf("%2.2f fps\n", $iterations / $time);
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light1 = $world->createLight('Light', array(-20, -20, -20)); $light1->setColor(new Image_3D_Color(255, 255, 255)); $light2 = $world->createLight('Light', array(20, 20, -20)); $light2->setColor(new Image_3D_Color(0, 200, 0)); $map = $world->createObject('map'); $detail = 30; $size = 150; $height = 40; $raster = 1 / $detail; for ($x = -1; $x <= 1; $x += $raster) { $row = array(); for ($y = -1; $y <= 1; $y += $raster) { $row[] = new Image_3D_Point($x * $size, $y * $size, sin($x * pi()) * sin($y * 2 * pi()) * $height); } $map->addRow($row); } $map->setColor(new Image_3D_Color(150, 150, 150, 0)); $map->transform($world->createMatrix('Rotation', array(-40, 20, -10))); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $world->createRenderer('perspectively'); $world->createDriver('GD'); $world->render(400, 400, 'Image_3D_Object_Map.png'); echo $world->stats();
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light = $world->createLight('Light', array(-2000, -2000, -2000)); $light->setColor(new Image_3D_Color(255, 255, 255)); $redLight = $world->createLight('Light', array(90, 0, 50)); $redLight->setColor(new Image_3D_Color(255, 0, 0)); $sphere = $world->createObject('sphere', array('r' => 150, 'detail' => 4)); $sphere->setColor(new Image_3D_Color(150, 150, 150)); $renderer = $world->createRenderer('perspectively'); $world->createDriver('GD'); $world->render(400, 400, 'example.png'); echo $world->stats();
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light = $world->createLight('Light', array(-2000, -2000, -2000)); $light->setColor(new Image_3D_Color(0, 0, 255)); $cone = $world->createObject('cone', array('detail' => 1)); $cone->setColor(new Image_3D_Color(255, 255, 255, 200)); $cone->transform($world->createMatrix('Scale', array(100, 400, 100))); $cone->transform($world->createMatrix('Move', array(0, -80, 0))->multiply($world->createMatrix('Rotation', array(150, 30, 30)))); $world->createRenderer('perspectively'); $world->createDriver('SVG'); $world->render(400, 400, 'Image_3D_Object_Cone_2.svg'); echo $world->stats();
<?php require_once __DIR__ . '/../../vendor/autoload.php'; // Erstellen der Welt $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); // Erstellung einer globalen Lichtquelle $light = $world->createLight('Light', array(-2000, -2000, -2000)); $light->setColor(new Image_3D_Color(155, 155, 155)); // Eines Punktuellen Lichtes mit distancefalloff $light = $world->createLight('Point', array(0, -100, 0, 'distance' => 200, 'falloff' => 2)); $light->setColor(new Image_3D_Color(255, 0, 0)); // Eines Spotlights $light = $world->createLight('Spotlight', array(500, -500, -300, 'aim' => array(50, 30, 0), 'angle' => 10, 'float' => 2)); $light->setColor(new Image_3D_Color(0, 255, 0, 100)); // Erstellen einer Kugel $sphere = $world->createObject('sphere', array('r' => 120, 'detail' => 5)); $sphere->setColor(new Image_3D_Color(200, 200, 200)); $sphere->transform($world->createMatrix('Move', array(70, 40, 0))); // Import eines 3ds-Objekts (Schriftzug "Image 3D") $text = $world->createObject('3ds', __DIR__ . '/models/Image_3D.3ds'); $text->setColor(new Image_3D_Color(255, 255, 255, 180)); $text->transform($world->createMatrix('Rotation', array(90, 0, 0))); $text->transform($world->createMatrix('Scale', array(5, 5, 5))); $text->transform($world->createMatrix('Move', array(0, -40, 0))); // Transformationen auf alle Objecte anwenden $text->transform($world->createMatrix('Scale', array(2, 2, 2))); // Erzeugen des gewuenschten Renderers $world->createRenderer('perspectively'); // Erzeugen des gewuenschten Ausgabetreibers $world->createDriver('SVG');
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(255, 255, 255)); $light = $world->createLight('Light', array(0, 1000, 1000)); $light->setColor(new Image_3D_Color(255, 255, 255)); $pie = $world->createObject('pie', array('start' => 0, 'end' => 120, 'detail' => 20, 'outside' => 150)); $pie->setColor(new Image_3D_Color(0, 0, 255)); $pie = $world->createObject('pie', array('start' => 120, 'end' => 165, 'detail' => 20, 'outside' => 150)); $pie->setColor(new Image_3D_Color(255, 0, 0)); $pie = $world->createObject('pie', array('start' => 165, 'end' => 240, 'detail' => 20, 'outside' => 150)); $pie->setColor(new Image_3D_Color(255, 255, 0)); $pie = $world->createObject('pie', array('start' => 240, 'end' => 360, 'detail' => 20, 'outside' => 150)); $pie->setColor(new Image_3D_Color(0, 255, 0)); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $world->transform($world->createMatrix('Scale', array(1, 1, 10))); $world->transform($world->createMatrix('Rotation', array(-60, 0, 0))); $world->createRenderer('perspectively'); $world->createDriver('ZBuffer'); $world->render(400, 400, 'Image_3D_Object_Pie.png'); echo $world->stats();
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(250, 250, 250)); $light = $world->createLight('Point', array(0, -200, 0, 'distance' => 300, 'falloff' => 2)); $light->setColor(new Image_3D_Color(150, 150, 255)); $steps = 10; $step = 20; for ($i = 0; $i < $steps; ++$i) { $y = $steps * $step / -2 + $i * $step; $p = $world->createObject('polygon', array(new Image_3D_Point(-100, $y, -30), new Image_3D_Point(-100, $y, 50), new Image_3D_Point(100, $y, 40))); $p->setColor(new Image_3D_Color(255, 255, 255)); } $world->transform($world->createMatrix('Rotation', array(20, 0, 0))); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, false); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $world->createRenderer('perspectively'); $world->createDriver('ZBuffer'); $world->render(400, 400, 'Image_3D_Pointlight.png'); echo $world->stats();
<?php set_time_limit(0); require_once __DIR__ . '/../../vendor/autoload.php'; $world = new Image_3D(); $world->setColor(new Image_3D_Color(240, 240, 240)); $light = $world->createLight('Light', array(0, 0, -500)); $light->setColor(new Image_3D_Color(255, 255, 255)); $cube = $world->createObject('quadcube', array(150, 150, 150)); $cube->setColor(new Image_3D_Color(50, 50, 250, 200)); $cube_s1 = $world->createObject('quadcube', array(150, 150, 150)); $cube_s1->subdivideSurfaces(1); $cube_s1->setColor(new Image_3D_Color(50, 50, 250, 170)); $cube_s2 = $world->createObject('quadcube', array(150, 150, 150)); $cube_s2->subdivideSurfaces(2); $cube_s2->setColor(new Image_3D_Color(50, 50, 250, 50)); $world->transform($world->createMatrix('Rotation', array(15, 15, 0))); $world->setOption(Image_3D::IMAGE_3D_OPTION_BF_CULLING, true); $world->setOption(Image_3D::IMAGE_3D_OPTION_FILLED, true); $world->createRenderer('perspectively'); $world->createDriver('GD'); $world->render(400, 400, 'Image_3D_Quadcube.png'); echo $world->stats();