Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: 7.x-1.x
Fetching contributors…

Cannot retrieve contributors at this time

212 lines (182 sloc) 6.638 kb
<?php
/**
* Implement hook_menu.
*/
/*function media_model_menu()
{
return array(
'file/%/3d' => array(
'page callback' => 'media_model_modelview',
'page arguments' => array(1),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
),
);
}
function media_model_modelview($fid) {
return $fid;
}*/
function media_model_file_view_alter(&$build, $type = 'file') {
// check to make sure it's a file type we support
if (!isset($build['file']['#file']))
return;
$filename = $build['file']['#file']->filename;
$extension = substr($filename, strlen($filename)-4);
if ($extension != '.obj' && $extension != '.md2')
return;
$build['file']['#file']->type = 'model';
$build['file']['#theme'] = 'model';
}
/**
* Implements hook_library().
*/
/*function media_model_library() {
$path = libraries_get_path('GLGE');
$libraries = array();
$libraries['GLGE'] = array(
'title' => 'GLGE WebGL Engine',
'website' => 'http://glge.org/',
'version' => '0.9',
'js' => array(
// The mediaelement script detects the path to itself to call other files
// in the same location. With preprocessing this is problematic as the
// script is no longer in the same directory as its other assets. There
// is an option that can be passed into the script with its location.
// @todo Update all calls to mediaelement to pass in the assets location.
$path . '/glge-compiled.js' => array('group' => JS_LIBRARY, 'preprocess' => FALSE),
),
);
return $libraries;
}*/
/**
* Implements hook_file_type_info().
*/
/*function media_model_file_type_info() {
return array(
'model_obj' => array(
'label' => t('3D Model in .OBJ format'),
'description' => t('A static polygonal 3D model'),
'claim callback' => 'media_model_file_type_model_claim',
'default view callback' => 'media_model_file_type_model_default_view',
'weight' => -1000,
),
);
}
function media_model_file_type_model_claim($file, $type) {
dpm($file);
return TRUE;
}
function media_model_file_type_model_default_view($file, $view_mode, $langcode) {
dpm($file);
return array(
'#type' => 'model',
'#title' => $file->filename . ' NOAHTESTING',
'#href' => file_create_url($file->uri),
);
}*/
/**
* Implements hook_file_formatter_info().
*/
function media_model_file_formatter_info() {
}
/**
* Implements hook_field_formatter_info().
*/
function media_model_field_formatter_info() {
$formatters = array();
$formatters['glge_objloader'] = array(
'label' => t('GLGE Wavefront .OBJ viewer'),
'field types' => array('file', 'model'),
'settings' => array(
'width' => variable_get('glge_objloader', '640'),
'height' => variable_get('glge_objloader', '385'),
),
);
return $formatters;
}
/**
* Implements hook_field_formatter_view().
*/
/*function media_model_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
//dpm($entity);
//dpm($display);
//dpm($items);
$element = array();
foreach ($items as $delta => $item) {
$settings = $display['settings'];
if ($display['type'] == 'glge_objloader') {
dpm($item);
$element[$delta] = array(
'#theme' => 'model',
'#file' => $item,
);
}
}
return $element;
}*/
/**
* Implements hook_theme().
*/
function media_model_theme($existing) {
//dpm($existing);
return array(
'model' => array(
/*'variables' => array(
'attributes' => array(),
'settings' => array(),
),*/
'render element' => 'element',
),
);
}
function theme_model($variables) {
//dpm($variables);
//drupal_set_message('<pre>theme_model variables: ' . print_r($variables, 1) . '</pre>');
//return 'GLGE';
// unique id per instance
//static $id=0;
drupal_add_js(libraries_get_path('GLGE') . '/glge-compiled.js', 'file');
$output = '<canvas class="glge-model" id="glge-model-' . time() . '-' . $variables['element']['#file']->fid . '" width="640" height="480">';
$output .= '</canvas>';
$output .=
//'<script id="glge-document" id="glge-document-' . time() . '-' . $id . '" type="text/xml">
'<script id="glge-document" type="text/xml"><glge>
<mesh id="xline"><positions>-1000.0,0,0,1000.0,0.0,0.0</positions></mesh>
<mesh id="yline"><positions>0,-1000,0,0,1000,0</positions></mesh>
<mesh id="zline"><positions>0,0,-1000,0,0,1000</positions></mesh>
<material id="mat" specular="0">
<texture id="ogrocolour" src="skin.jpg" />
<!-- <material_layer texture="#ogrocolour" mapinput="UV1" mapto="M_COLOR" /> -->
</material>
<material id="red" specular="0" color="#f00" shadeless="1" />
<material id="green" specular="0" color="#0f0" shadeless="1" />
<material id="blue" specular="0" color="#00f" shadeless="1" />
<material id="lines" specular="0" color="#777" shadeless="1" />
<material id="distance" specular="0" color="#ffff00" shadeless="1" />
<scene id="mainscene" ambient_color="#333" background_color="#888" fog_near="50" fog_far="60" fog_color="#555" fog_type="FOG_LINEAR" camera="#mainCamera">
<group id="graph">
<object id="xaxis" draw_type="DRAW_LINES" line_width="2" mesh="#xline" material="#red" />
<object id="yaxis" draw_type="DRAW_LINES" line_width="2" mesh="#yline" material="#green" />
<object id="zaxis" draw_type="DRAW_LINES" line_width="2" mesh="#zline" material="#blue" />
</group>
<group id="cameraOffset">
<camera id="mainCamera" loc_z="20" loc_y="2.2" loc_x="0" rot_x="0" rot_y="0" />
</group>
$extension = substr($variables['element']['#file']->uri, strlen($filename)-4);
dpm($extension);
if ($extension == '.obj') {
$output .= '<wavefront src="' . file_create_url($variables['element']['#file']->uri) . '" id="model" scale="0.05" pickable="true"/>
';
} else if ($extension == '.md2') {
$output .= '<MD2 src="' . file_create_url($variables['element']['#file']->uri) . '" MD2_animation="MoveForward" id="model" scale="0.5" pickable="true"/>';
}
$output .='
<light id="light" loc_x="0" loc_y="20" loc_z="10" rot_x="0" rot_y="1.57" attenuation_constant="0.9" type="L_DIR" />
<light id="light" loc_x="-10" loc_y="20" loc_z="-5" rot_x="-1.3" attenuation_constant="5" type="L_POINT" />
<light id="light" loc_x="-10" loc_y="20" loc_z="10" rot_x="-1.3" attenuation_constant="5" type="L_POINT" />
</scene>
</glge>
</script>';
drupal_add_js(drupal_get_path('module', 'media_model') . '/media_model.js', 'file');
return $output;
}
Jump to Line
Something went wrong with that request. Please try again.