@filemtime($m3d)) { if($path['extension'] == "m3d") { copy($in."/".$line[0], $m3d); } else $cmd = "../m3dconv/m3dconv -i".$line[1]." ". "-n ".escapeshellarg($line[2])." -l ".escapeshellarg($line[3])." -a ".escapeshellarg($line[4])." ". escapeshellarg($in."/".$line[0])." ".escapeshellarg($m3d)." && "; } $p = popen($cmd."../m3dview/m3dview ".escapeshellarg($m3d)." ".$png, "r"); $n = trim(fgets($p)); $l = trim(fgets($p)); $d = explode(",",trim(fgets($p))); pclose($p); $t = [$line[5]]; for($i=6;$i 65535 && !in_array("highres", $t)) $t[] = "highres"; if($d[12]) $d[0] = $d[2] = $d[6] = 0; return ["n"=>$n,"p"=>$path['filename'],"s"=>filesize($dir."/models/".$path['filename'].".m3d"), "l"=>$l==","?"Public Domain":$l,"f"=>$d[0],"u"=>$d[1],"o"=>$d[2],"h"=>$d[3],"U"=>$d[4],"O"=>$d[5],"v"=>$d[6], "m"=>$d[7],"t"=>$d[8],"b"=>$d[9],"a"=>$d[10],"L"=>$d[11],"V"=>$d[12],"c"=>$t]; } function safename($n) { if(mb_substr($n,1,1) == " ") $n = mb_substr($n, 2); return htmlspecialchars(mb_strtolower($n)); } function nicename($n) { if(mb_substr($n,1,1) == " ") { $p = mb_substr($n, 0, 2); $n = mb_substr($n, 2); } else { $p = ""; } return htmlspecialchars($p.mb_strtoupper(mb_substr($n, 0, 1)).mb_substr($n, 1)); } /* check arguments */ if(empty($_SERVER['argv'][2])) { die("Model 3D Homepage and Model Catalog Generator\n\nphp catalog.php \n\n". "CSV: file,convopts,name,license,author,category,tags\n"); } /* parse input csv and convert models */ $models = []; $cat = []; if(($f = fopen($_SERVER['argv'][1], "r")) !== FALSE) { for($n = 0; fgets($f) !== FALSE && !feof($f); $n++); fseek($f, 0); $l = 0; @mkdir($_SERVER['argv'][2]."/models"); mb_internal_encoding("UTF-8"); while(($line = fgetcsv($f)) !== FALSE && count($line) > 5) { echo("\r".round(++$l*100/$n, 2)."% -i".$line[1]." ".$line[0]." "); if($line[0][0]=='#') continue; $data = convertmodel($line, dirname($_SERVER['argv'][1]), $_SERVER['argv'][2]); $models[] = $data; $cat[$data["c"][0]] = 1; } fclose($f); echo("\r "); echo("\rDone. ".count($models)." models in ".count($cat)." categories.\n"); } if(empty($models)) die(); usort($models, function($a, $b){ return strnatcasecmp($a["n"], $b["n"]); }); $cat = array_keys($cat); /* generate index.html */ $f = fopen($_SERVER['argv'][2]."/index.html", "w"); fwrite($f, ' Model 3D

Welcome to Model 3D!

Model 3D is an application and engine neutral, universal 3D model format to store CAD models, meshes, skeletal animations and voxel images. It comes with a dependency-free, single header ANSI C/C++ SDK.

The file format and the SDK is Open Source and free as in free beer! Licensed under MIT license.

Compact

The format has the best data density of all the available 3D model formats (including CAD), easy on network traffic. Parsing is painless and lightning fast.

Animations

It can store multiple skeleton-based animations in a model file (so called actions). The SDK makes it easy to get the animation-pose for each.

Procedural

Model 3D is capable of storing procedural textures and faces. Any scripting language can be used, the SDK ships Lua binding as a Proof of Concept.

Integration

Extremely easy to integrate into any project. A Blender plugin is provided to export M3D models, which can be also loaded with the Assimp library.

Embeddable on webpages

With the WebGL polyfill, you can include Model 3D files in webpages just like normal 2D images! Hint: drag the images below!

demo
<img src="cube.m3d" width="300" height="300">
demo
<img src="suzanne.m3d" width="300" height="300">
demo
<img src="voxelimg.m3d" width="300" height="300">

Easy to use Software Development Kit

  • The M3D SDK is an stb-style, dependency-free single header file written in ANSI C89, licensed under MIT.
  • If you prefer, the SDK can provide a C++11 wrapper class around the C API, or you can write your own.
  • You can configure the SDK using defines to add ASCII format support or model exporting functionality.
  • You don\'t have to worry about the textures, the SDK will decompress PNG textures for you on its own (no library needed).
  • Unlike other 3D model SDKs, the in-memory format is simple, your code that interfaces with it can be extremely simple.
  • Follows the K.I.S.S. principle, there\'re only 5 functions in the API.
  • The API manual provides you with detailed description and SDK usage examples.
  • You can integrate the m3dconv utility into your build environment to convert foreign models in compilation time.
  • There\'s a simple model viewer, which demonstrates how to display animated models using the M3D SDK.

Convert Anything into Model 3D

  • The Blender Import/Export plugin makes it possible to directly save models into Model 3D format.
  • With the m3dconv command line tool you can convert almost any existing model into Model 3D easily:
  • Fully supports Wavefront OBJ (including negative indices, Bezier curves / surfaces, B-spline and NURBS), and a STEP (ISO-10303-21-4 / ISO-10303-24-2) file importer is on the way.
  • Voxel images, like BINVOX files, Minecraft Schematic files, Magicavoxel VOX files and Qubicle QB files can be converted too efficiently.
  • FBX support via the uFBX library (included).
  • glTF/glB support via the cglTF single header library (included).
  • Other supported formats via Assimp (not included): 3DS, 3DS MAX, X, ASE, BLEND, COLLADA (DAE), B3D, MS3D, MD5, MESH, STL, PLY and many many more...

Projects using Model 3D

  • Goxel2 a very capable voxel editor has choosen M3D as its primary format (fork of Goxel).
  • raylib a multiplatform, simple and easy-to-use programming library to enjoy videogames programming.
(Open an issue if you want your project to be listed here.)

Model 3D Samples

'); for($i = 0; $i < count($models); $i++) { $s = $models[$i]["s"]; $u = " bytes"; if($s < 8) continue; if($s > 1023) { $s = floor(($s + 1023)/1024); $u = " Kib"; } fwrite($f, '
'.htmlspecialchars($models[$i]["n"]).'
DownloadDownload
'.htmlspecialchars($models[$i]["n"]).'

'.htmlspecialchars($models[$i]["l"]).'

File'.htmlspecialchars($models[$i]["p"]).'.m3d ('.number_format($s,0,""," ").$u.')
Polygons'.($models[$i]["u"]?' UV':'').($models[$i]["o"]?' Normals':'').''.number_format($models[$i]["f"],0,""," ").'
Shapes'.($models[$i]["U"]?' UV':'').($models[$i]["O"]?' Normals':'').''.number_format($models[$i]["h"],0,""," ").'
Vertices'.number_format($models[$i]["v"],0,""," ").'
Voxels'.number_format($models[$i]["V"],0,""," ").'
Materials0?'success">Yes':'danger">No').'
Textures inlined0?'success">Yes':'danger">No').'
Rigged (bones + skin)0?'success">Yes':'danger">No').'
Animated0?'success">Yes':'danger">No').'
'); foreach($models[$i]["c"] as $c) fwrite($f, ' '.safename($c).''."\n"); fwrite($f, '
'); } fwrite($f, '

Copyright © bzt (bztsrc@gitlab) 2019.

'); fclose($f);