Blog Code Forum

WebGL:WordPress

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
(Page créée avec « === functions.php === <syntaxhighlight lang="php" line start="1"> <?php function gPrimitive( $atts ) { extract(shortcode_atts(array( 'gid' => '', 'style' => '', 'w... »)
Line 5: Line 5:
function gPrimitive( $atts ) {
function gPrimitive( $atts ) {
extract(shortcode_atts(array(
extract(shortcode_atts(array(
-
'gid' => '',
+
'gid' => 'cube.00000000',
-
'style' => '',
+
'vertices' => '
-
'width' => '640',
+
-0.5, -0.5, -0.5, // d
-
'height'=> '540',
+
+0.5, -0.5, -0.5, // c
-
'rgba' => '0.0, 0.0, 0.0, 1.0'), $atts));
+
-0.5, +0.5, -0.5, // a
 +
+0.5, +0.5, -0.5, // b
 +
-0.5, -0.5, +0.5, // h
 +
+0.5, -0.5, +0.5, // g
 +
-0.5, +0.5, +0.5, // e
 +
+0.5, +0.5, +0.5 // f
 +
',
 +
'indices' => '
 +
0, 1, 3, 2, // d c b a
 +
0, 4, 6, 2, // d h e a
 +
0, 4, 5, 1, // d h g c
 +
1, 5, 7, 3, // c g f b
 +
3, 2, 6, 7 // b a e f
 +
',
 +
'colors' =>
 +
'[
 +
[1.0, 0.0, 0.0, 1.0], // Front face
 +
[1.0, 1.0, 0.0, 1.0], // Back face
 +
[0.0, 1.0, 0.0, 1.0], // Top face
 +
[1.0, 0.5, 0.5, 1.0], // Bottom face
 +
[1.0, 0.0, 1.0, 1.0], // Right face
 +
[0.0, 0.0, 1.0, 1.0]  // Left face
 +
]',
 +
'style' => '',
 +
'width' => '640',
 +
'height' => '540',
 +
'rgba' => '0.0, 0.0, 0.0, 1.0'), $atts));
$output = '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/glMatrix-min.js"></script>'
$output = '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/glMatrix-min.js"></script>'
-
. '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/webgl-utils.js"></script>'
 
. '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/primitive.js"></script>';
. '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/primitive.js"></script>';
$main = '<script type="text/javascript">'
$main = '<script type="text/javascript">'
-
. 'main("' . $gid . '",' . $rgba .  ');'
+
. 'main("' . $gid . '",[' . $vertices . '],[' . $indices . '],' . $colors . ',' . $rgba .  ');'
. '</script>';
. '</script>';
Line 23: Line 48:
    $output,      $gid,      $style,    $width,    $height,    $main );
    $output,      $gid,      $style,    $width,    $height,    $main );
return($output);
return($output);
 +
}
 +
</syntaxhighlight>
 +
<br />
 +
<syntaxhighlight lang="php" line start="1">
 +
function twentyten_setup() {
 +
add_shortcode( 'primitive', 'gPrimitive' );
}
}
?>
?>
</syntaxhighlight>
</syntaxhighlight>

Revision as of 00:53, 8 February 2013

functions.php

  1. <?php
  2.  
  3. function gPrimitive( $atts ) {
  4. 	extract(shortcode_atts(array(
  5. 		'gid'		=> 'cube.00000000',
  6. 		'vertices'	=> '
  7. 			-0.5, -0.5, -0.5,	// d
  8. 			+0.5, -0.5, -0.5,	// c
  9. 			-0.5, +0.5, -0.5,	// a
  10. 			+0.5, +0.5, -0.5,	// b
  11. 			-0.5, -0.5, +0.5,	// h
  12. 			+0.5, -0.5, +0.5,	// g
  13. 			-0.5, +0.5, +0.5,	// e
  14. 			+0.5, +0.5, +0.5	// f
  15. 			',
  16. 		'indices'	=> '
  17. 			0, 1, 3, 2,		// d c b a
  18. 			0, 4, 6, 2,		// d h e a
  19. 			0, 4, 5, 1,		// d h g c
  20. 			1, 5, 7, 3,		// c g f b
  21. 			3, 2, 6, 7		// b a e f
  22. 			',
  23. 		'colors' =>
  24. 		'[
  25. 			[1.0, 0.0, 0.0, 1.0], // Front face
  26. 			[1.0, 1.0, 0.0, 1.0], // Back face
  27. 			[0.0, 1.0, 0.0, 1.0], // Top face
  28. 			[1.0, 0.5, 0.5, 1.0], // Bottom face
  29. 			[1.0, 0.0, 1.0, 1.0], // Right face
  30. 			[0.0, 0.0, 1.0, 1.0]  // Left face
  31. 		]',
  32. 		'style'		=> '',
  33. 		'width'		=> '640',
  34. 		'height'	=> '540',
  35. 		'rgba'		=> '0.0, 0.0, 0.0, 1.0'), $atts));
  36.  
  37.  
  38. 	$output	= '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/glMatrix-min.js"></script>'
  39. 		. '<script type="text/javascript" src="' . get_stylesheet_directory_uri() . '/primitive.js"></script>';
  40.  
  41. 	$main	= '<script type="text/javascript">'
  42. 		. 'main("' . $gid . '",[' . $vertices . '],[' . $indices . '],' . $colors . ',' . $rgba .  ');'
  43. 		. '</script>';
  44.  
  45. 	$output	= sprintf( '%s<canvas id="%s" style="%s" width="%s" height="%s"></canvas>%s',
  46. 			    $output,      $gid,      $style,    $width,     $height,     $main );
  47. 	return($output);
  48. }


  1. function twentyten_setup() {
  2. 	add_shortcode( 'primitive', 'gPrimitive' );
  3. }
  4.  
  5. ?>
Personal tools