code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
/*
Styles for older IE versions (previous to IE9).
*/
body {
background-color: #e6e6e6;
}
body.custom-background-empty {
background-color: #fff;
}
body.custom-background-empty .site,
body.custom-background-white .site {
box-shadow: none;
margin-bottom: 0;
margin-top: 0;
padding: 0;
}
.assistive-text,
.site .screen-reader-text {
clip: rect(1px 1px 1px 1px); /* IE7 */
}
.full-width .site-content {
float: none;
width: 100%;
}
img.size-full,
img.size-large,
img.header-image,
img.wp-post-image,
img[class*="align"],
img[class*="wp-image-"],
img[class*="attachment-"] {
width: auto; /* Prevent stretching of full-size and large-size images with height and width attributes in IE8 */
}
.author-avatar {
float: left;
margin-top: 8px;
margin-top: 0.571428571rem;
}
.author-description {
float: right;
width: 80%;
}
.site {
box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3);
margin: 48px auto;
max-width: 960px;
overflow: hidden;
padding: 0 40px;
}
.site-content {
float: left;
width: 65.104166667%;
}
body.template-front-page .site-content,
body.single-attachment .site-content,
body.full-width .site-content {
width: 100%;
}
.widget-area {
float: right;
width: 26.041666667%;
}
.site-header h1,
.site-header h2 {
text-align: left;
}
.site-header h1 {
font-size: 26px;
line-height: 1.846153846;
}
.main-navigation ul.nav-menu,
.main-navigation div.nav-menu > ul {
border-bottom: 1px solid #ededed;
border-top: 1px solid #ededed;
display: inline-block !important;
text-align: left;
width: 100%;
}
.main-navigation ul {
margin: 0;
text-indent: 0;
}
.main-navigation li a,
.main-navigation li {
display: inline-block;
text-decoration: none;
}
.ie7 .main-navigation li a,
.ie7 .main-navigation li {
display: inline;
}
.main-navigation li a {
border-bottom: 0;
color: #6a6a6a;
line-height: 3.692307692;
text-transform: uppercase;
}
.main-navigation li a:hover {
color: #000;
}
.main-navigation li {
margin: 0 40px 0 0;
position: relative;
}
.main-navigation li ul {
display: none;
margin: 0;
padding: 0;
position: absolute;
top: 100%;
z-index: 1;
}
.ie7 .main-navigation li ul {
left: 0;
}
.main-navigation li ul ul,
.ie7 .main-navigation li ul ul {
top: 0;
left: 100%;
}
.main-navigation ul li:hover > ul {
border-left: 0;
display: block;
}
.main-navigation li ul li a {
background: #efefef;
border-bottom: 1px solid #ededed;
display: block;
font-size: 11px;
line-height: 2.181818182;
padding: 8px 10px;
width: 180px;
}
.main-navigation li ul li a:hover {
background: #e3e3e3;
color: #444;
}
.main-navigation .current-menu-item > a,
.main-navigation .current-menu-ancestor > a,
.main-navigation .current_page_item > a,
.main-navigation .current_page_ancestor > a {
color: #636363;
font-weight: bold;
}
.menu-toggle {
display: none;
}
.entry-header .entry-title {
font-size: 22px;
}
#respond form input[type="text"] {
width: 46.333333333%;
}
#respond form textarea.blog-textarea {
width: 79.666666667%;
}
.template-front-page .site-content,
.template-front-page article {
overflow: hidden;
}
.template-front-page.has-post-thumbnail article {
float: left;
width: 47.916666667%;
}
.entry-page-image {
float: right;
margin-bottom: 0;
width: 47.916666667%;
}
.template-front-page .widget-area .widget,
.template-front-page.two-sidebars .widget-area .front-widgets {
float: left;
margin-bottom: 24px;
width: 51.875%;
}
.template-front-page .widget-area .widget:nth-child(odd) {
clear: right;
}
.template-front-page .widget-area .widget:nth-child(even),
.template-front-page.two-sidebars .widget-area .front-widgets + .front-widgets {
float: right;
margin: 0 0 24px;
width: 39.0625%;
}
.template-front-page.two-sidebars .widget,
.template-front-page.two-sidebars .widget:nth-child(even) {
float: none;
width: auto;
}
/* =RTL overrides for IE7 and IE8
-------------------------------------------------------------- */
.rtl .site-header h1,
.rtl .site-header h2 {
text-align: right;
}
.rtl .widget-area,
.rtl .author-description {
float: left;
}
.rtl .author-avatar,
.rtl .site-content {
float: right;
}
.rtl .main-navigation ul.nav-menu,
.rtl .main-navigation div.nav-menu > ul {
text-align: right;
}
.rtl .main-navigation ul li ul li,
.rtl .main-navigation ul li ul li ul li {
margin-left: 40px;
margin-right: auto;
}
.rtl .main-navigation li ul ul {
position: absolute;
bottom: 0;
right: 100%;
z-index: 1;
}
.ie7 .rtl .main-navigation li ul ul {
position: absolute;
bottom: 0;
right: 100%;
z-index: 1;
}
.ie7 .rtl .main-navigation ul li {
z-index: 99;
}
.ie7 .rtl .main-navigation li ul {
position: absolute;
bottom: 100%;
right: 0;
z-index: 1;
}
.ie7 .rtl .main-navigation li {
margin-right: auto;
margin-left: 40px;
}
.ie7 .rtl .main-navigation li ul ul ul {
position: relative;
z-index: 1;
} | 100vjet | trunk/themes/twentytwelve/css/ie.css | CSS | gpl3 | 4,788 |
<?php
/**
* The template for displaying Category pages.
*
* Used to display archive-type pages for posts in a category.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header(); ?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<header class="archive-header">
<h1 class="archive-title"><?php printf( __( 'Category Archives: %s', 'twentytwelve' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h1>
<?php if ( category_description() ) : // Show an optional category description ?>
<div class="archive-meta"><?php echo category_description(); ?></div>
<?php endif; ?>
</header><!-- .archive-header -->
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
/* Include the post format-specific template for the content. If you want to
* this in a child theme then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
twentytwelve_content_nav( 'nav-below' );
?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?> | 100vjet | trunk/themes/twentytwelve/category.php | PHP | gpl3 | 1,434 |
<?php
/**
* Implements an optional custom header for Twenty Twelve.
* See http://codex.wordpress.org/Custom_Headers
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
/**
* Sets up the WordPress core custom header arguments and settings.
*
* @uses add_theme_support() to register support for 3.4 and up.
* @uses twentytwelve_header_style() to style front-end.
* @uses twentytwelve_admin_header_style() to style wp-admin form.
* @uses twentytwelve_admin_header_image() to add custom markup to wp-admin form.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_custom_header_setup() {
$args = array(
// Text color and image (empty to use none).
'default-text-color' => '444',
'default-image' => '',
// Set height and width, with a maximum value for the width.
'height' => 250,
'width' => 960,
'max-width' => 2000,
// Support flexible height and width.
'flex-height' => true,
'flex-width' => true,
// Random image rotation off by default.
'random-default' => false,
// Callbacks for styling the header and the admin preview.
'wp-head-callback' => 'twentytwelve_header_style',
'admin-head-callback' => 'twentytwelve_admin_header_style',
'admin-preview-callback' => 'twentytwelve_admin_header_image',
);
add_theme_support( 'custom-header', $args );
}
add_action( 'after_setup_theme', 'twentytwelve_custom_header_setup' );
/**
* Styles the header text displayed on the blog.
*
* get_header_textcolor() options: 444 is default, hide text (returns 'blank'), or any hex value.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_header_style() {
$text_color = get_header_textcolor();
// If no custom options for text are set, let's bail
if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
return;
// If we get this far, we have custom styles.
?>
<style type="text/css">
<?php
// Has the text been hidden?
if ( ! display_header_text() ) :
?>
.site-title,
.site-description {
position: absolute !important;
clip: rect(1px 1px 1px 1px); /* IE7 */
clip: rect(1px, 1px, 1px, 1px);
}
<?php
// If the user has set a custom color for the text, use that.
else :
?>
.site-title a,
.site-description {
color: #<?php echo $text_color; ?> !important;
}
<?php endif; ?>
</style>
<?php
}
/**
* Styles the header image displayed on the Appearance > Header admin panel.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_admin_header_style() {
?>
<style type="text/css">
.appearance_page_custom-header #headimg {
border: none;
}
#headimg h1,
#headimg h2 {
line-height: 1.6;
margin: 0;
padding: 0;
}
#headimg h1 {
font-size: 30px;
}
#headimg h1 a {
color: #515151;
text-decoration: none;
}
#headimg h1 a:hover {
color: #21759b;
}
#headimg h2 {
color: #757575;
font: normal 13px/1.8 "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif;
margin-bottom: 24px;
}
#headimg img {
max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px;
}
</style>
<?php
}
/**
* Outputs markup to be displayed on the Appearance > Header admin panel.
* This callback overrides the default markup displayed there.
*
* @since Twenty Twelve 1.0
*/
function twentytwelve_admin_header_image() {
?>
<div id="headimg">
<?php
if ( ! display_header_text() )
$style = ' style="display:none;"';
else
$style = ' style="color:#' . get_header_textcolor() . ';"';
?>
<h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
<h2 id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2>
<?php $header_image = get_header_image();
if ( ! empty( $header_image ) ) : ?>
<img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
<?php endif; ?>
</div>
<?php } | 100vjet | trunk/themes/twentytwelve/inc/custom-header.php | PHP | gpl3 | 4,124 |
function FindProxyForURL(url, host) {
PROXY = "PROXY yourhttpproxy:80";
DEFAULT = "DIRECT";
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?appspot\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?blogspot\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(\d{2,}\.)docs\.google\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(\d{2,}\.)drive\.google\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?googleapis\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?googlecode\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?googlegroups\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?googlemashups\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?ig\.ig\.gmodules\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?a\.orkut\.gmodules\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)doc-(.{5})-docs\.googleusercontent\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\-)?a-fc-opensocial\.googleusercontent\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)images(\d{2,})-focus-opensocial\.googleusercontent\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(\d{2,}\.)-wave-opensocial\.googleusercontent\.com/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?au\.doubleclick\.net/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?de\.doubleclick\.net/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?fr\.doubleclick\.net/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?jp\.doubleclick\.net/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?uk\.doubleclick\.net/i.test(url)) return PROXY;
if(/^[\w\-]+:\/+(?!\/)(www|ssl)\.google-analytics\.net/i.test(url)) return DEFAULT;
if(/^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?google-analytics\.net/i.test(url)) return PROXY;
return DEFAULT;
} | 110visual-ipv6hosts | pac.js | JavaScript | oos | 1,906 |
//Hero
package {
import flash.display.Sprite;
import flash.events.Event;
public class Hero extends Role {
public function Hero(id:int) {
Side = "GOOD";
Id = id;
speed = 3;
graphics.beginFill(0x00ff00, 0.1);
graphics.drawCircle(0, 0, field);
graphics.beginFill(0x00ff00);
graphics.drawCircle(0, 0, 5);
graphics.moveTo( -5, 5);
graphics.lineTo(5, 5);
graphics.lineTo(0, 10);
graphics.lineTo( -5, 5);
graphics.endFill();
addEventListener(Event.ENTER_FRAME, seekTarget);
}
}
}
| 108fantasy-tactics | trunk/Hero.as | ActionScript | art | 576 |
/*
* Copyright 2007 (c) Andre Stubbe, http://www.andrestubbe.com
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.Plane;
import org.papervision3d.scenes.MovieScene3D;
[SWF(width='400',height='400',backgroundColor='0x000000',frameRate='40')]
public class BitmapVertices extends Sprite
{
private var container :Sprite;
private var scene :MovieScene3D;
private var camera :Camera3D;
private var plane :Plane;
public function BitmapVertices()
{
container = new Sprite;
container.x = 200;
container.y = 200;
addChild( container );
scene = new MovieScene3D( container );
camera = new Camera3D();
camera.z = -50;
camera.zoom = 2;
// create a plane
plane = new Plane( new BitmapFileMaterial("texture.jpg"), 128, 128, 8, 8);
plane.material.smooth = true;
plane.material.doubleSided = true;
plane.material.lineAlpha = 0.2;
plane.rotationX = -45;
// register the plane
scene.addChild( plane );
// create an enterframe loop
stage.addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
private function onEnterFrame( event: Event ): void
{
plane.rotationY = mouseX;
plane.rotationX = mouseY;
// change the Z coordinate of every vertex
for(var i:uint = 0;i<plane.geometry.vertices.length; i++){
plane.geometry.vertices[i].z = Math.random()*10;
}
// render the scene
scene.renderCamera( camera );
}
}
}
| 108fantasy-tactics | trunk/BitmapVertices.as | ActionScript | art | 2,816 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006-2007 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ PAPERVISION3D
package org.papervision3d
{
import org.papervision3d.core.culling.DefaultTriangleCuller;
import org.papervision3d.core.culling.ITriangleCuller;
/**
* The Papervision3D class contains global properties and settings.
*/
public class Papervision3D
{
// ___________________________________________________________________ SETTINGS
/**
* Indicates if the angles are expressed in degrees (true) or radians (false). The default value is true, degrees.
*/
static public var useDEGREES :Boolean = true;
/**
* Indicates if the scales are expressed in percent (true) or from zero to one (false). The default value is false, i.e. units.
*/
static public var usePERCENT :Boolean = false;
// ___________________________________________________________________ STATIC
/**
* Enables engine name to be retrieved at runtime or when reviewing a decompiled swf.
*/
static public var NAME :String = 'Papervision3D';
/**
* Enables version to be retrieved at runtime or when reviewing a decompiled swf.
*/
static public var VERSION :String = 'Beta 1.7';
/**
* Enables version date to be retrieved at runtime or when reviewing a decompiled swf.
*/
static public var DATE :String = '20.08.07';
/**
* Enables copyright information to be retrieved at runtime or when reviewing a decompiled swf.
*/
static public var AUTHOR :String = '(c) 2006-2007 Copyright by Carlos Ulloa | papervision3d.org | carlos@papervision3d.org';
/**
* Determines whether debug printout is enabled. It also prints version information at startup.
*/
static public var VERBOSE :Boolean = true;
// ___________________________________________________________________ LOG
/**
* Sends debug information to the Output panel.
*
* @param message A String value to send to Output.
*/
static public function log( message :String ):void
{
if( Papervision3D.VERBOSE )
trace( message );
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/Papervision3D.as | ActionScript | art | 3,785 |
package org.papervision3d.scenes
{
import flash.display.Sprite;
import org.papervision3d.objects.DisplayObject3D;
import com.blitzagency.xray.logger.XrayLog;
import org.papervision3d.utils.InteractiveSceneManager;
import org.papervision3d.core.proto.CameraObject3D;
public class InteractiveScene3D extends MovieScene3D
{
//new
public var interactiveSceneManager:InteractiveSceneManager;
public function InteractiveScene3D(container:Sprite)
{
super(container);
interactiveSceneManager = new InteractiveSceneManager(this);
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
public override function renderCamera( camera :CameraObject3D ):void
{
interactiveSceneManager.resetFaces();
super.renderCamera( camera );
interactiveSceneManager.sortObjects();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/scenes/InteractiveScene3D.as | ActionScript | art | 1,293 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ MovieScene3D
package org.papervision3d.scenes
{
import flash.utils.getTimer;
import flash.display.*;
import org.papervision3d.scenes.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.DisplayObject3D;
import flash.utils.Dictionary;
/**
* The MovieScene3D class lets you create a scene where each object is rendered in its own container.
* <p/>
* A scene is the place where objects are placed, it contains the 3D environment.
*/
public class MovieScene3D extends Scene3D
{
// ___________________________________________________________________ N E W
//
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a scene where each object is rendered in its own container.
*
* @param container The Sprite where the new containers are created.
*
*/
public function MovieScene3D( container:Sprite )
{
super( container );
this.containerList = new Array();
spriteList = new Dictionary();
}
// ___________________________________________________________________ A D D C H I L D
//
// AA DDDDD DDDDD CCCC HH HH II LL DDDDD
// AAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DD DD DD DD CC HHHHHH II LL DD DD
// AAAAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DDDDD DDDDD CCCC HH HH II LLLLLL DDDDD
/**
* Adds a child DisplayObject3D instance to the scene.
*
* If you add a GeometryObject3D symbol, a new DisplayObject3D instance is created.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The GeometryObject3D symbol or DisplayObject3D instance to add as a child of the scene.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public override function addChild( child :DisplayObject3D, name :String=null ):DisplayObject3D
{
child = super.addChild( child, name );
child.container = new Sprite();
container.addChild( child.container );
this.containerList.push( child.container );
spriteList[child] = child.container;
return child;
}
public function getSprite(child:DisplayObject3D):Sprite
{
return spriteList[child];
}
public override function removeChild( child:DisplayObject3D ):DisplayObject3D
{
var removed:DisplayObject3D=super.removeChild(child);
for(var i:int=0;i<containerList.length;i++){
if(removed.container==containerList[i]){
this.containerList.splice(i, 1);
}
}
container.removeChild(removed.container);
delete spriteList[removed];
return removed;
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
protected override function renderObjects( sort:Boolean ):void
{
var objectsLength :Number = this.objects.length;
// Clear object container
var gfx :Sprite;
var containerList :Array = this.containerList;
var i :Number = 0;
// Clear all known object
while( gfx = containerList[i++] ) gfx.graphics.clear();
// Render
var p :DisplayObject3D;
var objects :Array = this.objects;
i = objects.length;
if( sort )
{
while( p = objects[--i] )
{
if( p.visible )
{
container.addChild( p.container );
p.render( this );
}
}
}
else
{
while( p = objects[--i] )
{
if( p.visible )
{
p.render( this );
}
}
}
// Update stats
var stats:Object = this.stats;
stats.performance = getTimer() - stats.performance;
}
private var containerList : Array;
private var spriteList : Dictionary;
}
} | 108fantasy-tactics | trunk/org/papervision3d/scenes/MovieScene3D.as | ActionScript | art | 6,311 |
package org.papervision3d.scenes
{
import flash.display.Sprite;
import mx.containers.Canvas;
import org.papervision3d.objects.DisplayObject3D;
import flash.utils.Dictionary;
import flash.utils.getTimer;
import mx.core.UIComponent;
public class FlexScene3D extends Scene3D
{
private var containerList : Array;
private var spriteList : Dictionary;
public function FlexScene3D(container:Sprite)
{
super(container);
this.containerList = new Array();
spriteList = new Dictionary();
}
// ___________________________________________________________________ A D D C H I L D
//
// AA DDDDD DDDDD CCCC HH HH II LL DDDDD
// AAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DD DD DD DD CC HHHHHH II LL DD DD
// AAAAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DDDDD DDDDD CCCC HH HH II LLLLLL DDDDD
/**
* Adds a child DisplayObject3D instance to the scene.
*
* If you add a GeometryObject3D symbol, a new DisplayObject3D instance is created.
*
* CanvasScene3D is a fix for Flex2 - Its Flex2's version of MovieScene3D. If you want your objects separated into sprite containers, use CanvasScene3D.
* I DID try using pure Canvas objects where sprite was used, but I kept getting "index out of range errors" and just kept getting internal Flex errors.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The GeometryObject3D symbol or DisplayObject3D instance to add as a child of the scene.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public override function addChild( child :DisplayObject3D, name :String=null ):DisplayObject3D
{
child = super.addChild( child, name );
// for Flex2 we need to create a UIComponent
var uiDumby:UIComponent = new UIComponent();
// now create the sprite container
child.container = new Sprite();
// add the sprite to the UIComponent - which is legal, but adding a sprite to a Canvas or any other sub classed UIComponent is not
uiDumby.addChild(child.container);
// now add the uiDumby to the canvas container
container.addChild( uiDumby );
// push for use in the renderer
this.containerList.push( child.container );
spriteList[child] = child.container;
return child;
}
public function getSprite(child:DisplayObject3D):Canvas
{
return spriteList[child];
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
protected override function renderObjects( sort:Boolean ):void
{
var objectsLength :Number = this.objects.length;
// Clear object container
var gfx :Sprite;
var containerList :Array = this.containerList;
var i :Number = 0;
// Clear all known object
while( gfx = containerList[i++] ) gfx.graphics.clear();
// Render
var p :DisplayObject3D;
var objects :Array = this.objects;
i = objects.length;
if( sort )
{
while( p = objects[--i] )
{
if( p.visible )
{
// this keeps the memory consumption stable. Otherwise, there was a slight memory leak with each render
if(container.getChildByName("container")) container.removeChild(container.getChildByName("container"));
// same trick: add sprite to a UIComponent stand-in
var uiDumby:UIComponent = new UIComponent();
uiDumby.name = "container";
uiDumby.addChild(p.container);
container.addChild( uiDumby );
p.render( this );
}
}
}
else
{
while( p = objects[--i] )
{
if( p.visible )
{
p.render( this );
}
}
}
// Update stats
var stats:Object = this.stats;
stats.performance = getTimer() - stats.performance;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/scenes/FlexScene3D.as | ActionScript | art | 4,633 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Scene3D
package org.papervision3d.scenes
{
import flash.utils.getTimer;
import flash.display.Sprite;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.*;
import org.papervision3d.core.proto.*;
/**
* The Scene3D class lets you create a scene where all objects are rendered in the same container.
* <p/>
* A scene is the place where objects are placed, it contains the 3D environment.
*/
public class Scene3D extends SceneObject3D
{
// ___________________________________________________________________ N E W
//
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* The Scene3D class lets you create a scene where all objects are rendered in the same container.
*
* @param container The Sprite that you draw into when rendering.
*
*/
public function Scene3D( container:Sprite )
{
super( container );
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
protected override function renderObjects( sort:Boolean ):void
{
// Clear scene container
this.container.graphics.clear();
var p :DisplayObject3D;
var objects :Array = this.objects;
var i :Number = objects.length;
while( p = objects[--i] )
if( p.visible )
p.render( this );
// Update stats
var stats:Object = this.stats;
stats.performance = getTimer() - stats.performance;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/scenes/Scene3D.as | ActionScript | art | 3,777 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ LayerScene3D
package org.papervision3d.scenes
{
import flash.utils.getTimer;
import flash.display.*;
import org.papervision3d.Papervision3D;
import org.papervision3d.scenes.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.DisplayObject3D;
import flash.utils.Dictionary;
/**
* The LayerScene3D class lets you create a scene where each object is rendered in its own container.
* <p/>
* A scene is the place where objects are placed, it contains the 3D environment.
*/
public class LayerScene3D extends Scene3D
{
public var totalLayers :Number = 32;
// ___________________________________________________________________ N E W
//
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a scene where each object is rendered in its own container.
*
* @param container The Sprite where the new containers are created.
*
*/
public function LayerScene3D( container:Sprite )
{
super( container );
containerList = new Array();
currentLayer = createLayer( 0 );
}
// ___________________________________________________________________ A D D C H I L D
//
// AA DDDDD DDDDD CCCC HH HH II LL DDDDD
// AAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DD DD DD DD CC HHHHHH II LL DD DD
// AAAAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DDDDD DDDDD CCCC HH HH II LLLLLL DDDDD
/**
* Adds a child DisplayObject3D instance to the scene.
*
* If you add a GeometryObject3D symbol, a new DisplayObject3D instance is created.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The GeometryObject3D symbol or DisplayObject3D instance to add as a child of the scene.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public override function addChild( child :DisplayObject3D, name :String=null ):DisplayObject3D
{
child = super.addChild( child, name );
child.container = currentLayer;
return child;
}
// ___________________________________________________________________ A D D C H I L D
//
// AA DDDDD DDDDD CCCC HH HH II LL DDDDD
// AAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DD DD DD DD CC HHHHHH II LL DD DD
// AAAAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DDDDD DDDDD CCCC HH HH II LLLLLL DDDDD
/**
* Adds a child DisplayObject3D instance to a layer in the scene.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The GeometryObject3D symbol or DisplayObject3D instance to add as a child of the scene.
* @param layer The layer to add to.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public function addChildAt( child :DisplayObject3D, layer :int, name :String=null ):DisplayObject3D
{
child = super.addChild( child, name );
var childContainer :Sprite = layerContainer( layer );
if( childContainer )
{
child.container = childContainer;
}
else
child.container = currentLayer;
return child;
}
public function selectLayer( layer:int ):void
{
var selectContainer :Sprite = layerContainer( layer );
if( selectContainer )
currentLayer = selectContainer;
}
private function layerContainer( layer:int ):Sprite
{
var layerSprite:Sprite = getLayerSprite( layer );
if( ! layerSprite )
{
layerSprite = createLayer( layer );
}
return layerSprite;
}
private function createLayer( layer:int ):Sprite
{
if( layer < totalLayers )
{
for( var i:int = container.numChildren; i <= layer; i++ )
{
var layerSprite:Sprite = new Sprite();
layerSprite.name = "Layer"+i;
container.addChildAt( layerSprite, i );
containerList[ i ] = layerSprite;
}
return layerSprite;
}
else
{
Papervision3D.log( "SceneLayer3D - ERROR: Layer " + layer + " is not allowed as it's greater than totalLayers. Use a lower layer number or change totalLayers if really needed." );
return null;
}
}
public function getLayerSprite( layer:int ):Sprite
{
return containerList[ layer ];
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
protected override function renderObjects( sort:Boolean ):void
{
var objectsLength :Number = this.objects.length;
// Clear object container
var gfx :Sprite;
var i :Number = 0;
// Clear all known object
while( gfx = containerList[i++] ) gfx.graphics.clear();
// Render
var p :DisplayObject3D;
var objects :Array = this.objects;
i = objects.length;
while( p = objects[--i] )
{
if( p.visible )
{
p.render( this );
}
}
// Update stats
var stats:Object = this.stats;
stats.performance = getTimer() - stats.performance;
}
private var containerList :Array;
private var currentLayer :Sprite;
}
} | 108fantasy-tactics | trunk/org/papervision3d/scenes/LayerScene3D.as | ActionScript | art | 7,808 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Trevor McCauley
* @link www.senocular.com
*/
package org.papervision3d.utils.virtualmouse
{
/**
* Interface for virtual mouse events
* allowing you to check an event for
* the type of IVirtualMouseEvent to see
* if it originated from VirtualMouse.
*/
public interface IVirtualMouseEvent {}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/virtualmouse/IVirtualMouseEvent.as | ActionScript | art | 2,058 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Trevor McCauley
* @link www.senocular.com
*/
package org.papervision3d.utils.virtualmouse
{
import flash.display.InteractiveObject;
import flash.events.MouseEvent;
/**
* Wrapper for the MouseEvent class to let you check
* to see if an event originated from the user's mouse
* or a VirtualMouse instance.
*/
public class VirtualMouseMouseEvent extends MouseEvent implements IVirtualMouseEvent {
public function VirtualMouseMouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, localX:Number = NaN, localY:Number = NaN, relatedObject:InteractiveObject = null, ctrlKey:Boolean = false, altKey:Boolean = false, shiftKey:Boolean = false, buttonDown:Boolean = false, delta:int = 0){
super(type, bubbles, cancelable, localX, localY, relatedObject, ctrlKey, altKey, shiftKey, buttonDown, delta);
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/virtualmouse/VirtualMouseMouseEvent.as | ActionScript | art | 2,598 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Trevor McCauley
* @link www.senocular.com
*/
package org.papervision3d.utils.virtualmouse
{
import flash.events.Event;
/**
* Wrapper for the Event class to let you check to
* see if an event originated from the user's mouse
* or a VirtualMouse instance.
*/
public class VirtualMouseEvent extends Event implements IVirtualMouseEvent {
public function VirtualMouseEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false){
super(type, bubbles, cancelable);
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/virtualmouse/VirtualMouseEvent.as | ActionScript | art | 2,254 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Trevor McCauley
* @link www.senocular.com
*/
package org.papervision3d.utils.virtualmouse
{
import com.blitzagency.xray.logger.XrayLog;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.display.InteractiveObject;
import flash.display.SimpleButton;
import flash.display.Stage;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.utils.Dictionary;
/**
* Dispatched when the virtual mouse state is updated.
* @eventType flash.events.Event
*/
[Event(name="update", type="flash.events.Event")]
/**
* Dispatched when the virtual mouse fires an
* Event.MOUSE_LEAVE event.
* @eventType flash.events.Event
*/
[Event(name="mouseLeave", type="flash.events.Event")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.MOUSE_MOVE event.
* @eventType flash.events.MouseEvent
*/
[Event(name="mouseMove", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.MOUSE_OUT event.
* @eventType flash.events.MouseEvent
*/
[Event(name="mouseOut", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.ROLL_OUT event.
* @eventType flash.events.MouseEvent
*/
[Event(name="rollOut", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.MOUSE_OVER event.
* @eventType flash.events.MouseEvent
*/
[Event(name="mouseOver", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.ROLL_OVER event.
* @eventType flash.events.MouseEvent
*/
[Event(name="rollOver", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.MOUSE_DOWN event.
* @eventType flash.events.MouseEvent
*/
[Event(name="mouseDown", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.MOUSE_UP event.
* @eventType flash.events.MouseEvent
*/
[Event(name="mouseUp", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.CLICK event.
* @eventType flash.events.MouseEvent
*/
[Event(name="click", type="flash.events.MouseEvent")]
/**
* Dispatched when the virtual mouse fires an
* MouseEvent.DOUBLE_CLICK event.
* @eventType flash.events.MouseEvent
*/
[Event(name="doubleClick", type="flash.events.MouseEvent")]
/**
* The VirtualMouse class is used to create a programmatic
* version of the users mouse that can be moved about the
* Flash player stage firing off mouse events of the display
* objects it interacts with. This can allow you to simulate
* interaction with buttons and movie clips through ActionScript.
* <br />
* Handled events include:
* Event.MOUSE_LEAVE,
* MouseEvent.MOUSE_MOVE,
* MouseEvent.MOUSE_OUT,
* MouseEvent.ROLL_OUT,
* MouseEvent.MOUSE_OVER,
* MouseEvent.ROLL_OVER,
* MouseEvent.MOUSE_DOWN,
* MouseEvent.MOUSE_UP.
* MouseEvent.CLICK, and,
* MouseEvent.DOUBLE_CLICK.
* Along with dispatching those events for their respective
* targets, the VirtualMouse instance will also dispatch the
* event on itself allowing to capture which events are being
* fired by the virtual mouse. The last event fired can also
* be referenced in the lastEvent property.
* <br />
* VirtualMouse mouse cannot:
* activate states of SimpleButton instances,
* change object focus,
* handle mouseWheel related events,
* change the system's cursor location, or
* spoof the location of the mouseX and mouseY properties
* (which some components rely on).
*/
public class VirtualMouse extends EventDispatcher {
public static const UPDATE:String = "update";
private var altKey:Boolean = false;
private var ctrlKey:Boolean = false;
private var shiftKey:Boolean = false;
private var delta:int = 0; // mouseWheel unsupported
private var _stage:Stage;
private var _container:Sprite;
private var target:InteractiveObject;
private var location:Point;
private var isLocked:Boolean = false;
private var isDoubleClickEvent:Boolean = false;
private static var _mouseIsDown:Boolean = false;
private var disabledEvents:Object = new Object();
private var ignoredInstances:Dictionary = new Dictionary(true);
private var _lastEvent:Event;
private var lastMouseDown:Boolean = false;
private var updateMouseDown:Boolean = false;
private var lastLocation:Point;
private var lastDownTarget:DisplayObject;
private var lastWithinStage:Boolean = true;
private var _useNativeEvents:Boolean = false;
private var eventEvent:Class = VirtualMouseEvent;
private var mouseEventEvent:Class = VirtualMouseMouseEvent;
private var log:XrayLog = new XrayLog();
/**
* A reference to the Stage instance. This
* reference needs to be passed to the
* VirtualMouse instance either in its constructor
* or through assigning it's stage property.
* Without a valid reference to the stage, the
* virtual mouse will not function.
* @see VirtualMouse()
*/
public function get stage():Stage {
return _stage;
}
public function set stage(s:Stage):void {
var hadStage:Boolean;
if (_stage){
hadStage = true;
_stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
_stage.removeEventListener(KeyboardEvent.KEY_UP, keyHandler);
}else{
hadStage = false;
}
_stage = s;
if (_stage) {
_stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
_stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
target = _stage;
if (!hadStage) update();
}
}
/**
*
* @param value Sprite container you want VirtualMouse to use with its testing of sub containers
* @return
*/
public function set container(value:Sprite):void
{
_container = value;
}
public function get container():Sprite { return _container; }
/**
* The last event dispatched by the VirtualMouse
* instance. This can be useful for preventing
* event recursion if performing VirtualMouse
* operations within MouseEvent handlers.
*/
public function get lastEvent():Event {
return _lastEvent;
}
/**
* True if the virtual mouse is being
* pressed, false if not. The mouse is
* down for the virtual mouse if press()
* was called.
* @see press()
* @see release()
*/
public function get mouseIsDown():Boolean {
return _mouseIsDown;
}
/**
* The x location of the virtual mouse. If you are
* setting both the x and y properties of the
* virtual mouse at the same time, you would probably
* want to lock the VirtualMouse instance to prevent
* additional events from firing.
* @see lock
* @see unlock
* @see y
* @see setLocation()
* @see getLocation()
*/
public function get x():Number {
return location.x;
}
public function set x(n:Number):void {
location.x = n;
if (!isLocked) update();
}
/**
* The y location of the virtual mouse. If you are
* setting both the x and y properties of the
* virtual mouse at the same time, you would probably
* want to lock the VirtualMouse instance to prevent
* additional events from firing.
* @see lock
* @see unlock
* @see x
* @see setLocation()
* @see getLocation()
*/
public function get y():Number {
return location.y;
}
public function set y(n:Number):void {
location.y = n;
if (!isLocked) update();
}
/**
* Determines if the events dispatched by the
* VirtualMouse instance are IVirualMouseEvent
* Events (wrapping Event and MouseEvent) or events
* of the native Event and MouseEvent type. When using
* non-native events, you can check to see if the
* events originated from VirtualMouse by seeing if
* the events are of the type IVirualMouseEvent.
* @see lastEvent
*/
public function get useNativeEvents():Boolean {
return _useNativeEvents;
}
public function set useNativeEvents(b:Boolean):void {
if (b == _useNativeEvents) return;
_useNativeEvents = b;
if (_useNativeEvents){
eventEvent = VirtualMouseEvent;
mouseEventEvent = VirtualMouseMouseEvent;
}else{
eventEvent = Event;
mouseEventEvent = MouseEvent;
}
}
/**
* Initializes a new VirtualMouse instance.
* @param stage A reference to the stage instance.
* @param startX The initial x location of
* the virtual mouse.
* @param startY The initial y location of
* the virtual mouse.
*/
public function VirtualMouse(stage:Stage = null, container:Sprite = null, startX:Number = 0, startY:Number = 0) {
this.stage = stage;
this.container = container;
location = new Point(startX, startY);
lastLocation = location.clone();
addEventListener(UPDATE, handleUpdate);
update();
}
/**
* Returns the location (x and y) of the current
* VirtualMouse instance. The location of the
* virtual mouse is based in the global
* coordinate space.
* @return A Point instance representing the
* location of the virtual mouse in
* global coordinate space.
* @see x
* @see y
* @see setLocation()
*/
public function getLocation():Point {
return location.clone();
}
/**
* Sets the location (x and y) of the current
* VirtualMouse instance. There are two ways to
* call setLocation, either passing in a single
* Point instance, or by passing in two Number
* instances representing x and y coordinates.
* The location of the virtual mouse is based in
* the global coordinate space.
* @param a A Point instance or x Number value.
* @param b A y Number value if a is a Number.
* @see x
* @see y
* @see getLocation()
*/
public function setLocation(a:*, b:* = null):void {
if (a is Point) {
var loc:Point = Point(a);
location.x = loc.x;
location.y = loc.y;
}else{
location.x = Number(a);
location.y = Number(b);
}
if (!isLocked) update();
}
/**
* Locks the current VirtualMouse instance
* preventing updates from being made as
* properties change within the instance.
* To release and allow an update, call unlock().
* @see lock()
* @see update()
*/
public function lock():void {
isLocked = true;
}
/**
* Unlocks the current VirtualMouse instance
* allowing updates to be made for the
* dispatching of virtual mouse events. After
* unlocking the instance, it will update and
* additional calls to press(), release(), or
* changing the location of the virtual mouse
* will also invoke updates.
* @see lock()
* @see update()
*/
public function unlock():void {
isLocked = false;
update();
}
/**
* Allows you to disable an event by type
* preventing the virtual mouse from
* dispatching that event during an update.
* @param type The type for the event to
* disable, e.g. MouseEvent.CLICK
* @see enableEvent()
*/
public function disableEvent(type:String):void {
disabledEvents[type] = true;
}
/**
* Re-enables an event disabled with
* disableEvent.
* @param type The type for the event to
* enable, e.g. MouseEvent.CLICK
* @see disableEvent()
*/
public function enableEvent(type:String):void {
if (type in disabledEvents) {
delete disabledEvents[type];
}
}
/**
* Ignores a display object preventing that
* object from recieving events from the
* virtual mouse. This is useful for instances
* used for cursors which may always be under
* the virtual mouse's location.
* @param instance A reference to the
* DisplayObject instance to ignore.
* @see unignore()
*/
public function ignore(instance:DisplayObject):void {
ignoredInstances[instance] = true;
}
/**
* Removes an instance from the ignore list
* defined by ignore(). When an ingored
* object is passed into unignore(), it will
* be able to receive events from the virtual
* mouse.
* @param instance A reference to the
* DisplayObject instance to unignore.
* @see ignore()
*/
public function unignore(instance:DisplayObject):void {
if (instance in ignoredInstances){
delete ignoredInstances[instance];
}
}
/**
* Simulates the pressing of the left
* mouse button. To release the mouse
* button, use release().
* @see release()
* @see click()
*/
public function press():void {
//if (_mouseIsDown) return;
updateMouseDown = true;
_mouseIsDown = true;
if (!isLocked) update();
}
/**
* Simulates the release of the left
* mouse button. This method has no
* effect unless press() was called first.
* @see press()
* @see click()
*/
public function release():void {
//if (!_mouseIsDown) return;
updateMouseDown = true;
_mouseIsDown = false;
if (!isLocked) update();
}
/**
* Simulates a click of the left
* mouse button (press and release)
* @see press()
* @see release()
* @see click()
* @see doubleClick()
*/
public function click():void {
press();
release();
}
/**
* Simulates a double-click of the left
* mouse button (press and release twice).
* Calling this command is the only way to
* simulate a double-click for the virtual
* mouse. Calling press() and release() or
* click() is rapid succession will not
* invoke a double-click event. The double-click
* event will also only fire for an instance
* if it's doubleClickEnabled property is
* set to true.
* @see click()
*/
public function doubleClick():void {
// if locked, doubleClick will
// not fire but the mouse will
// be released if not already
if (isLocked) {
release();
}else{
// call update with a click, press, then release
// and double-click notification for release
click();
press();
isDoubleClickEvent = true;
release();
isDoubleClickEvent = false;
}
}
/*Added by Jim Kremens kremens@gmail.com 08/16/07 */
public function exitContainer():void {
var targetLocal:Point = target.globalToLocal(location);
if (!disabledEvents[MouseEvent.MOUSE_OUT]) {
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
container.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (!disabledEvents[MouseEvent.ROLL_OUT]) { // rolls do not propagate
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
container.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (target != container) {
if (!disabledEvents[MouseEvent.MOUSE_OUT]) {
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (!disabledEvents[MouseEvent.ROLL_OUT]) { // rolls do not propagate
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, container, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
}
//reset the target to the stage, which is the value it starts at.
target = _stage;
}
/**
* Updates the VirtualMouse instance's state
* to reflect a change in the virtual mouse.
* Within this method all events will be dispatched.
* update() is called any time a VirtualMouse
* property is changed unless lock() was used to
* lock the instance. update() will then not be
* called until unlock() is used to unlock
* the instance. Typically you would never call
* update() directly; it is called automatically
* by the VirtualMouse class. Calling update()
* manually will override lock(). Whenever update()
* is called, the UPDATE event is dispatched.
* @see lock()
* @see unlock()
*/
public function update():void {
// dispatch an update event indicating that
// an update has occured
dispatchEvent(new Event(UPDATE, false, false));
}
private function handleUpdate(event:Event):void
{
if (!container) return;
// go through each objectsUnderPoint checking:
// 1) is not ignored
// 2) is InteractiveObject
// 3) mouseEnabled
// 4) all parents have mouseChildren
// if not interactive object, defer interaction to next object in list
// if is interactive and enabled, give interaction and ignore rest
var objectsUnderPoint:Array = container.getObjectsUnderPoint(location);
var currentTarget:InteractiveObject;
var currentParent:DisplayObject;
var i:int = objectsUnderPoint.length;
while (i--) {
currentParent = objectsUnderPoint[i];
// go through parent hierarchy
while (currentParent) {
// don't use ignored instances as the target
if (ignoredInstances[currentParent]) {
currentTarget = null;
break;
}
// invalid target if in a SimpleButton
if (currentTarget && currentParent is SimpleButton)
{
//log.debug("found SimpleButton - setting currentTarget to null");
currentTarget = null;
// invalid target if a parent has a
// false mouseChildren
} else if (currentTarget && !DisplayObjectContainer(currentParent).mouseChildren)
{
//log.debug("parent false mouseChildren - setting currentTarget to null");
currentTarget = null;
}
// define target if an InteractiveObject
// and mouseEnabled is true
if (!currentTarget && currentParent is InteractiveObject && InteractiveObject(currentParent).mouseEnabled)
{
//log.debug("found InteractiveObject && mouseEnabled = true - setting currentTarget");
currentTarget = InteractiveObject(currentParent);
}
// next parent in hierarchy
currentParent = currentParent.parent;
}
// if a currentTarget was found
// ignore all other objectsUnderPoint
if (currentTarget){
break;
}
}
// if a currentTarget was not found
// the currentTarget is the stage
if (!currentTarget){
currentTarget = _stage;
log.debug("no new target found, using stage");
}
// get local coordinate locations
var targetLocal:Point = target.globalToLocal(location);
var currentTargetLocal:Point = currentTarget.globalToLocal(location);
// move event
if (lastLocation.x != location.x || lastLocation.y != location.y)
{
var withinStage:Boolean = false;
if(stage) withinStage = (location.x >= 0 && location.y >= 0 && location.x <= stage.stageWidth && location.y <= stage.stageHeight);
// mouse leave if left stage
if (!withinStage && lastWithinStage && !disabledEvents[Event.MOUSE_LEAVE]){
_lastEvent = new eventEvent(Event.MOUSE_LEAVE, false, false);
stage.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// only mouse move if within stage
if (withinStage && !disabledEvents[MouseEvent.MOUSE_MOVE]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_MOVE, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// remember if within stage
lastWithinStage = withinStage;
}
// roll/mouse (out and over) events
if (currentTarget != target)
{
// off of last target
if (!disabledEvents[MouseEvent.MOUSE_OUT]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OUT, true, false, targetLocal.x, targetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (!disabledEvents[MouseEvent.ROLL_OUT]){ // rolls do not propagate
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OUT, false, false, targetLocal.x, targetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
target.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// on to current target
if (!disabledEvents[MouseEvent.MOUSE_OVER]){
//log.debug("*** MOUSEOVER****");
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_OVER, true, false, currentTargetLocal.x, currentTargetLocal.y, target, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (!disabledEvents[MouseEvent.ROLL_OVER]){ // rolls do not propagate
//log.debug("*** ROLLOVER****");
_lastEvent = new mouseEventEvent(MouseEvent.ROLL_OVER, false, false, currentTargetLocal.x, currentTargetLocal.y, target, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
}
// click/up/down events
if (updateMouseDown) {
if (_mouseIsDown) {
if (!disabledEvents[MouseEvent.MOUSE_DOWN]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_DOWN, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// remember last down
lastDownTarget = currentTarget;
updateMouseDown = false;
// mouse is up
}else{
if (!disabledEvents[MouseEvent.MOUSE_UP]){
_lastEvent = new mouseEventEvent(MouseEvent.MOUSE_UP, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
if (!disabledEvents[MouseEvent.CLICK] && currentTarget == lastDownTarget) {
_lastEvent = new mouseEventEvent(MouseEvent.CLICK, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// clear last down
lastDownTarget = null;
updateMouseDown = false;
}
}
// explicit call to doubleClick()
if (isDoubleClickEvent && !disabledEvents[MouseEvent.DOUBLE_CLICK] && currentTarget.doubleClickEnabled) {
_lastEvent = new mouseEventEvent(MouseEvent.DOUBLE_CLICK, true, false, currentTargetLocal.x, currentTargetLocal.y, currentTarget, ctrlKey, altKey, shiftKey, _mouseIsDown, delta);
currentTarget.dispatchEvent(_lastEvent);
dispatchEvent(_lastEvent);
}
// remember last values
lastLocation = location.clone();
lastMouseDown = _mouseIsDown;
target = currentTarget;
}
private function keyHandler(event:KeyboardEvent):void {
// update properties used in MouseEvents
altKey = event.altKey;
ctrlKey = event.ctrlKey;
shiftKey = event.shiftKey;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/virtualmouse/VirtualMouse.as | ActionScript | art | 25,930 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* ...
* @author John Grden
* @version 0.1
*/
package org.papervision3d.utils
{
import com.blitzagency.xray.logger.XrayLog;
import com.blitzagency.xray.logger.util.ObjectTools;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.display.BlendMode;
import flash.events.EventDispatcher;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Dictionary;
import org.papervision3d.core.geom.Mesh3D;
import org.papervision3d.core.geom.Face3DInstance;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.utils.InteractiveSprite;
import org.papervision3d.materials.InteractiveMovieMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.components.as3.utils.CoordinateTools;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.utils.virtualmouse.VirtualMouse;
/**
* Dispatched when an InteractiveSprite container in the ISM recieves a MouseEvent.CLICK
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_CLICK
*/
[Event(name="mouseClick", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite in the ISM receives an MouseEvent.MOUSE_OVER event
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_OVER
*/
[Event(name="mouseOver", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite in the ISM receives an MouseEvent.MOUSE_OUT event
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_OUT
*/
[Event(name="mouseOut", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite in the ISM receives a MouseEvent.MOUSE_MOVE event
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_MOVE
*/
[Event(name="mouseMove", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite in the ISM receives a MouseEvent.MOUSE_PRESS event
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_PRESS
*/
[Event(name="mousePress", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite in the ISM receives a MouseEvent.MOUSE_RELEASE event
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_RELEASE
*/
[Event(name="mouseRelease", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when the main container of the ISM is clicked
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_RELEASE_OUTSIDE
*/
[Event(name="mouseReleaseOutside", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* Dispatched when an InteractiveSprite is created in the ISM for drawing and mouse interaction purposes
*
* @eventType org.papervision3d.events.InteractiveScene3DEvent.OBJECT_ADDED
*/
[Event(name="objectAdded", type="org.papervision3d.events.InteractiveScene3DEvent")]
/**
* InteractiveSceneManager handles all the traffic and sub rendering of faces for mouse interactivity within an interactive scene.
* </p>
* <p>
* When you create an InteractiveScene3D object, it automatically creates the InteractiveSceneManager (ISM for short) for you. From there on, any 3D object using an interactive material
* will automatically be given mouse events that are dispatched through the ISM OR the DisplayObject3D itself. The event type is InteractiveScene3DEvent.
* </p>
* <p>
* ISM has 2 modes:
* <ul>
* <li>Object level mode</li>
* <li>Face level mode</li>
* </ul>
* </p>
* <p>
* Object level mode is a bit faster in that sprite containers for the objects are created and then all faces are drawn in that container. You're able to receive mouse
* events based on the objects, but not the contents of the materials used on the objects.
* </P>
* <p>
* For example, if you created a movieclip, put UI components in it and applied it to a DisplayObject3D (DO3D for short), you would not be able to interact with those elements in
* your movieclip. But you WOULD be able to have mouse events on the entire DO3D.
* </p>
* <p>
* Face level mode creates sprite containers for each face of a DO3D that uses an interactive material and gives you the ability to interact with a movieclips objects like UI components.
* </p>
* <p>
* For example, if you created a movieclip, put UI components in it and applied it to a DO3D, you would be able to interact with those elements in
* your movieclip and receive their mouse events like you normally would.
* </p>
* <p>There is one other option for faceLevelMode and that's directly on the DO3D's themselves. This is even heavier in terms of speed, but its there if you need face level access to all DO3D's.
* DisplayObject3D.faceLevelMode is a public static property that when set to true, causes all DO3D's do create their own sprite containers for their faces. The difference between
* this and what the ISM does is that, the ISM only draws faces for DO3D's that have interactive materials - giving you the control you need to dictate what needs interactivity and what doesn't.
* </p>
* @author John Grden
*
*/
public class InteractiveSceneManager extends EventDispatcher
{
/**
* The ISM, by default, uses a BlendMode.ERASE to hide the hit area of the drawn face.
* Setting this to true will show the drawn faces and give you the ability to add whatever type effects/filters you want
* over your scene and 3D objects.
* </p>
* <p>
* When set to true, you should set DEFAULT_SPRITE_ALPHA, DEFAULT_FILL_ALPHA and DEFAULT_FILL_COLOR as these will dictate how the faces are drawn over the scene.
* </p>
* <p>
* Setting DEFAULT_SPRITE_ALPHA = 0 will give you the same effect as the blendmode, but only slower. A combination of DEFAULT_SPRITE_ALPHA and DEFAULT_FILL_ALPHA along with filters
* can really give you some nice visual affects over your scene for your 3D objects.
*/
public static var SHOW_DRAWN_FACES :Boolean = false;
/**
* Alpha value 0-1 of the sprite container created for DO3D's or Face3D containers in the ISM
*/
public static var DEFAULT_SPRITE_ALPHA :Number = 1;
/**
* Alpha value 0-1 of the drawn face
*/
public static var DEFAULT_FILL_ALPHA :Number = 1;
/**
* Color used to draw the face in the sprite container
*/
public static var DEFAULT_FILL_COLOR :Number = 0xFFFFFF;
/**
* Color used for the line drawn around the face
*/
public static var DEFAULT_LINE_COLOR :Number = -1;
/**
* Line size of the line drawn around the face
*/
public static var DEFAULT_LINE_SIZE :Number = 1;
/**
* Alpha value 0-1 of the line drawn around the face
*/
public static var DEFAULT_LINE_ALPHA :Number = 1;
/**
* MOUSE_IS_DOWN is a quick static property to check and is maintained by the ISM
*/
public static var MOUSE_IS_DOWN :Boolean = false;
/**
* When set to true, the hand cursor is shown over objects that have mouse events assigned to it.
*/
public var buttonMode :Boolean = false;
/**
* This allows objects faces to have their own containers. When set to true
* and the DisplayObject3D.faceLevelMode = false, the faces will be drawn in ISM's layer of containers
*/
public var faceLevelMode :Boolean = false;
private var _mouseInteractionMode :Boolean = false;
/**
* @private
* @param value
*
*/
public function set mouseInteractionMode(value:Boolean):void
{
_mouseInteractionMode = value;
allowDraw = !value;
if( value ) container.stage.addEventListener(MouseEvent.MOUSE_MOVE, handleStageMouseMove);
if( !value ) container.stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleStageMouseMove);
}
/**
* If the user sets this to true, then we monitor the allowDraw flag via mouse interaction and we only draw the faces if there's mouse interaction with the scene.
* This is meant to maximize CPU for interactivity
* If set to true, then leave SHOW_DRAWN_FACES set to false to avoid odd drawings over the 3D scene
*/
public function get mouseInteractionMode():Boolean { return _mouseInteractionMode; }
/**
* A dictionary where the InteractiveContainerData objects are stored for DO3D's or Face3D objects. You can get to a DO3D or Face3D's InteractiveContainerDate object
* with:
* </P>
* <p>
* <code>
* var icd:InteractiveContainerData = faceDictionary[do3dInstance];
* </code>
* </p>
*/
public var faceDictionary :Dictionary = new Dictionary();
/**
* A dictionary where the DO3D's and Face3D objects are stored. You can get to a DO3D or Face3D by supplying the sprite container reference:
* </P>
* <p>
* <code>
* var do3d:DisplayObject3D = containerDictionary[spriteInstance];
* or
* var face3d:Face3D = containerDictionary[spriteInstance];
* </code>
* </p>
*/
public var containerDictionary :Dictionary = new Dictionary();
/**
* Main container for ISM to create the sub InteractiveSprite containers for the faces and DO3D objects passed in during the render loop
*/
public var container :Sprite = new InteractiveSprite();
/**
* InteractiveScene3D instance, usually passed in by the constructor
*/
public var scene :SceneObject3D;
/**
* Mouse3D gives you a pointer in 3D space that orients itself to a face your mouse is currently over. It copy's the transform information of the face giving you the ability to do something in 3D at that same location
*/
public var mouse3D :Mouse3D = new Mouse3D();
/**
* VirtualMouse is used with faceLevelMode of ISM or DO3D's. Its a virtual mouse that causes the objects in your materials movieclip containers to fire off their mouse events such as click, over, out, release, press etc
* </p>
* <p>
* Using these events requires you only to do what you normally do - establish listeners with your objects like you normally would, and you'll receive them!
*/
public var virtualMouse :VirtualMouse = new VirtualMouse();
/**
* @private
*/
public function set enableMouse(value:Boolean):void
{
Mouse3D.enabled = value;
}
/**
* Boolean value that sets Mouse3D.enabled = true
*/
public function get enableMouse():Boolean { return Mouse3D.enabled; }
/**
* Setting to true will show output via trace window in IDE or Xray's output
*/
public var debug :Boolean = false;
/**
* @private
* Boolean flag used internally to turn off ISM drawing when it's not needed in the render loop. This only applies if mouseInteractionMode is set to true.
*/
protected var allowDraw :Boolean = true;
/**
* @private
* When mouseInteractionMode is turned on, this tells ISM's MouseOver event to dispatch a click event
*/
protected var evaluateClick :Boolean = false;
/**
* @private
*/
protected var log :XrayLog = new XrayLog();
/**
*
* @param p_scene The InteractiveScene3D object instance. This is passed in via the constructor of InteractiveScene3D when you create a new one.
* @return
*/
public function InteractiveSceneManager(p_scene:SceneObject3D):void
{
container.addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);
scene = p_scene;
scene.container.parent.addChild(container);
container.x = scene.container.x;
container.y = scene.container.y;
enableMouse = false;
}
/**
* Convenience method to help set the default parameters of the ISM.
* This gives you faceLevelMode and buttonMode interaction on your scene. Setting faceLevelMode = false reverts ISM to Object level mode
* @return
*/
public function setInteractivityDefaults():void
{
SHOW_DRAWN_FACES = false;
DEFAULT_SPRITE_ALPHA = 1;
DEFAULT_FILL_ALPHA = 1;
BitmapMaterial.AUTO_MIP_MAPPING = false;
DisplayObject3D.faceLevelMode = false;
buttonMode = true;
faceLevelMode = true;
mouseInteractionMode = false;
}
/**
* Adds a DisplayObject3D or Face3D object to the ISM
* @param container3d
* @return
*/
public function addInteractiveObject(container3d:Object):void
{
if(faceDictionary[container3d] == null)
{
var icd:InteractiveContainerData = faceDictionary[container3d] = new InteractiveContainerData(container3d);
// for reverse lookup when you have the sprite container
containerDictionary[icd.container] = container3d;
// add mouse events to be captured and passed along
var icdContainer:InteractiveSprite = icd.container;
icdContainer.addEventListener(MouseEvent.MOUSE_DOWN, handleMousePress);
icdContainer.addEventListener(MouseEvent.MOUSE_UP, handleMouseRelease);
icdContainer.addEventListener(MouseEvent.CLICK, handleMouseClick);
icdContainer.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
icdContainer.addEventListener(MouseEvent.MOUSE_OUT, handleMouseOut);
icdContainer.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
icdContainer.buttonMode = buttonMode;
if( !SHOW_DRAWN_FACES && !DisplayObject3D.faceLevelMode ) icdContainer.blendMode = BlendMode.ERASE;
// need to let virtualMouse know what to ignore
virtualMouse.ignore(icdContainer);
// let others know we've added a container
dispatchEvent(new InteractiveScene3DEvent(InteractiveScene3DEvent.OBJECT_ADDED, null, icdContainer));
if(debug) log.debug("addDisplayObject id", container3d.id, container3d.name, DEFAULT_SPRITE_ALPHA);
}
}
/**
* drawFace is called from each of the interactive materials in the render loop. It either receives DisplayObject3D or a Face3D object reference. It then creates a container
* if one doesn't exist. Then, it draws the face into the designated container which is an InteractiveSprite.
*
* @param container3d
* @param face3d
* @param x0
* @param x1
* @param x2
* @param y0
* @param y1
* @param y2
* @return
*/
public function drawFace(container3d:DisplayObject3D, face3d:Face3D, x0:Number, x1:Number, x2:Number, y0:Number, y1:Number, y2:Number ):void
{
// if we're face level on this DO3D, then we switch to the face3D object
var container:Object = container3d;
if(faceLevelMode || DisplayObject3D.faceLevelMode) container = face3d;
// add to the dictionary if not added already
if(faceDictionary[container] == null) addInteractiveObject(container);
if( allowDraw && !DisplayObject3D.faceLevelMode )
{
var drawingContainer:InteractiveContainerData = faceDictionary[container];
var iContainer:InteractiveSprite = drawingContainer.container;
var graphics:Graphics = iContainer.graphics;
iContainer.x0 = x0;
iContainer.x1 = x1;
iContainer.x2 = x2;
iContainer.y0 = y0;
iContainer.y1 = y1;
iContainer.y2 = y2;
graphics.beginFill(drawingContainer.color, drawingContainer.fillAlpha);
if( drawingContainer.lineColor != -1 && SHOW_DRAWN_FACES ) graphics.lineStyle(drawingContainer.lineSize, drawingContainer.lineColor, drawingContainer.lineAlpha);
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.endFill();
drawingContainer.isDrawn = true;
}
}
/*
public function getSprite(container3d:DisplayObject3D):InteractiveSprite
{
return InteractiveContainerData(faceDictionary[container3d]).container;
}
public function getDisplayObject3D(sprite:InteractiveSprite):DisplayObject3D
{
return DisplayObject3D(containerDictionary[sprite]);
}
*/
/**
* When called, aligns the ISM's container with the scene's container to make sure faces drawn in the ISM are aligned with the scene perfectly
*
*/
public function resizeStage():void
{
container.x = scene.container.x;
container.y = scene.container.y;
}
/**
* When called, all faces are cleared and the isDrawn flag is reset on the InteractiveContainerData objects to ready them for the next loop.
*
* This is called via InteractiveScene3D before the render.
*
*/
public function resetFaces():void
{
// clear all triangles/faces that have been drawn
for each( var item:InteractiveContainerData in faceDictionary)
{
item.container.graphics.clear();
item.sort = item.isDrawn;
item.isDrawn = false;
}
// make sure the sprite is aligned with the scene's canvas
resizeStage();
}
/**
* After the render loop is completed, InteractiveScene3D calls this method to sort the interactive scene objects. If nothing was drawn into a container, it's completely
* ignored at this level as well.
*
*/
public function sortObjects():void
{
// called from the scene after the render loop is completed
var sort:Array = [];
for each( var item:InteractiveContainerData in faceDictionary)
{
if(!item.sort) continue;
var distance:Number = item.face3d == null ? item.screenZ : item.face3d.face3DInstance.screenZ;
sort.push({container:item.container, distance:distance});
}
sort.sortOn("distance", Array.DESCENDING | Array.NUMERIC);
for(var i:uint=0;i<sort.length;i++) container.addChild(sort[i].container);
// after the render loop is complete, and we've sorted, we reset the allowDraw flag
if( mouseInteractionMode ) allowDraw = false;
}
/**
* @private
* @param e
*
*/
protected function handleAddedToStage(e:Event):void
{
container.stage.addEventListener (Event.RESIZE, handleResize);
container.stage.addEventListener(MouseEvent.MOUSE_UP, handleReleaseOutside);
virtualMouse.stage = container.stage;
}
/**
* Handles the MOUSE_DOWN event on an InteractiveSprite container
* @param e
*
*/
protected function handleMousePress(e:MouseEvent):void
{
MOUSE_IS_DOWN = true;
if( virtualMouse ) virtualMouse.press();
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_PRESS, Sprite(e.currentTarget));
}
/**
* Handles the MOUSE_UP event on an InteractiveSprite container
* @param e
*
*/
protected function handleMouseRelease(e:MouseEvent):void
{
MOUSE_IS_DOWN = false;
if( virtualMouse ) virtualMouse.release();
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_RELEASE, Sprite(e.currentTarget));
}
/**
* Handles the MOUSE_CLICK event on an InteractiveSprite container
* @param e
*
*/
protected function handleMouseClick(e:MouseEvent):void
{
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_CLICK, Sprite(e.currentTarget));
}
/**
* Handles the MOUSE_OVER event on an InteractiveSprite container
* @param e
*
*/
protected function handleMouseOver(e:MouseEvent):void
{
var eventType:String
eventType = !evaluateClick || !mouseInteractionMode ? InteractiveScene3DEvent.OBJECT_OVER : InteractiveScene3DEvent.OBJECT_CLICK;
evaluateClick = false;
if( virtualMouse && eventType == InteractiveScene3DEvent.OBJECT_CLICK ) virtualMouse.click()
dispatchObjectEvent(eventType, Sprite(e.currentTarget));
}
/**
* Handles the MOUSE_OUT event on an InteractiveSprite container
* @param e
*
*/
protected function handleMouseOut(e:MouseEvent):void
{
if( VirtualMouse && ( faceLevelMode || DisplayObject3D.faceLevelMode ))
{
try
{
var face3d:Face3D = containerDictionary[e.currentTarget];
var p:Object = InteractiveUtils.getMapCoordAtPoint(face3d, container.mouseX, container.mouseY);
var mat:InteractiveMovieMaterial = InteractiveMovieMaterial(face3d.face3DInstance.instance.material);
var rect:Rectangle = new Rectangle(0, 0, mat.movie.width, mat.movie.height);
var contains:Boolean = rect.contains(p.x, p.y);
if (!contains) virtualMouse.exitContainer();
}catch(err:Error)
{
log.error("material type is not Interactive. If you're using a Collada object, you may have to reassign the material to the object after the collada scene is loaded", err.message);
}
}
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_OUT, Sprite(e.currentTarget));
}
/**
* Handles the MOUSE_MOVE event on an InteractiveSprite container
* @param e
*
*/
protected function handleMouseMove(e:MouseEvent):void
{
var point:Object;
if( VirtualMouse && ( faceLevelMode || DisplayObject3D.faceLevelMode ))
{
// need the face3d for the coordinate conversion
var face3d:Face3D = containerDictionary[e.currentTarget];
// get 2D coordinates
point = InteractiveUtils.getMapCoordAtPoint(face3d, container.mouseX, container.mouseY);
//log.debug("material type", ObjectTools.getImmediateClassPath(face3d.face3DInstance.instance.material), face3d.face3DInstance.instance.material is InteractiveMovieMaterial);
try
{
// locate the material's movie
var mat:MovieMaterial = face3d.face3DInstance.instance.material as MovieMaterial;
// set the location where the calcs should be performed
virtualMouse.container = mat.movie as Sprite;
// update virtual mouse so it can test
if( virtualMouse.container ) virtualMouse.setLocation(point.x, point.y);
}catch(err:Error)
{
log.error("material type is not Inter active. If you're using a Collada object, you may have to reassign the material to the object after the collada scene is loaded", err.message);
}
}
dispatchObjectEvent(InteractiveScene3DEvent.OBJECT_MOVE, Sprite(e.currentTarget));
if( Mouse3D.enabled && ( faceLevelMode || DisplayObject3D.faceLevelMode ) )
{
mouse3D.updatePosition(Face3D(containerDictionary[e.currentTarget]), e.currentTarget as Sprite);
}
}
/**
* Handles mouse clicks on the stage. If so, we release a releaseOutside event
* @param e
*
*/
protected function handleReleaseOutside(e:MouseEvent):void
{
if(debug) log.debug("releaseOutside");
dispatchEvent(new InteractiveScene3DEvent(InteractiveScene3DEvent.OBJECT_RELEASE_OUTSIDE));
MOUSE_IS_DOWN = false;
evaluateClick = true
allowDraw = true;
}
/**
* When ISM is in mouseInteractionMode, we capture mouse move events from the stage to trigger a draw
* @param e
*
*/
protected function handleStageMouseMove(e:MouseEvent):void
{
allowDraw = true;
}
/**
* @private
* @param event
* @param currentTarget
*
*/
protected function dispatchObjectEvent(event:String, currentTarget:Sprite):void
{
if(debug) log.debug(event, DisplayObject3D(containerDictionary[currentTarget]).name);
if(containerDictionary[currentTarget] is DisplayObject3D)
{
containerDictionary[currentTarget].dispatchEvent(new InteractiveScene3DEvent(event, containerDictionary[currentTarget], InteractiveSprite(currentTarget)));
dispatchEvent(new InteractiveScene3DEvent(event, containerDictionary[currentTarget], InteractiveSprite(currentTarget), null, null));
}else if(containerDictionary[currentTarget] is Face3D)
{
var face3d:Face3D = containerDictionary[currentTarget];
var face3dContainer:InteractiveContainerData = faceDictionary[face3d];
dispatchEvent(new InteractiveScene3DEvent(event, null, InteractiveSprite(currentTarget), face3d, face3dContainer));
}
}
/**
* @private
* @param e
*
*/
protected function handleResize(e:Event):void
{
resizeStage();
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/utils/InteractiveSceneManager.as | ActionScript | art | 26,380 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* ...
* @author John Grden
* @author De'Angelo Richardson
* @version 0.1
*/
package org.papervision3d.utils
{
import flash.display.Sprite;
import org.papervision3d.objects.DisplayObject3D;
/**
* InteractiveSprite is used whenever a face container is created whether in the ISM or with DO3D's.
*
* It provides a pointer reference back to the DO3D using it as well as the InteractiveContainerData that might be associated with it
* @author John
*
*/
public class InteractiveSprite extends Sprite
{
public var obj:DisplayObject3D = null;
public var interactiveContainerData:InteractiveContainerData = null;
public var x0:Number;
public var x1:Number;
public var x2:Number;
public var y0:Number;
public var y1:Number;
public var y2:Number;
public function InteractiveSprite(obj:DisplayObject3D=null):void
{
this.obj = obj;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/InteractiveSprite.as | ActionScript | art | 2,647 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author John Grden
*/
package org.papervision3d.utils
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.display.SpreadMethod;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.objects.DisplayObject3D;
import flash.display.Sprite;
import flash.display.BlendMode;
import org.papervision3d.utils.InteractiveSprite;
/**
* InteractiveContainerData is a data object for a face or do3d that's passed to the ISM for interaction. It contains the information that glues all objects involved, together.
* @author John
*
*/
public class InteractiveContainerData extends EventDispatcher
{
public var displayObject3D :DisplayObject3D = null;
public var container :InteractiveSprite;
public var face3d :Face3D;
/**
* Used in the initial reset of the scene and then in the drawing stage. if set to true, then it'll be sorted
*/
public var isDrawn :Boolean = false;
/**
* used in the sort method of the ISM - if true, it's included in the sorted array
*/
public var sort :Boolean = false;
/**
* color used for the fill of the face
*/
public var color :Number = InteractiveSceneManager.DEFAULT_FILL_COLOR;
/**
* Alpha value 0-1 of the fill
*/
public var fillAlpha :Number = InteractiveSceneManager.DEFAULT_FILL_ALPHA;
/**
* Line color for the outline of the drawing
*/
public var lineColor :Number = InteractiveSceneManager.DEFAULT_LINE_COLOR;
/**
* Line size to be used
*/
public var lineSize :Number = InteractiveSceneManager.DEFAULT_LINE_SIZE;
/**
* Lind Alpha to be used
*/
public var lineAlpha :Number = InteractiveSceneManager.DEFAULT_LINE_ALPHA;
/**
* Used in the ISM's sort method to sort the containers
* @return
*
*/
public function get screenZ():Number
{
return displayObject3D != null ? displayObject3D.screenZ : face3d.screenZ;
}
public function InteractiveContainerData(container3d:*, p_color:Number=0x000000, target:IEventDispatcher=null)
{
super(target);
displayObject3D = container3d is DisplayObject3D == true ? container3d : null;
face3d = container3d is Face3D == true ? container3d : null;
if( displayObject3D != null ) this.container = new InteractiveSprite(container3d);
if( face3d != null )
{
if( face3d.face3DInstance.container != null )
{
this.container = InteractiveSprite(face3d.face3DInstance.container);
}
else
{
this.container = new InteractiveSprite();
}
}
color = p_color;
container.alpha = InteractiveSceneManager.DEFAULT_SPRITE_ALPHA;
container.interactiveContainerData = this;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/InteractiveContainerData.as | ActionScript | art | 4,590 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Pierre Lepers
* @author De'Angelo Richardson
* @author John Grden
*
* NOTES:
* Special thanks to Blackpawn for this post:
* http://www.blackpawn.com/texts/pointinpoly/default.html
*
* And Pierre Lepers / Away3D for providing the foundational UVatPoint and getCoordAtPoint methods. We're not sure who came out with them first, but wanted
* to thank them both just the same.
*
* These rock!!
* @version 1.0
*/
package org.papervision3d.utils
{
import flash.display.BitmapData;
import flash.geom.Point;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.DisplayObject3D;
/**
* InteractiveUtils are used in conjunction with the ISM to resolve a face's mouse interaction and coordinates back to 2D screen space
*
*
*/
public class InteractiveUtils
{
public static function UVatPoint( face3d:Face3D, x : Number, y : Number ) : Object
{
var v0:Vertex3D = face3d.v0;
var v1:Vertex3D = face3d.v1;
var v2:Vertex3D = face3d.v2;
var v0Dx : Number = v0.vertex2DInstance.x;
var v0Dy : Number = v0.vertex2DInstance.y;
var v1Dx : Number = v1.vertex2DInstance.x;
var v1Dy : Number = v1.vertex2DInstance.y;
var v2Dx : Number = v2.vertex2DInstance.x;
var v2Dy : Number = v2.vertex2DInstance.y;
var v0_x : Number = v2Dx - v0Dx;
var v0_y : Number = v2Dy - v0Dy;
var v1_x : Number = v1Dx - v0Dx;
var v1_y : Number = v1Dy - v0Dy;
var v2_x : Number = x - v0Dx;
var v2_y : Number = y - v0Dy;
var dot00 : Number = v0_x * v0_x + v0_y * v0_y;
var dot01 : Number = v0_x * v1_x + v0_y * v1_y;
var dot02 : Number = v0_x * v2_x + v0_y * v2_y;
var dot11 : Number = v1_x * v1_x + v1_y * v1_y;
var dot12 : Number = v1_x * v2_x + v1_y * v2_y;
var invDenom : Number = 1 / (dot00 * dot11 - dot01 * dot01);
var u : Number = (dot11 * dot02 - dot01 * dot12) * invDenom;
var v : Number = (dot00 * dot12 - dot01 * dot02) * invDenom;
return { u : u, v : v };
}
public static function getCoordAtPoint( face3d:Face3D, x : Number, y : Number ) : Vertex3D
{
var rUV : Object = UVatPoint(face3d, x, y);
var v0x : Number = face3d.v0.x;
var v0y : Number = face3d.v0.y;
var v0z : Number = face3d.v0.z;
var v1x : Number = face3d.v1.x;
var v1y : Number = face3d.v1.y;
var v1z : Number = face3d.v1.z;
var v2x : Number = face3d.v2.x;
var v2y : Number = face3d.v2.y;
var v2z : Number = face3d.v2.z;
var u : Number = rUV.u;
var v : Number = rUV.v;
var rX : Number = v0x + ( v1x - v0x ) * v + ( v2x - v0x ) * u;
var rY : Number = v0y + ( v1y - v0y ) * v + ( v2y - v0y ) * u;
var rZ : Number = v0z + ( v1z - v0z ) * v + ( v2z - v0z ) * u;
return new Vertex3D( rX, rY, rZ );
}
public static function getMapCoordAtPointDO3D( displayObject:DisplayObject3D, x : Number, y : Number ):Object
{
var face:Face3D = displayObject.geometry.faces[0];
return getMapCoordAtPoint(face, x, y);
}
public static function getMapCoordAtPoint( face3d:Face3D, x : Number, y : Number ) : Object
{
var uv:Array = face3d.uv;
var rUV : Object = UVatPoint(face3d, x, y);
var u : Number = rUV.u;
var v : Number = rUV.v;
var u0 : Number = uv[0].u;
var u1 : Number = uv[1].u;
var u2 : Number = uv[2].u;
var v0 : Number = uv[0].v;
var v1 : Number = uv[1].v;
var v2 : Number = uv[2].v;
var v_x : Number = ( u1 - u0 ) * v + ( u2 - u0 ) * u + u0;
var v_y : Number = ( v1 - v0 ) * v + ( v2 - v0 ) * u + v0;
var material:MaterialObject3D = face3d.face3DInstance.instance.material;
var bitmap:BitmapData = material.bitmap;
var width:Number = 1;
var height:Number = 1;
if(bitmap)
{
width = BitmapMaterial.AUTO_MIP_MAPPING ? material.widthOffset : bitmap.width;
height = BitmapMaterial.AUTO_MIP_MAPPING ? material.heightOffset : bitmap.height;
}
return { x:v_x * width, y:height - v_y * height };
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/InteractiveUtils.as | ActionScript | art | 5,971 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author De'Angelo Richardson
*/
package org.papervision3d.utils
{
import com.blitzagency.xray.logger.XrayLog;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.utils.Dictionary;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.scenes.InteractiveScene3D;
import org.papervision3d.utils.InteractiveSceneManager;
import org.papervision3d.utils.InteractiveSprite;
import org.papervision3d.utils.InteractiveUtils;
public class Mouse3D extends DisplayObject3D
{
static private var UP :Number3D = new Number3D(0, 1, 0);
static public var enabled :Boolean = true;
public function Mouse3D(initObject:Object=null):void
{
}
public function updatePosition( face3d:Face3D, container:Sprite ):void
{
var position:Number3D = new Number3D(0, 0, 0);
var target:Number3D = new Number3D(face3d.faceNormal.x, face3d.faceNormal.y, face3d.faceNormal.z);
var zAxis:Number3D = Number3D.sub(target, position);
zAxis.normalize();
if (zAxis.modulo > 0.1)
{
var xAxis:Number3D = Number3D.cross(zAxis, UP);
xAxis.normalize();
var yAxis:Number3D = Number3D.cross(zAxis, xAxis);
yAxis.normalize();
var look:Matrix3D = this.transform;
look.n11 = xAxis.x;
look.n21 = xAxis.y;
look.n31 = xAxis.z;
look.n12 = -yAxis.x;
look.n22 = -yAxis.y;
look.n32 = -yAxis.z;
look.n13 = zAxis.x;
look.n23 = zAxis.y;
look.n33 = zAxis.z;
}
var m:Matrix3D = Matrix3D.IDENTITY;
this.transform = Matrix3D.multiply(face3d.face3DInstance.instance.world, look);
var v:Matrix3D = Matrix3D.IDENTITY;
var mx:Number = container.mouseX;
var my:Number = container.mouseY;
v.n14 = InteractiveUtils.getCoordAtPoint(face3d, mx, my).x;
v.n24 = InteractiveUtils.getCoordAtPoint(face3d, mx, my).y;
v.n34 = InteractiveUtils.getCoordAtPoint(face3d, mx, my).z;
m.calculateMultiply( face3d.face3DInstance.instance.world, v );
x = m.n14;
y = m.n24;
z = m.n34;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/utils/Mouse3D.as | ActionScript | art | 4,011 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.papervision3d.events
{
import flash.events.Event;
/**
* The FileLoadEvent class represents events that are dispatched when files are loaded.
*/
public class FileLoadEvent extends Event
{
public static var LOAD_COMPLETE :String = "loadComplete";
public static var LOAD_ERROR :String = "loadError";
public static var SECURITY_LOAD_ERROR :String = "securityLoadError";
public static var COLLADA_MATERIALS_DONE :String = "colladaMaterialsDone";
public static var LOAD_PROGRESS :String = "loadProgress";
public var file:String = "";
public var bytesLoaded:Number = -1;
public var bytesTotal:Number = -1;
public var message:String = "";
public var dataObj:Object = null;
public function FileLoadEvent( type:String, file:String="", bytesLoaded:Number=-1, bytesTotal:Number=-1, message:String="", dataObj:Object = null, bubbles:Boolean=false, cancelable:Boolean=false)
{
super( type, bubbles, cancelable );
this.file = file;
this.bytesLoaded = bytesLoaded;
this.bytesTotal = bytesTotal;
this.message = message;
this.dataObj = dataObj;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/events/FileLoadEvent.as | ActionScript | art | 2,867 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* ...
* @author John Grden
* @version 0.1
*/
package org.papervision3d.events
{
import flash.events.Event;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.objects.DisplayObject3D;
import flash.display.Sprite;
import org.papervision3d.utils.InteractiveContainerData;
public class InteractiveScene3DEvent extends Event
{
/**
* Dispatched when a container in the ISM recieves a MouseEvent.CLICK event
* @eventType mouseClick
*/
public static const OBJECT_CLICK:String = "mouseClick";
/**
* Dispatched when a container in the ISM receives an MouseEvent.MOUSE_OVER event
* @eventType mouseOver
*/
public static const OBJECT_OVER:String = "mouseOver";
/**
* Dispatched when a container in the ISM receives an MouseEvent.MOUSE_OUT event
* @eventType mouseOut
*/
public static const OBJECT_OUT:String = "mouseOut";
/**
* Dispatched when a container in the ISM receives a MouseEvent.MOUSE_MOVE event
* @eventType mouseMove
*/
public static const OBJECT_MOVE:String = "mouseMove";
/**
* Dispatched when a container in the ISM receives a MouseEvent.MOUSE_PRESS event
* @eventType mousePress
*/
public static const OBJECT_PRESS:String = "mousePress";
/**
* Dispatched when a container in the ISM receives a MouseEvent.MOUSE_RELEASE event
* @eventType mouseRelease
*/
public static const OBJECT_RELEASE:String = "mouseRelease";
/**
* Dispatched when the main container of the ISM is clicked
* @eventType mouseReleaseOutside
*/
public static const OBJECT_RELEASE_OUTSIDE:String = "mouseReleaseOutside";
/**
* Dispatched when a container is created in the ISM for drawing and mouse interaction purposes
* @eventType objectAdded
*/
public static const OBJECT_ADDED:String = "objectAdded";
public var displayObject3D :DisplayObject3D = null;
public var sprite :Sprite = null;
public var face3d :Face3D = null;
public var interactiveContainerData :InteractiveContainerData = null;
public function InteractiveScene3DEvent(type:String, container3d:DisplayObject3D=null, sprite:Sprite=null, face3d:Face3D=null, interactiveContainerData:InteractiveContainerData=null, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
this.displayObject3D = container3d;
this.sprite = sprite;
this.face3d = face3d;
this.interactiveContainerData = interactiveContainerData;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/events/InteractiveScene3DEvent.as | ActionScript | art | 4,246 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// CameraObject3D: Camera3D
package org.papervision3d.cameras
{
import org.papervision3d.Papervision3D;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.objects.DisplayObject3D;
/**
* The Camera3D class creates a camera that views the area around a target object.
* <p/>
* A camera defines the view from which a scene will be rendered. Different camera settings would present a scene from different points of view.
* <p/>
* 3D cameras simulate still-image, motion picture, or video cameras of the real world. When rendering, the scene is drawn as if you were looking through the camera lens.
*/
public class Camera3D extends CameraObject3D
{
// __________________________________________________________________________
// PUBLIC
/**
* A DisplayObject3D object that specifies the current position the camera is looking at.
*/
public var target :DisplayObject3D;
/**
* A Number3D object that specifies the desired position of the camera in 3D space. Only used when calling update().
*/
public var goto :Number3D;
/**
* A Number3D object that specifies the desired rotation of the camera in 3D space. Only used when calling update().
*/
// public var gotoRotation :Number3D;
/**
* A Number3D object that specifies the desired position of the camera's target in 3D space. Only used when calling update().
*/
// public var gotoTarget :Number3D;
// __________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* The Camera3D constructor creates cameras that view the area around a target object.
*
* Its initial position can be specified in the initObject.
*
* @param zoom This value specifies the scale at which the 3D objects are rendered. Higher values magnify the scene, compressing distance. Use it in conjunction with focus.
* <p/>
* @param focus This value is a positive number representing the distance of the observer from the front clipping plane, which is the closest any object can be to the camera. Use it in conjunction with zoom.
* <p/>
* @param initObject An optional object that contains user defined properties with which to populate the newly created DisplayObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
* <p/>
* The following initObject property is also recognized by the constructor:
* <ul>
* <li><b>sort</b>: A Boolean value that determines whether the 3D objects are z-depth sorted between themselves when rendering. The default value is true.</li>
* </ul>
*/
public function Camera3D( target:DisplayObject3D=null, zoom:Number=2, focus:Number=100, initObject:Object=null )
{
super( zoom, focus, initObject );
this.target = target || DisplayObject3D.ZERO;
this.goto = new Number3D( this.x, this.y, this.z );
// this.goTarget = new Number3D( this.target.x, this.target.y, this.target.z );
}
// ___________________________________________________________________________________________________
// T R A N S F O R M
// TTTTTT RRRRR AA NN NN SSSSS FFFFFF OOOO RRRRR MM MM
// TT RR RR AAAA NNN NN SS FF OO OO RR RR MMM MMM
// TT RRRRR AA AA NNNNNN SSSS FFFF OO OO RRRRR MMMMMMM
// TT RR RR AAAAAA NN NNN SS FF OO OO RR RR MM M MM
// TT RR RR AA AA NN NN SSSSS FF OOOO RR RR MM MM
/**
* [internal-use] Transforms world coordinates into camera space.
*/
public override function transformView( transform:Matrix3D=null ):void
{
this.lookAt( this.target );
super.transformView();
}
// ___________________________________________________________________________________________________
//
// UU UU PPPPP DDDDD AA TTTTTT EEEEEE
// UU UU PP PP DD DD AAAA TT EE
// UU UU PPPPP DD DD AA AA TT EEEE
// UU UU PP DD DD AAAAAA TT EE
// UUUU PP DDDDD AA AA TT EEEEEE
/**
* [experimental] Hovers the camera around as the user moves the mouse, without changing the distance to the target. This greatly enhances the 3D illusion.
*
* @param type Type of movement.
* @param mouseX Indicates the x coordinate of the mouse position in relation to the canvas MovieClip.
* @param mouseY Indicates the y coordinate of the mouse position in relation to the canvas MovieClip.
*/
public function hover( type:Number, mouseX:Number, mouseY:Number ):void
{
var target :DisplayObject3D = this.target;
var goto :Number3D = this.goto;
// var gotoTarget :Number3D = this.gotoTarget;
var camSpeed :Number = 8;
switch( type )
{
case 0:
// Sphere mapped camera (free)
var dX :Number = goto.x - target.x;
var dZ :Number = goto.z - target.z;
var ang :Number = Math.atan2( dZ, dX );
var dist :Number = Math.sqrt( dX*dX + dZ*dZ );
var xMouse :Number = 0.5 * mouseX;
var camX :Number = dist * Math.cos( ang - xMouse );
var camZ :Number = dist * Math.sin( ang - xMouse );
var camY :Number = goto.y - 300 * mouseY;
this.x -= (this.x - camX) /camSpeed;
this.y -= (this.y - camY) /camSpeed;
this.z -= (this.z - camZ) /camSpeed;
break;
case 1:
this.x -= (this.x - 1000 * mouseX) /camSpeed;
this.y -= (this.y - 1000 * mouseY) /camSpeed;
// this.z -= (this.z - ) /camSpeed;
break;
/*
// BROKEN
case ???:
// Sphere mapped camera (fixed)
var dX = cam.pos.gx - cam.target.x;
var dZ = cam.pos.gz - cam.target.z;
ang -= ( ang - (Math.atan2( dZ, dX ) - iCanvas._xmouse/300) ) /camSpeed;
dist -= ( dist - Math.sqrt( dX*dX + dZ*dZ ) ) /camSpeed;
var camX = dist * Math.cos( ang );
var camZ = dist * Math.sin( ang );
var camY = -iCanvas._ymouse/3;
cam.pos.x = camX;
cam.pos.y -= (cam.pos.y - (camY + cam.pos.gy) ) /camSpeed;
cam.pos.z = camZ;
break;
*/
}
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/cameras/Camera3D.as | ActionScript | art | 8,464 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ FREECAMERA3D
package org.papervision3d.cameras
{
import org.papervision3d.core.Matrix3D;
import org.papervision3d.core.proto.CameraObject3D;
/**
* The FreeCamera3D class creates a camera that views the area in the direction the camera is aimed.
* <p/>
* A camera defines the view from which a scene will be rendered. Different camera settings would present a scene from different points of view.
* <p/>
* 3D cameras simulate still-image, motion picture, or video cameras of the real world. When rendering, the scene is drawn as if you were looking through the camera lens.
*/
public class FreeCamera3D extends CameraObject3D
{
// ___________________________________________________________________ NEW
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* The FreeCamera3D constructor lets you create a camera that views the area in the direction the camera is aimed.
*
* Its initial position can be specified in the initObject.
*
* @param zoom This value specifies the scale at which the 3D objects are rendered. Higher values magnify the scene, compressing distance. Use it in conjunction with focus.
* <p/>
* @param focus This value is a positive number representing the distance of the observer from the front clipping plane, which is the closest any object can be to the camera. Use it in conjunction with zoom.
* <p/>
* @param initObject An optional object that contains user defined properties with which to populate the newly created DisplayObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
* <p/>
* The following initObject property is also recognized by the constructor:
* <ul>
* <li><b>sort</b>: A Boolean value that determines whether the 3D objects are z-depth sorted between themselves when rendering. The default value is true.</li>
* </ul>
*/
public function FreeCamera3D( zoom:Number=2, focus:Number=100, initObject:Object=null )
{
super( zoom, focus, initObject );
}
/**
* [internal-use] Transforms world coordinates into camera space.
*/
// TODO OPTIMIZE (LOW)
public override function transformView( transform:Matrix3D=null ):void
{
if( this._transformDirty ) updateTransform();
// Rotate Z
super.transformView();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/cameras/FreeCamera3D.as | ActionScript | art | 4,385 |
/**
* @author John Grden
*/
package org.papervision3d.components.as3.flash9
{
import com.blitzagency.xray.logger.XrayLog;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.utils.Timer;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.cameras.FreeCamera3D;
import org.papervision3d.components.as3.core.PV3DUIComponent;
import org.papervision3d.components.as3.utils.CoordinateTools;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.MovieScene3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.scenes.InteractiveScene3D;
/**
* Dispatched when the Scene3D has been created along with the camera.
*
* @eventType org.papervision3d.components.as3.flash9.PV3DScene3D.SCENE_INIT
*/
[Event(name="sceneInit", type="flash.events.Event")]
/**
* PV3DScene3D creates a MovieScene3D and FreeCamera3D for quick scene and resize management. You can access the scene and camera for full control with code at runtime.
*
*/
public class PV3DScene3D extends PV3DUIComponent
{
/**
* @eventType sceneInit
*/
public static const SCENE_INIT:String = "sceneInit";
// public vars
// component UI handlers
[Inspectable ( defaultValue="Free", enumeration="Free, Target", type="List", name="Camera Type" )]
/**
* @private
*/
public var cameraType :String = "Free";
[Inspectable ( type="Number", defaultValue=-1000, name="Camera Z")]
/**
* @private
*/
public function set cameraZ(z:Number):void
{
_cameraZ = z;
try
{
currentCamera3D.z = z;
updateScene();
}catch(e:Error)
{
}
}
/**
* @private
*/
public function get cameraZ():Number
{
return _cameraZ;
}
[Inspectable ( type="Number", defaultValue=1, name="Camera Zoom")]
/**
* @private
*/
public function set cameraZoom(zoom:Number):void
{
_cameraZoom = zoom;
try
{
currentCamera3D.zoom = zoom;
updateScene();
}catch(e:Error)
{
}
}
/**
* @private
*/
public function get cameraZoom():Number
{
return _cameraZoom;
}
[Inspectable ( type="Number", defaultValue=300, name="Camera Focus")]
/**
* @private
*/
public function set cameraFocus(focus:Number):void
{
_cameraFocus = focus;
try
{
currentCamera3D.focus = focus;
updateScene();
}catch(e:Error)
{
// camera not ready
}
}
/**
* @private
*/
public function get cameraFocus():Number
{
return _cameraFocus;
}
/**
* @private
*/
public var currentCamera3D :CameraObject3D;
/**
* @private
*/
public function set cameraTarget(p_target:DisplayObject3D):void
{
_cameraTarget = p_target;
targetCam.target = _cameraTarget;
}
/**
* @private
*/
public function get cameraTarget():DisplayObject3D
{
return _cameraTarget;
}
// scenes
/**
* @private
*/
protected var _scene :InteractiveScene3D = null;
/**
* The InteractiveScene3D used by the component
*/
public function set scene(scene3d:InteractiveScene3D):void
{
_scene = scene3d;
}
public function get scene():InteractiveScene3D
{
return _scene;
}
/**
* The camera used by the component. FreeCamer3D by default
* @return
*
*/
public function get camera():CameraObject3D { return currentCamera3D; }
public function set camera(p_camera:CameraObject3D):void { currentCamera3D = p_camera; }
/**
* @private
*/
protected var timer :Timer = new Timer(25,0);
// cameras
/**
* @private
*/
protected var targetCam :Camera3D;
/**
* @private
*/
protected var _cameraTarget :DisplayObject3D;
/**
* @private
*/
protected var _cameraZ :Number = -1000;
/**
* @private
*/
protected var _cameraZoom :Number = 1;
/**
* @private
*/
protected var _cameraFocus :Number = 300;
/**
* @private
*/
protected var freeCam :FreeCamera3D;
/**
* The sprite container where the scene will be drawn
*/
protected var canvas :Sprite = null;
/**
* @private
*/
protected var mainCanvas :Sprite = null;
public function PV3DScene3D()
{
super();
initApp();
}
/**
* Used to pause the rendering of the scene
*
*/
public function pause():void
{
timer.stop();
}
/**
* Used to resume the rendering of the scene
*
*/
public function resume():void
{
timer.start();
}
/**
* @private
*/
override protected function configUI():void
{
//log.debug("configUI");
if(isLivePreview)
{
//trace("displayLogo?");
displayLogo();
}
manageStageSize();
var coordinates:Point = CoordinateTools.localToLocal(this, parent);
screenOffsetX = coordinates.x;
screenOffsetY = coordinates.y;
canvas = new Sprite();
canvas.name = "canvas";
mainCanvas = new Sprite();
mainCanvas.name = "mainCanvas";
addChild(canvas);
canvas.addChild(mainCanvas);
createCamera(cameraType);
// create scene object
init3D();
// updateScene
if(!isLivePreview)
{
timer.addEventListener(TimerEvent.TIMER, handleTimerUpdate);
timer.start();
}else
{
// gives me 5 frame updates it seems
stage.addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
}
/**
* @private
*/
protected function displayLogo():void
{
var logo:Logo = new Logo();
addChild(logo);
}
/**
* @private
*/
protected function init3D():void
{
// Scene - we use InteractiveScene3D by default and we assume this for them since they're in the IDE
createScene();
dispatchEvent(new Event(SCENE_INIT));
}
protected function createScene():void
{
scene = new InteractiveScene3D( mainCanvas );
}
/**
* @private
*/
protected function createCamera(cameraChoice:String):void
{
switch(cameraChoice)
{
case "Free":
currentCamera3D = freeCam = new FreeCamera3D();
break;
case "Target":
currentCamera3D = targetCam = new Camera3D();
break;
}
currentCamera3D.z = cameraZ;
currentCamera3D.zoom = cameraZoom;
currentCamera3D.focus = cameraFocus;
}
/**
* @private
*/
override protected function alignStage():void
{
try
{
//log.debug("alignStage width/height", (sceneWidth/2) + ", " + (sceneHeight/2));
mainCanvas.x = sceneWidth/2;//stage.stageWidth/2;
mainCanvas.y = sceneHeight/2;//stage.stageHeight/2;
updateScene();
//scene.renderCamera( freeCam );
}catch(e:Error)
{
//log.error("alignStage Error", e.message);
}
}
/**
* @private
*/
protected function handleTimerUpdate(e:TimerEvent):void
{
updateScene();
}
/**
* @private
*/
protected function handleEnterFrame(e:Event):void
{
//trace("enter frame");
updateScene();
}
/**
* @private
*/
protected function updateScene():void
{
try
{
scene.renderCamera( currentCamera3D );
}catch(e:Error)
{
//log.debug("updateScene error", e.message);
}
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/flash9/PV3DScene3D.as | ActionScript | art | 7,853 |
/**
* @author John Grden
*/
package org.papervision3d.components.as3.flash9
{
import com.blitzagency.xray.logger.util.PropertyTools;
import fl.data.SimpleDataProvider;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Dictionary;
import flash.utils.Timer;
import org.papervision3d.components.as3.collections.MaterialsListItem;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.objects.Collada;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.InteractiveBitmapFileMaterial;
import org.papervision3d.materials.InteractiveMovieAssetMaterial;
import org.papervision3d.materials.InteractiveBitmapAssetMaterial;
import org.papervision3d.components.as3.utils.ObjectController;
/**
* Dispatched when the collada file and materials have been completely parsed and loaded.
*
* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_COMPLETE
*/
[Event(name="sceneComplete", type="flash.events.Event")]
/**
* Dispatched while the collada file is loading.
* <p>Event carries 2 properties:
* <ul>
* <li>1. bytesLoaded
* <li>2. bytesTotal
* </ul>
* </p>
* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_LOAD_PROGRESS
*/
[Event(name="sceneLoadProgress", type="flash.events.Event")]
/**
* Dispatched when the collada object cannot load the file specified either because of security or non-existance
* <p>
* provides a property called "message" which is the actual load error initially received.
* </p>
* @eventType org.papervision3d.components.as3.flash9.PV3DColladaScene.SCENE_LOAD_ERROR
*/
[Event(name="sceneLoadError", type="flash.events.Event")]
/**
* PV3DColladaScene is the main class for the Flash CS3 COLLADA component.
* </p>
* <p>It's main purpose is to provide the developer/designer with drag and drop functionality to render a COLLADA scene with a camera and Scene3D. Full access to a materials list and objects
* is given through the api:
* <ul>
* <li>scene</li>
* <li>camera</li>
* <li>collada</li>
* </ul>
* </p>
* <p>The component includes a Custom Panel via Windows>other panels>PV3DPanel</P>
* <p>To use the component, drag it from the components list on to the stage in the Flash IDE. First, set the local directory by clicking on the folder icon in the Panel.
* Then, select the DAE (COLLADA) file to use. At this point, you *should* see your 3D scene being rendered.
* </p>
* <p>You might have to play with the scale if you're not seeing the scene or camera Z (move it out more).
* </p>
* <p>If you textured your models with bitmaps in your 3D application, COLLADA retains those file paths and Papervision3D will attempt to dynamically load them for you IF you don't
* provide a materials list. So, there is a good chance you'll see your scene fully textured once you've provided the local directory and file paths.
* </p>
* <p>If you provide a MaterialsList via the property inspector, there are 3 types supported:
* <ul>
* <li>Bitmap: BitmapAssetMaterial - a bitmap defined in the library</li>
* <li>MovieClip: MovieAssetMaterial - a MovieClip defined in the library</li>
* <li>File: BitmapFileMaterial - an external bitmap file</li>
* </ul>
*
* </p>
* @see org.papervision3d.components.as3.collections.MaterialsListItem
*/
public class PV3DColladaScene extends PV3DScene3D
{
/**
* @eventType sceneComplete
*/
public static const SCENE_COMPLETE :String = "sceneComplete";
/**
* @eventType sceneLoadProgress
*/
public static const SCENE_LOAD_PROGRESS :String = "sceneLoadProgress";
/**
* @eventType sceneLoadError
*/
public static const SCENE_LOAD_ERROR :String = "sceneLoadError";
/**
* A boolean flag letting the component know whether or not to show trace output
*/
public var debug :Boolean = false;
private var _materialsList :MaterialsList = new MaterialsList();
/**
* The MaterialsList object that is used by the component if one is provided. This is set at design-time and is read-only at runtime
*/
public function get materialsList():MaterialsList { return _materialsList; }
private var _col :Collada;
private var _colladaFile :String = "";
private var _localPath :String = "";
private var _sceneScale :Number = 0;
private var rebuildCollada :Boolean = false;
private var _rotationList :Object = {pitch:0, yaw:0, roll:0};
private var _extMaterials :SimpleDataProvider = new SimpleDataProvider();
private var materialsQue :Dictionary = new Dictionary();
private var previewTimer :Timer = new Timer(25,0);
/**
* @private
* @note Called when the component is actually running in a compiled SWF at runtime, rather than LivePreview
* @param p_piSetting
*
*/
override public function set componentInspectorSetting(p_piSetting:Boolean):void
{
_componentInspectorSetting = p_piSetting;
if(debug) log.debug("componentInspectorSetting", p_piSetting);
if(!_componentInspectorSetting)
{
initApp();
if(debug) log.debug("colladaFile?", colladaFile);
if(debug) log.debug("isLivePreview?", isLivePreview);
// just start by building materials and it'll light up from there.
createMaterials();
}
}
/**
* @private
*/
override public function get componentInspectorSetting():Boolean
{
return _componentInspectorSetting;
}
/**
* The Papervision3D Collada object created for the component's use.
* @return Collada object
*
*/
public function get collada():Collada
{
return _col;
}
public function set collada(col:Collada):void
{
_col = col;
}
/**
* this fires after all of the properties have been updated. The Property Inspector (pi) sets all properties for a component even if only 1 is updated.
* So, the modified LivePreviewParent I created makes this call to propertyInspectorSetting and passes a flag to let the component know that's its
* ok to proceed with dealing with the changes.
*
* Changes have to be dealt with in a specific order. Materials, then collada WITH scale passed in the constructor, then rotation after collada is completely loaded.
* @private
*/
override public function set propertyInspectorSetting(p_piSetting:Boolean):void
{
_propertyInspectorSetting = p_piSetting;
if(!p_piSetting)
{
// if we haven't initialized yet, do so
if(!isAppInitialized) initApp();
if(debug) log.debug("********** isLivePreview?", isLivePreview);
if(rebuildCollada || collada == null)
{
if(debug) log.debug("GO CREATE MATERIALS");
createMaterials();
}else
{
if(debug) log.debug("GO update collada");
finalizeColladaLoad();
}
}
if(debug) log.debug("propertyInspectorSetting", p_piSetting);
}
/**
* @private
*/
override public function get propertyInspectorSetting():Boolean
{
return _propertyInspectorSetting;
}
[Inspectable (name="Scene Rotation", defaultValue=false, type="Boolean")]
/**
* Boolean flag indicating whether or not to add mouse drag/rotation abilities to the collada container. Clicking
* yes will allow you to use simple dragging to rotate the scene.
*/
public var sceneRotation :Boolean = true;
[Inspectable (type="String", defaultValue="", name="Local Directory") ]
/**
* @private
*/
public function set localPath(p_localPath:String):void
{
if(p_localPath != _localPath && p_localPath.length > 0)
{
p_localPath = p_localPath.split("\\").join("/");
_localPath = p_localPath.substring(p_localPath.length-1) == "/" ? p_localPath : p_localPath + "/";
}
}
/**
* @private
*/
public function get localPath():String
{
return _localPath;
}
[Inspectable (type="String", defaultValue="", name="Collada File") ]
/**
* A relative reference to the external collada file to be used
* @return String
*
*/
public function set colladaFile(p_colladaFile:String):void
{
if(_colladaFile != p_colladaFile && p_colladaFile.length > 0)
{
if(debug) log.debug("set colladaFile", p_colladaFile);
rebuildCollada = true;
_colladaFile = p_colladaFile;
}
}
public function get colladaFile():String
{
return _colladaFile;
}
[Collection(name="Materials List", collectionClass="fl.data.SimpleDataProvider", collectionItem="org.papervision3d.components.as3.collections.MaterialsListItem", identifier="item")]
/**
* @private
*/
public function set extMaterials(p_extMaterials:SimpleDataProvider):void
{
if(p_extMaterials.dataProvider.length > 0 && !checkMaterialListsMatch(extMaterials, p_extMaterials))
{
if(debug) log.debug("****** COMPARE", checkMaterialListsMatch(extMaterials, p_extMaterials));
_extMaterials = p_extMaterials;
rebuildCollada = true;
}
}
/**
* @private
*/
public function get extMaterials():SimpleDataProvider { return _extMaterials; }
[Inspectable (type="Number", defaultValue=.01, name="Scale") ]
/**
* @private
*/
public function set sceneScale(p_scale:Number):void
{
if(p_scale == _sceneScale) return;
_sceneScale = p_scale;
if(isLivePreview && (collada != null && colladaFile.length > 0))
{
// force an object redraw
rebuildCollada = true;
}
}
/**
* @private
*/
public function get sceneScale():Number
{
return _sceneScale;
}
[Inspectable (type="Object", defaultValue="pitch:0, yaw:0, roll:0", name="Initial Rotation") ]
/**
* @private
*/
public function set rotationList(p_rotation:Object):void
{
_rotationList = p_rotation;
}
/**
* @private
*/
public function get rotationList():Object
{
return _rotationList;
}
public function PV3DColladaScene()
{
//BitmapMaterial.AUTO_MIP_MAPPING = true;
super();
}
/**
* @private
*/
override protected function init3D():void
{
super.init3D();
initScene();
}
/**
* @private
*/
protected function initScene():void
{
}
/**
* @private
* Creates the 3 main types of materials and loads external materials.
*
* Note that smooth has been pulled. It was causing rte's about smooth not being a property of the materials. Will have to fix later.
*/
protected function createMaterials():void
{
if(debug) log.debug("extMaterials", extMaterials.dataProvider.length);
var loadCollada:Boolean = false;
if(extMaterials.dataProvider.length > 0)
{
// reset the materials que
materialsQue = new Dictionary();
var clrMat:ColorMaterial = new ColorMaterial(0x00ff00, .75);
for(var i:Number=0;i<extMaterials.dataProvider.length;i++)
{
// materials are in library with linkage
var materialsListItem:MaterialsListItem = MaterialsListItem(extMaterials.dataProvider[i]);
switch(materialsListItem.materialType.toLowerCase())
{
case "bitmap":
if(isLivePreview)
{
clrMat.oneSide = materialsListItem.singleSided;
materialsList.addMaterial(clrMat, materialsListItem.materialName);
}else
{
var bam:BitmapAssetMaterial = materialsListItem.interactive ? new InteractiveBitmapAssetMaterial(materialsListItem.materialLinkageID) : new BitmapAssetMaterial(materialsListItem.materialLinkageID);;
loadCollada = true;
bam.oneSide = materialsListItem.singleSided;
//bam.smooth = materialsListItem.smooth;
materialsList.addMaterial(bam, materialsListItem.materialName);
}
if(!checkForFileLoads(extMaterials)) loadCollada = true;
break;
case "file":
var fileLocation:String = isLivePreview ? _localPath + materialsListItem.materialFileLocation : materialsListItem.materialFileLocation;
fileLocation = fileLocation.split("\\").join("/");
if(debug) log.debug("File to load", fileLocation);
var bm:BitmapFileMaterial = materialsListItem.interactive ? new InteractiveBitmapFileMaterial("") : new BitmapFileMaterial("");
bm.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapFileLoadComplete);
materialsQue[bm] = false;
// setting the texture property actually causes the load of the file
bm.texture = fileLocation;
//bm.smooth = materialsListItem.smooth;
// because we didn't set the URL through the constructor, we have to set it manually if we want it back in the event thats disatched
bm.url = fileLocation;
bm.oneSide = materialsListItem.singleSided;
materialsList.addMaterial(bm, materialsListItem.materialName);
break;
case "movieclip":
if(isLivePreview)
{
clrMat.oneSide = materialsListItem.singleSided;
materialsList.addMaterial(clrMat, materialsListItem.materialName);
}else
{
var mov:MovieAssetMaterial = materialsListItem.interactive ? new InteractiveMovieAssetMaterial(materialsListItem.materialLinkageID, materialsListItem.transparent) : new MovieAssetMaterial(materialsListItem.materialLinkageID, materialsListItem.transparent);
if(materialsListItem.animated) mov.animated = true;
mov.oneSide = materialsListItem.singleSided;
//mov.smooth = materialsListItem.smooth;
materialsList.addMaterial(mov, materialsListItem.materialName);
}
if(!checkForFileLoads(extMaterials)) loadCollada = true;
break;
}
}
}else
{
if(debug) log.debug("*************************** NO MATERIALS TO LOAD***************");
loadCollada = true;
}
if(loadCollada) createColladaScene();
}
/**
* @private
* Checks the load que to make sure all files are loaded before loading the collada scene
*/
private function checkForFileLoads(obj:SimpleDataProvider):Boolean
{
for(var i:Number=0;i<obj.dataProvider.length;i++)
{
var materialsListItem:MaterialsListItem = MaterialsListItem(extMaterials.dataProvider[i]);
if(debug) log.debug("@@@@@@@@@@@@@@@@ checkForFileLoads", materialsListItem.materialType.toLowerCase())
if(materialsListItem.materialType.toLowerCase() == "file") return true;
}
return false;
}
/**
* @private
* When an external file is completely loaded, we receive this event and check to see if all the files have been loaded before loading the collada scene
*/
protected function handleBitmapFileLoadComplete(e:FileLoadEvent):void
{
if(debug) log.debug("%%%%%% handleBitmapFileLoadComplete", e.file);
materialsQue[e.target] = true;
var bm:BitmapFileMaterial = BitmapFileMaterial(e.target);
bm.removeEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapFileLoadComplete);
if(collada != null && materialsList.numMaterials > 0) collada.materials = materialsList;
if(colladaFile.length > 0 && checkLoadedQue())
{
if(debug) log.debug("should load collada after getting all bitmaps");
createColladaScene();
}
}
/**
* @private
*/
protected function checkLoadedQue():Boolean
{
for each(var items:Object in materialsQue)
{
if(!items) return false;
}
return true;
}
/**
* @private
*/
override protected function stageResizeHandler(e:Event):void
{
if(!resizeWithStage) return;
if(debug) log.debug("stageResize");
resizeStage();
}
/**
* @private
* Creates the Collada object and loads the file
*/
protected function createColladaScene():void
{
if(colladaFile.length == 0) return;
if(debug) log.debug("createColladaScene", colladaFile, scene == null);
if(collada != null) scene.removeChild(collada);
var fileLocation:String = isLivePreview ? _localPath + colladaFile : colladaFile;
if(debug) log.debug("fileLocation for collada", fileLocation);
if(collada) collada.container.graphics.clear();
collada = new Collada(fileLocation, materialsList, sceneScale,{localPath:localPath});
scene.addChild(collada);
collada.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
//collada.addEventListener(FileLoadEvent.COLLADA_MATERIALS_DONE, handleLoadComplete);
collada.addEventListener(FileLoadEvent.LOAD_PROGRESS, handleLoadProgress);
collada.addEventListener(FileLoadEvent.LOAD_ERROR, handleLoadError);
collada.addEventListener(FileLoadEvent.SECURITY_LOAD_ERROR, handleLoadError);
}
/**
* @private
* Called when Collada file is completely rendered
*/
protected function handleLoadComplete(e:FileLoadEvent):void
{
if(debug) log.debug("handleLoadComplete - Collada", e.file);
// remove listeners
collada.removeEventListener(FileLoadEvent.LOAD_COMPLETE, handleLoadComplete);
collada.removeEventListener(FileLoadEvent.LOAD_PROGRESS, handleLoadProgress);
collada.removeEventListener(FileLoadEvent.LOAD_ERROR, handleLoadError);
collada.removeEventListener(FileLoadEvent.SECURITY_LOAD_ERROR, handleLoadError);
finalizeColladaLoad();
}
/**
* @private
* Called when Collada progress event is dispatched
*/
protected function handleLoadProgress(e:FileLoadEvent):void
{
dispatchEvent(new FileLoadEvent(SCENE_LOAD_PROGRESS, e.file, e.bytesLoaded, e.bytesTotal));
}
/**
* @private
* Called when Collada has an error with loading the DAE file specified
*/
protected function handleLoadError(e:FileLoadEvent):void
{
dispatchEvent(new FileLoadEvent(SCENE_LOAD_ERROR, e.file, 0, 0, e.message));
}
/**
* @private
* Called after Collada file is loaded completely. sets the rotation, and updates the scene.
*/
protected function finalizeColladaLoad():void
{
collada.rotationX = rotationList.pitch;
collada.rotationY = rotationList.yaw;
collada.rotationZ = rotationList.roll;
updateScene();
dispatchEvent(new FileLoadEvent(SCENE_COMPLETE));
// set to false so no unnecessary redraws occur
rebuildCollada = false;
if(sceneRotation && !isLivePreview)
{
ObjectController.getInstance().registerStage(this.stage);
ObjectController.getInstance().registerControlObject(collada);
}
// for debugging
if(debug) showChildren();
}
/**
* @private
* Just for testing to see the children of the collada object
*/
private function showChildren():void
{
for each(var item:Object in collada.children) if(debug) trace("collada children: ", item.name);
}
/**
* @private
*/
override protected function handleTimerUpdate(e:TimerEvent):void
{
updateScene();
}
/**
* @private
* Used for matching the materials list that comes in when an update occurs on the component at Designtime. A brand new version is sent with every change to the
* component at design time, so we have to crawl through and verify if it's been changed to really know if we need to re-render the collada scene.
*/
private function checkMaterialListsMatch(obj_0:SimpleDataProvider, obj_1:SimpleDataProvider):Boolean
{
if(obj_0.dataProvider.length != obj_1.dataProvider.length) return false;
for(var i:Number=0;i<obj_0.dataProvider.length;i++)
{
// materials are in library with linkage
var m0:MaterialsListItem = MaterialsListItem(obj_0.dataProvider[i]);
var m1:MaterialsListItem = MaterialsListItem(obj_1.dataProvider[i]);
var props:Array = PropertyTools.getProperties(m0);
for (var ii:Number=0;i<props.length;i++)
{
if(debug) log.debug("compare", m0[props[i].name] + ", " + m1[props[i].name]);
if(m0[props[i].name] != m1[props[i].name]) return false;
}
}
return true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/flash9/PV3DColladaScene.as | ActionScript | art | 20,782 |
/**
* @private
*/
package org.papervision3d.components.as3.flash9
{
import flash.display.DisplayObject
public class Logo extends DisplayObject
{
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/flash9/Logo.as | ActionScript | art | 164 |
package org.papervision3d.components.as3.utils
{
/*
Copyright (c) 2007 John Grden
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author John Grden
*/
import com.blitzagency.xray.logger.XrayLog;
//import com.rockonflash.papervision3d.modelviewer.events.ObjectControllerEvent;
import flash.display.Stage;
import flash.events.EventDispatcher;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.ui.Keyboard;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.utils.setInterval;
import org.papervision3d.objects.DisplayObject3D;
public class ObjectController extends EventDispatcher
{
private static var _instance:ObjectController = null;
public static function getInstance():ObjectController
{
if(_instance == null) _instance = new ObjectController();
return _instance;
}
public var isMouseDown :Boolean;
public var restrictInversion :Boolean = false;
protected var currentRotationObj:DisplayObject3D;
protected var arrowLeft :Boolean;
protected var arrowUp :Boolean;
protected var arrowRight :Boolean;
protected var arrowDown :Boolean;
protected var lastX :Number;
protected var lastY :Number;
protected var difX :Number;
protected var difY :Number;
protected var si :Number;
//protected var timer :Timer = new Timer(25,0);
protected var movementInc :Number = 1;
private var log :XrayLog = new XrayLog();
private var stage :Stage;
public function ObjectController()
{
// constructor
//Mouse.addListener(this);
//Keyboard.addListener(this);
//timer.addEventListener(TimerEvent.TIMER, handleTimerTick);
//timer.start();
}
public function registerControlObject(obj:DisplayObject3D):void
{
currentRotationObj = obj;
}
public function registerStage(p_stage:Stage):void
{
stage = p_stage;
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
updateLastRotation();
updateDif();
}
protected function updateLastRotation():void
{
lastX = stage.mouseX;
lastY = stage.mouseY;
}
protected function updateDif():void
{
difX = Number(stage.mouseX - lastX);
difY = Number(stage.mouseY - lastY);
}
protected function onMouseDown(e:MouseEvent):void
{
updateLastRotation();
isMouseDown = true;
}
protected function onMouseMove(e:MouseEvent):void
{
updateMovements();
}
/*
protected function handleTimerTick(e:TimerEvent):void
{
updateMovements();
}
*/
protected function onMouseUp(e:MouseEvent):void
{
isMouseDown = false;
updateLastRotation();
}
protected function onKeyDown(e:KeyboardEvent):void
{
/*
37 // left
38 // up
39 // right
40 // down
*/
try
{
movementInc += movementInc*.1;
log.debug("keyDown", e.keyCode);
switch(e.keyCode)
{
case 37:
arrowLeft = true;
break;
case 38:
arrowUp = true;
break;
case 39:
arrowRight = true;
break;
case 40:
arrowDown = true;
break;
}
}catch(e:Error)
{
log.debug("keyDown error");
}
}
protected function onKeyUp(e:KeyboardEvent):void
{
movementInc = 1;
try
{
switch(e.keyCode)
{
case 37:
arrowLeft = false;
break;
case 38:
arrowUp = false;
break;
case 39:
arrowRight = false;
break;
case 40:
arrowDown = false;
break;
}
}catch(e:Error)
{
log.debug("keyDown error");
}
}
protected function handleKeyStroke():void
{
var inc:Number = 5 + movementInc;
if(arrowLeft) currentRotationObj.x -= inc;
if(arrowUp) currentRotationObj.z += inc;
if(arrowRight) currentRotationObj.x += inc;
if(arrowDown) currentRotationObj.z -= inc;
}
protected function updateMovements():void
{
updateDif();
handleKeyStroke();
if(!isMouseDown) return;
try
{
var posx:Number = difX/7;
var posy:Number = difY/7;
posx = posx > 360 ? posx % 360 : posx;
posy = posy > 360 ? posy % 360 : posy;
if(restrictInversion && currentRotationObj.rotationX - posy >= (-90) && currentRotationObj.rotationX - posy <= (90))
{
currentRotationObj.rotationX -= posy;
}else if(!restrictInversion)
{
currentRotationObj.rotationX -= posy;
}
currentRotationObj.rotationY += posx;
//dispatchEvent(new ObjectControllerEvent(ObjectControllerEvent.MOVEMENT, posx, posy));
if(difX != 0) lastX = stage.mouseX;
if(difY != 0) lastY = stage.mouseY;
}catch(e:Error)
{
log.debug("handleMouseMove failed");
}
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/utils/ObjectController.as | ActionScript | art | 6,260 |
/**
* @private
*/
/*
Copyright (c) 2007 John Grden
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package org.papervision3d.components.as3.utils
{
import flash.display.DisplayObject;
import flash.geom.Point;
public class CoordinateTools
{
public static function localToLocal(containerFrom:DisplayObject, containerTo:DisplayObject):Point
{
var point:Point = new Point();
point = containerFrom.localToGlobal(point);
point = containerTo.globalToLocal(point);
return point;
}
// zero based random range returned
public static function random(range:Number):Number
{
return Math.floor(Math.random()*range);
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/utils/CoordinateTools.as | ActionScript | art | 1,669 |
package org.papervision3d.components.as3.collections
{
/**
* MaterialsListItem is used by the component to provided settings for materials to be used in a collada scene. The 3 Material types it supports are "File", "Bitmap" and "MovieClip".
* </p>
* <p>When setting a material to "File", the external bitmap will be loaded at Design-time.</p>
* <p>When setting a meterial to "MovieClip" or "Bitmap", a ColorMaterial (green) will be used to represent the material at design-time. At run-time, you should see your material used on the models.</p>
* <p>One feature of the MaterialsListItem is that you can set the properties for a Bitmap or MovieClip and still setup up a temporary File location for Designtime.
* <ol>
* <li>Create a new texture by hitting the "+" sign after you bring up the dialog.</li>
* <li>Define your properties for the Material</li>
* <li>Include not only the LinkageID, but a file location as well. The file location would point to a bitmap for designtime adjustments and rendering.</li>
* <li>When you're ready to compile, change the materialType back to it's intended type ("Bitmap" or "MovieClip").</li>
* </ol>
* </p>
* <p>
* This allows you to keep all of your settings while allowing a stand-in bitmap to be loaded at designtime.
* </p>
*/
public class MaterialsListItem
{
[Inspectable (name="materialName", type="String")]
/**
* The name given to a texture after importing into a 3D application (IE: 3D Studio Max, Maya, Blender).
* The Collada object will use this as reference as to which material to use for texturing the objects that have been assigned the same material.
*/
public var materialName :String = "";
[Inspectable (name="materialLinkageID", type="String")]
/**
* LinkageID set in the library for a Bitmap or MovieClip asset
*/
public var materialLinkageID :String = "";
[Inspectable (name="materialFileLocation", type="String")]
/**
* If an external file is being used, this is the relative or absolute URL of the file
*/
public var materialFileLocation :String = "";
[Inspectable (name="materialType", defaultValue="Bitmap", type="String")]
//[Inspectable (name="materialType", defaultValue="Bitmap", enumeration="Bitmap, File, MovieClip", type="list")]
/**
* There are 3 types of materials that can be used with this component:
* </p>
* <p>
* <ul>
* <li>Bitmap: BitmapAssetMaterial - a bitmap defined in the library</li>
* <li>MovieClip: MovieAssetMaterial - a MovieClip defined in the library</li>
* <li>File: BitmapFileMaterial - an external bitmap file</li>
* </ul>
* </p>
*/
public var materialType :String = "Bitmap";
[Inspectable (name="animated", defaultValue=false, type="Boolean")]
/**
* Boolean flag indicating whether or not the material should be redrawn in the render loop
*/
public var animated :Boolean = true;
[Inspectable (name="singleSided", defaultValue=true, type="Boolean")]
/**
* Boolean flag indicating whether or not the material should be drawn on both sides
*/
public var singleSided :Boolean = true;
[Inspectable (name="transparent", defaultValue=true, type="Boolean")]
/**
* If set to true, preserves the alpha information of the Material being used
*/
public var transparent :Boolean = true;
[Inspectable (name="interactive", defaultValue=false, type="Boolean")]
/**
* Boolean flag indicating whether or not the material is Interactive. If set to true, the DisplayObject3D this material
* is assigned to will dispatch mouse events.
*/
public var interactive :Boolean = false;
//[Inspectable (name="smooth", defaultValue=false, type="Boolean")]
//public var smooth :Boolean = false;
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/collections/MaterialsListItem.as | ActionScript | art | 3,872 |
/**
*
* @author John Grden
*
*/
package org.papervision3d.components.as3.core
{
import adobe.utils.MMExecute;
import com.blitzagency.xray.logger.XrayLog;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.utils.getQualifiedClassName;
import flash.utils.setTimeout;
// include all types of objects users might use
import org.papervision3d.materials.*;
import org.papervision3d.objects.*;
import org.papervision3d.cameras.*;
import org.papervision3d.utils.InteractiveSceneManager;
/**
* Dispatched when the component has been initialized. This does not include when the scene3d is created or a subsequent collada file is completed
*
* @eventType org.papervision3d.components.as3.flash9.PV3DUIComponent.INIT_COMPLETE
*/
[Event(name="initComplete", type="flash.events.Event")]
/**
* PV3DUIComponent is the core class from which the other PV3D Design-time components are built. It takes care of stage resize events and positioning of the component
*
*/
public class PV3DUIComponent extends MovieClip
{
/**
* @eventType initComplete
*/
public static const INIT_COMPLETE :String = "initComplete";
[Inspectable ( type="Boolean", defaultValue=false, name="Clip content")]
/**
* Whether or not you want the scene to have a mask applied to the area of the component. If false, you will see the 3D scene extend beyond the bounding area of the component
*/
public var clipContent :Boolean = false;
[Inspectable ( name="Resize with Stage?", defaultValue=false, type="Boolean" )]
/**
* A Boolean flag that allows the component to resize to bottom/right of the stage if set to true. Remember to set your x/y coordinates as the component will only resize from where you've positioned it on stage.
* @param p_resize
*
*/
public function set resizeWithStage(p_resize:Boolean):void
{
_resizeWithStage = p_resize;
resizeStage();
}
public function get resizeWithStage():Boolean
{
return _resizeWithStage;
}
// coordinates
/**
* @private
*/
protected var screenOffsetX :Number = 0;
/**
* @private
*/
protected var screenOffsetY :Number = 0;
// sizing
/**
* Width of your component on stage
*/
public var sceneWidth :Number = 320;
/**
* Height of your component on stage
*/
public var sceneHeight :Number = 240;
private var _resizeWithStage :Boolean = false;
/**
* @private
*/
protected var _componentInspectorSetting :Boolean = false;
/**
* @private
*/
protected var _propertyInspectorSetting :Boolean = false
/**
* @private
*/
protected var isAppInitialized :Boolean = false;
// live preview
/**
* @private
*/
protected var isLivePreview :Boolean = false;
// logging
/**
* @private
*/
protected var log :XrayLog = new XrayLog();
public function PV3DUIComponent()
{
super();
init();
}
/**
* @private
* @note Called when the component is actually running in a compiled SWF at runtime, rather than LivePreview
* @param p_piSetting
*
*/
public function set componentInspectorSetting(p_piSetting:Boolean):void
{
_componentInspectorSetting = p_piSetting;
log.debug("componentInspectorSetting", p_piSetting);
if(!_componentInspectorSetting)
{
// properties are set, we're ready to init the app
initApp();
}
}
/**
* @private
*/
public function get componentInspectorSetting():Boolean
{
return _componentInspectorSetting;
}
/**
* @private
*/
public function set propertyInspectorSetting(p_piSetting:Boolean):void
{
_propertyInspectorSetting = p_piSetting;
}
/**
* @private
*/
public function get propertyInspectorSetting():Boolean
{
return _propertyInspectorSetting;
}
/**
* @private
*/
private function init():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
}
/**
* @private
*/
protected function initApp():void
{
isLivePreview = (parent != null && getQualifiedClassName(parent) == "fl.livepreview::LivePreviewParent");
configUI();
drawStage();
alignStage();
initListeners();
dispatchEvent(new Event(INIT_COMPLETE));
isAppInitialized = true;
}
/**
* @private
*/
protected function configUI():void
{
}
// called by LivePreveiwParent class
/**
* Pass in width and height to change the size of the component on stage. This will not scale your 3D scene, only the component itself
* @param w
* @param h
*
*/
public function setSize(w:Number, h:Number):void
{
//log.debug("setSize called", w + ", " + h);
width = w;
height = h;
resizeStage();
}
/**
* @private
*/
protected function manageStageSize():void
{
sceneWidth = resizeWithStage ? stage.stageWidth : width //super.width;
sceneHeight = resizeWithStage ? stage.stageHeight : height //super.height;
super.scaleX = 1;
super.scaleY = 1;
scaleX = 1;
scaleY = 1;
width=sceneWidth;
height=sceneHeight;
}
/**
* @private
* I tried to get the designtime size of the stage, but unfortunately, JSFL isn't usable from a component ;(
*/
protected function getStageSize():void
{
//var values:String = MMExecute("fl.runScript(fl.configURI + \"Commands/papervision3d/setValues.jsfl\", \"getStageSize\");");
//trace("stageSize", values);
}
/**
* @private
*/
protected function drawStage():void
{
//return;
scaleX = 1;
scaleY = 1;
graphics.clear();
graphics.beginFill(0x000000, 0);
graphics.drawRect(0,0,sceneWidth,sceneHeight);
graphics.endFill();
scrollRect = null;
if(clipContent) scrollRect = new Rectangle(0,0,sceneWidth, sceneHeight);
}
/**
* @private
*/
protected function initListeners():void
{
stage.addEventListener("resize", stageResizeHandler);
stage.addEventListener("fullScreen", stageResizeHandler);
}
/**
* @private
*/
protected function resizeStage():void
{
manageStageSize();
drawStage();
alignStage();
}
/**
* @private
*/
protected function stageResizeHandler(e:Event):void
{
if(!resizeWithStage) return;
resizeStage();
}
/**
* @private
*/
protected function alignStage():void
{
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/components/as3/core/PV3DUIComponent.as | ActionScript | art | 6,825 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// NumberUV
package org.papervision3d.core
{
/**
* The NumberUV class represents a value in a texture UV coordinate system.
*
* Properties u and v represent the horizontal and vertical texture axes respectively.
*
*/
public class NumberUV
{
/**
* The horizontal coordinate value.
*/
public var u: Number;
/**
* The vertical coordinate value.
*/
public var v: Number;
/**
* Creates a new NumberUV object whose coordinate values are specified by the u and v parameters. If you call this constructor function without parameters, a NumberUV with u and v properties set to zero is created.
*
* @param u The horizontal coordinate value. The default value is zero.
* @param v The vertical coordinate value. The default value is zero.
*/
public function NumberUV( u: Number=0, v: Number=0 )
{
this.u = u;
this.v = v;
}
/**
* Returns a new NumberUV object that is a clone of the original instance with the same UV values.
*
* @return A new NumberUV instance with the same UV values as the original NumberUV instance.
*/
public function clone():NumberUV
{
return new NumberUV( this.u, this.v );
}
/**
* Returns a NumberUV object with u and v properties set to zero.
*
* @return A NumberUV object.
*/
static public function get ZERO():NumberUV
{
return new NumberUV( 0, 0 );
}
/**
* Returns a string value representing the UV values in the specified NumberUV object.
*
* @return A string.
*/
public function toString(): String
{
return 'u:' + u + ' v:' + v;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/NumberUV.as | ActionScript | art | 3,334 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________ Matrix3D
package org.papervision3d.core
{
import flash.geom.Matrix;
import org.papervision3d.core.Number3D;
/**
* The Matrix3D class lets you create and manipulate 4x3 3D transformation matrices.
*/
/*
Acknowledgements and references:
> Industrial Light & Magic, a division of Lucas Digital Ltd. LLC
> DAVID H. EBERLY3D: Game Engine Design
> TOMAS AKENINE-MöLLER AND ERIC HAINES: Real-Time Rendering
> THOMAS PFEIFFER: Sandy3D - www.flashsandy.org
> The Matrix and Quaternion FAQ - http://www.j3d.org/matrix_faq/matrfaq_latest.html
*/
public class Matrix3D
{
/**
* X O O O
* O O O O
* O O O O
*/
public var n11 :Number;
/**
* O X O O
* O O O O
* O O O O
*/
public var n12 :Number;
/**
* O O X O
* O O O O
* O O O O
*/
public var n13 :Number;
/**
* O O O X
* O O O O
* O O O O
*/
public var n14 :Number;
/**
* O O O O
* X O O O
* O O O O
*/
public var n21 :Number;
/**
* O O O O
* O X O O
* O O O O
*/
public var n22 :Number;
/**
* O O O O
* O O X O
* O O O O
*/
public var n23 :Number;
/**
* O O O O
* O O O X
* O O O O
*/
public var n24 :Number;
/**
* O O O O
* O O O O
* X O O O
*/
public var n31 :Number;
/**
* O O O O
* O O O O
* O X O O
*/
public var n32 :Number;
/**
* O O O O
* O O O O
* O O X O
*/
public var n33 :Number;
/**
* O O O O
* O O O O
* O O O X
*/
public var n34 :Number;
// _________________________________________________________________________________ Matrix3D
/**
* The Matrix3D constructor lets you create Matrix3D objects.
*
* @param args The values to populate the matrix with. Identity matrix is returned by default.
*/
public function Matrix3D( args:Array=null )
{
if( ! args || args.length < 12 )
{
n11 = n22 = n33 = 1;
n12 = n13 = n14 = n21 = n23 = n24 = n31 = n32 = n34 = 0;
}
else
{
n11 = args[0]; n12 = args[1]; n13 = args[2]; n14 = args[3];
n21 = args[4]; n22 = args[5]; n23 = args[6]; n24 = args[7];
n31 = args[8]; n32 = args[9]; n33 = args[10]; n34 = args[11];
}
}
// _________________________________________________________________________________ IDENTITY
public static function get IDENTITY():Matrix3D
{
return new Matrix3D
(
[
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0
]
);
}
// _________________________________________________________________________________ trace
public function toString():String
{
var s:String = "";
s += int(n11*1000)/1000 + "\t\t" + int(n12*1000)/1000 + "\t\t" + int(n13*1000)/1000 + "\t\t" + int(n14*1000)/1000 +"\n";
s += int(n21*1000)/1000 + "\t\t" + int(n22*1000)/1000 + "\t\t" + int(n23*1000)/1000 + "\t\t" + int(n24*1000)/1000 + "\n";
s += int(n31*1000)/1000 + "\t\t" + int(n32*1000)/1000 + "\t\t" + int(n33*1000)/1000 + "\t\t" + int(n34*1000)/1000 + "\n";
return s;
}
// _________________________________________________________________________________ OPERATIONS
public function calculateMultiply( a:Matrix3D, b:Matrix3D ):void
{
var a11:Number = a.n11; var b11:Number = b.n11;
var a21:Number = a.n21; var b21:Number = b.n21;
var a31:Number = a.n31; var b31:Number = b.n31;
var a12:Number = a.n12; var b12:Number = b.n12;
var a22:Number = a.n22; var b22:Number = b.n22;
var a32:Number = a.n32; var b32:Number = b.n32;
var a13:Number = a.n13; var b13:Number = b.n13;
var a23:Number = a.n23; var b23:Number = b.n23;
var a33:Number = a.n33; var b33:Number = b.n33;
var a14:Number = a.n14; var b14:Number = b.n14;
var a24:Number = a.n24; var b24:Number = b.n24;
var a34:Number = a.n34; var b34:Number = b.n34;
this.n11 = a11 * b11 + a12 * b21 + a13 * b31;
this.n12 = a11 * b12 + a12 * b22 + a13 * b32;
this.n13 = a11 * b13 + a12 * b23 + a13 * b33;
this.n14 = a11 * b14 + a12 * b24 + a13 * b34 + a14;
this.n21 = a21 * b11 + a22 * b21 + a23 * b31;
this.n22 = a21 * b12 + a22 * b22 + a23 * b32;
this.n23 = a21 * b13 + a22 * b23 + a23 * b33;
this.n24 = a21 * b14 + a22 * b24 + a23 * b34 + a24;
this.n31 = a31 * b11 + a32 * b21 + a33 * b31;
this.n32 = a31 * b12 + a32 * b22 + a33 * b32;
this.n33 = a31 * b13 + a32 * b23 + a33 * b33;
this.n34 = a31 * b14 + a32 * b24 + a33 * b34 + a34;
}
public static function multiply( a:Matrix3D, b:Matrix3D ):Matrix3D
{
var m:Matrix3D = new Matrix3D();
m.calculateMultiply( a, b );
return m;
}
public function calculateMultiply3x3( a:Matrix3D, b:Matrix3D ):void
{
var a11:Number = a.n11; var b11:Number = b.n11;
var a21:Number = a.n21; var b21:Number = b.n21;
var a31:Number = a.n31; var b31:Number = b.n31;
var a12:Number = a.n12; var b12:Number = b.n12;
var a22:Number = a.n22; var b22:Number = b.n22;
var a32:Number = a.n32; var b32:Number = b.n32;
var a13:Number = a.n13; var b13:Number = b.n13;
var a23:Number = a.n23; var b23:Number = b.n23;
var a33:Number = a.n33; var b33:Number = b.n33;
this.n11 = a11 * b11 + a12 * b21 + a13 * b31;
this.n12 = a11 * b12 + a12 * b22 + a13 * b32;
this.n13 = a11 * b13 + a12 * b23 + a13 * b33;
this.n21 = a21 * b11 + a22 * b21 + a23 * b31;
this.n22 = a21 * b12 + a22 * b22 + a23 * b32;
this.n23 = a21 * b13 + a22 * b23 + a23 * b33;
this.n31 = a31 * b11 + a32 * b21 + a33 * b31;
this.n32 = a31 * b12 + a32 * b22 + a33 * b32;
this.n33 = a31 * b13 + a32 * b23 + a33 * b33;
}
public static function multiply3x3( a:Matrix3D, b:Matrix3D ):Matrix3D
{
var m:Matrix3D = new Matrix3D();
m.calculateMultiply3x3( a, b );
return m;
}
public function calculateAdd( a:Matrix3D, b:Matrix3D ):void
{
this.n11 = a.n11 + b.n11;
this.n12 = a.n12 + b.n12;
this.n13 = a.n13 + b.n13;
this.n14 = a.n14 + b.n14;
this.n21 = a.n21 + b.n21;
this.n22 = a.n22 + b.n22;
this.n23 = a.n23 + b.n23;
this.n24 = a.n24 + b.n24;
this.n31 = a.n31 + b.n31;
this.n32 = a.n32 + b.n32;
this.n33 = a.n33 + b.n33;
this.n34 = a.n34 + b.n34;
}
public static function add( a:Matrix3D, b:Matrix3D ):Matrix3D
{
var m:Matrix3D = new Matrix3D();
m.calculateAdd( a, b );
return m;
}
public function calculateInverse( m:Matrix3D ):void
{
var d:Number = m.det;
if( Math.abs(d) > 0.001 )
{
d = 1/d;
var m11:Number = m.n11; var m21:Number = m.n21; var m31:Number = m.n31;
var m12:Number = m.n12; var m22:Number = m.n22; var m32:Number = m.n32;
var m13:Number = m.n13; var m23:Number = m.n23; var m33:Number = m.n33;
var m14:Number = m.n14; var m24:Number = m.n24; var m34:Number = m.n34;
this.n11 = d * ( m22 * m33 - m32 * m23 );
this.n12 = -d * ( m12 * m33 - m32 * m13 );
this.n13 = d * ( m12 * m23 - m22 * m13 );
this.n14 = -d * ( m12 * (m23*m34 - m33*m24) - m22 * (m13*m34 - m33*m14) + m32 * (m13*m24 - m23*m14) );
this.n21 = -d * ( m21 * m33 - m31 * m23 );
this.n22 = d * ( m11 * m33 - m31 * m13 );
this.n23 = -d* ( m11 * m23 - m21 * m13 );
this.n24 = d * ( m11 * (m23*m34 - m33*m24) - m21 * (m13*m34 - m33*m14) + m31 * (m13*m24 - m23*m14) );
this.n31 = d * ( m21 * m32 - m31 * m22 );
this.n32 = -d* ( m11 * m32 - m31 * m12 );
this.n33 = d * ( m11 * m22 - m21 * m12 );
this.n34 = -d* ( m11 * (m22*m34 - m32*m24) - m21 * (m12*m34 - m32*m14) + m31 * (m12*m24 - m22*m14) );
}
}
public static function inverse( m:Matrix3D ):Matrix3D
{
var inv:Matrix3D = new Matrix3D();
inv.calculateInverse( m );
return inv;
}
public function get det():Number
{
return (this.n11 * this.n22 - this.n21 * this.n12) * this.n33 - (this.n11 * this.n32 - this.n31 * this.n12) * this.n23 +
(this.n21 * this.n32 - this.n31 * this.n22) * this.n13;
}
public function get trace():Number
{
return this.n11 + this.n22 + this.n33 + 1;
}
// _________________________________________________________________________________ COPY
public function copy( m:Matrix3D ):Matrix3D
{
this.n11 = m.n11; this.n12 = m.n12;
this.n13 = m.n13; this.n14 = m.n14;
this.n21 = m.n21; this.n22 = m.n22;
this.n23 = m.n23; this.n24 = m.n24;
this.n31 = m.n31; this.n32 = m.n32;
this.n33 = m.n33; this.n34 = m.n34;
return this;
}
public function copy3x3( m:Matrix3D ):Matrix3D
{
this.n11 = m.n11; this.n12 = m.n12; this.n13 = m.n13;
this.n21 = m.n21; this.n22 = m.n22; this.n23 = m.n23;
this.n31 = m.n31; this.n32 = m.n32; this.n33 = m.n33;
return this;
}
public static function clone( m:Matrix3D ):Matrix3D
{
return new Matrix3D
(
[
m.n11, m.n12, m.n13, m.n14,
m.n21, m.n22, m.n23, m.n24,
m.n31, m.n32, m.n33, m.n34
]
);
}
// _________________________________________________________________________________ VECTOR
public static function multiplyVector( m:Matrix3D, v:Number3D ):void
{
var vx:Number = v.x;
var vy:Number = v.y;
var vz:Number = v.z;
v.x = vx * m.n11 + vy * m.n12 + vz * m.n13 + m.n14;
v.y = vx * m.n21 + vy * m.n22 + vz * m.n23 + m.n24;
v.z = vx * m.n31 + vy * m.n32 + vz * m.n33 + m.n34;
}
public static function multiplyVector3x3( m:Matrix3D, v:Number3D ):void
{
var vx:Number = v.x;
var vy:Number = v.y;
var vz:Number = v.z;
v.x = vx * m.n11 + vy * m.n12 + vz * m.n13;
v.y = vx * m.n21 + vy * m.n22 + vz * m.n23;
v.z = vx * m.n31 + vy * m.n32 + vz * m.n33;
}
public static function rotateAxis( m:Matrix3D, v:Number3D ):void
{
var vx:Number = v.x;
var vy:Number = v.y;
var vz:Number = v.z;
v.x = vx * m.n11 + vy * m.n12 + vz * m.n13;
v.y = vx * m.n21 + vy * m.n22 + vz * m.n23;
v.z = vx * m.n31 + vy * m.n32 + vz * m.n33;
v.normalize();
}
/*
public static function projectVector( m:Matrix3D, v:Number3D ):void
{
var c:Number = 1 / ( v.x * m.n41 + v.y * m.n42 + v.z * m.n43 + 1 );
multiplyVector( m, v );
v.x = v.x * c;
v.y = v.y * c;
v.z = 0;
}
*/
// _________________________________________________________________________________ EULER
/*
public static function matrix2eulerOLD( m:Matrix3D ):Number3D
{
var angle:Number3D = new Number3D();
var d :Number = -Math.asin( Math.max( -1, Math.min( 1, m.n13 ) ) ); // Calculate Y-axis angle
var c :Number = Math.cos( d );
angle.y = d * toDEGREES;
var trX:Number, trY:Number;
if( Math.abs( c ) > 0.005 ) // Gimball lock?
{
trX = m.n33 / c; // No, so get X-axis angle
trY = -m.n23 / c;
angle.x = Math.atan2( trY, trX ) * toDEGREES;
trX = m.n11 / c; // Get Z-axis angle
trY = -m.n12 / c;
angle.z = Math.atan2( trY, trX ) * toDEGREES;
}
else // Gimball lock has occurred
{
angle.x = 0; // Set X-axis angle to zero
trX = m.n22; // And calculate Z-axis angle
trY = m.n21;
angle.z = Math.atan2( trY, trX ) * toDEGREES;
}
// TODO: Clamp all angles to range
return angle;
}
*/
public static function matrix2euler( t:Matrix3D ):Number3D
{
var rot:Number3D = new Number3D();
// Normalize the local x, y and z axes to remove scaling.
var i:Number3D = new Number3D( t.n11, t.n21, t.n31 );
var j:Number3D = new Number3D( t.n12, t.n22, t.n32 );
var k:Number3D = new Number3D( t.n13, t.n23, t.n33 );
i.normalize();
j.normalize();
k.normalize();
var m:Matrix3D = new Matrix3D(
[
i.x, j.x, k.x, 0,
i.y, j.y, k.y, 0,
i.z, j.z, k.z, 0
] );
// Extract the first angle, rot.x
rot.x = Math.atan2( m.n23, m.n33 ); // rot.x = Math<T>::atan2 (M[1][2], M[2][2]);
// Remove the rot.x rotation from M, so that the remaining
// rotation, N, is only around two axes, and gimbal lock
// cannot occur.
var rx:Matrix3D = Matrix3D.rotationX( -rot.x );
var n:Matrix3D = Matrix3D.multiply( rx, m );
// Extract the other two angles, rot.y and rot.z, from N.
var cy:Number = Math.sqrt( n.n11 * n.n11 + n.n21 * n.n21); // T cy = Math<T>::sqrt (N[0][0]*N[0][0] + N[0][1]*N[0][1]);
rot.y = Math.atan2( -n.n31, cy ); // rot.y = Math<T>::atan2 (-N[0][2], cy);
rot.z = Math.atan2( -n.n12, n.n11 ); //rot.z = Math<T>::atan2 (-N[1][0], N[1][1]);
// Fix angles
if( rot.x == Math.PI )
{
if( rot.y > 0 )
rot.y -= Math.PI;
else
rot.y += Math.PI;
rot.x = 0;
rot.z += Math.PI;
}
// Convert to degrees if needed
rot.x *= toDEGREES;
rot.y *= toDEGREES;
rot.z *= toDEGREES;
return rot;
}
public static function euler2matrix( deg:Number3D ):Matrix3D
{
var m:Matrix3D = IDENTITY;
var ax:Number = deg.x * toRADIANS;
var ay:Number = deg.y * toRADIANS;
var az:Number = deg.z * toRADIANS;
var a:Number = Math.cos( ax );
var b:Number = Math.sin( ax );
var c:Number = Math.cos( ay );
var d:Number = Math.sin( ay );
var e:Number = Math.cos( az );
var f:Number = Math.sin( az );
var ad:Number = a * d;
var bd:Number = b * d;
m.n11 = c * e;
m.n12 = -c * f;
m.n13 = d;
m.n21 = bd * e + a * f;
m.n22 = -bd * f + a * e;
m.n23 = -b * c;
m.n31 = -ad * e + b * f;
m.n32 = ad * f + b * e;
m.n33 = a * c;
return m;
}
// _________________________________________________________________________________ ROTATION
public static function rotationX( rad:Number ):Matrix3D
{
var m :Matrix3D = IDENTITY;
var c :Number = Math.cos( rad );
var s :Number = Math.sin( rad );
m.n22 = c;
m.n23 = -s;
m.n32 = s;
m.n33 = c;
return m;
}
public static function rotationY( rad:Number ):Matrix3D
{
var m :Matrix3D = IDENTITY;
var c :Number = Math.cos( rad );
var s :Number = Math.sin( rad );
m.n11 = c;
m.n13 = -s;
m.n31 = s;
m.n33 = c;
return m;
}
public static function rotationZ( rad:Number ):Matrix3D
{
var m :Matrix3D = IDENTITY;
var c :Number = Math.cos( rad );
var s :Number = Math.sin( rad );
m.n11 = c;
m.n12 = -s;
m.n21 = s;
m.n22 = c;
return m;
}
public static function rotationMatrix( x:Number, y:Number, z:Number, rad:Number ):Matrix3D
{
var m:Matrix3D = IDENTITY;
var nCos:Number = Math.cos( rad );
var nSin:Number = Math.sin( rad );
var scos:Number = 1 - nCos;
var sxy :Number = x * y * scos;
var syz :Number = y * z * scos;
var sxz :Number = x * z * scos;
var sz :Number = nSin * z;
var sy :Number = nSin * y;
var sx :Number = nSin * x;
m.n11 = nCos + x * x * scos;
m.n12 = -sz + sxy;
m.n13 = sy + sxz;
m.n21 = sz + sxy;
m.n22 = nCos + y * y * scos;
m.n23 = -sx + syz;
m.n31 = -sy + sxz;
m.n32 = sx + syz;
m.n33 = nCos + z * z * scos;
return m;
}
public static function rotationMatrixWithReference( axis:Number3D, rad:Number, ref:Number3D ):Matrix3D
{
var m:Matrix3D = Matrix3D.translationMatrix( ref.x, -ref.y, ref.z );
m.calculateMultiply( m, Matrix3D.rotationMatrix( axis.x, axis.y, axis.z, rad ) );
m.calculateMultiply( m, Matrix3D.translationMatrix ( -ref.x, ref.y, -ref.z ) );
return m;
}
// _________________________________________________________________________________ TRANSFORM
public static function translationMatrix( x:Number, y:Number, z:Number ):Matrix3D
{
var m:Matrix3D = IDENTITY;
m.n14 = x;
m.n24 = y;
m.n34 = z;
return m;
}
public static function scaleMatrix( x:Number, y:Number, z:Number ):Matrix3D
{
var m:Matrix3D = IDENTITY;
m.n11 = x;
m.n22 = y;
m.n33 = z;
return m;
}
// _________________________________________________________________________________ QUATERNIONS
public static function magnitudeQuaternion( q:Object ):Number
{
return( Math.sqrt( q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z ) );
}
public static function normalizeQuaternion( q:Object ):Object
{
var mag:Number = magnitudeQuaternion( q );
q.x /= mag;
q.y /= mag;
q.z /= mag;
q.w /= mag;
return q;
}
public static function axis2quaternion( x:Number, y:Number, z:Number, angle:Number ):Object
{
var sin:Number = Math.sin( angle / 2 );
var cos:Number = Math.cos( angle / 2 );
var q:Object = new Object();
q.x = x * sin;
q.y = y * sin;
q.z = z * sin;
q.w = cos;
return normalizeQuaternion( q );
}
public static function euler2quaternion( ax:Number, ay:Number, az:Number ):Object
{
var fSinPitch :Number = Math.sin( ax * 0.5 );
var fCosPitch :Number = Math.cos( ax * 0.5 );
var fSinYaw :Number = Math.sin( ay * 0.5 );
var fCosYaw :Number = Math.cos( ay * 0.5 );
var fSinRoll :Number = Math.sin( az * 0.5 );
var fCosRoll :Number = Math.cos( az * 0.5 );
var fCosPitchCosYaw :Number = fCosPitch * fCosYaw;
var fSinPitchSinYaw :Number = fSinPitch * fSinYaw;
var q:Object = new Object();
q.x = fSinRoll * fCosPitchCosYaw - fCosRoll * fSinPitchSinYaw;
q.y = fCosRoll * fSinPitch * fCosYaw + fSinRoll * fCosPitch * fSinYaw;
q.z = fCosRoll * fCosPitch * fSinYaw - fSinRoll * fSinPitch * fCosYaw;
q.w = fCosRoll * fCosPitchCosYaw + fSinRoll * fSinPitchSinYaw;
return q;
}
public static function quaternion2matrix( x:Number, y:Number, z:Number, w:Number ):Matrix3D
{
var xx:Number = x * x;
var xy:Number = x * y;
var xz:Number = x * z;
var xw:Number = x * w;
var yy:Number = y * y;
var yz:Number = y * z;
var yw:Number = y * w;
var zz:Number = z * z;
var zw:Number = z * w;
var m:Matrix3D = IDENTITY;
m.n11 = 1 - 2 * ( yy + zz );
m.n12 = 2 * ( xy - zw );
m.n13 = 2 * ( xz + yw );
m.n21 = 2 * ( xy + zw );
m.n22 = 1 - 2 * ( xx + zz );
m.n23 = 2 * ( yz - xw );
m.n31 = 2 * ( xz - yw );
m.n32 = 2 * ( yz + xw );
m.n33 = 1 - 2 * ( xx + yy );
return m;
}
public static function multiplyQuaternion( a:Object, b:Object ):Object
{
var ax:Number = a.x; var ay:Number = a.y; var az:Number = a.z; var aw:Number = a.w;
var bx:Number = b.x; var by:Number = b.y; var bz:Number = b.z; var bw:Number = b.w;
var q:Object = new Object();
q.x = aw*bx + ax*bw + ay*bz - az*by;
q.y = aw*by + ay*bw + az*bx - ax*bz;
q.z = aw*bz + az*bw + ax*by - ay*bx;
q.w = aw*bw - ax*bx - ay*by - az*bz;
return q;
}
// _________________________________________________________________________________ TRIG
static private var toDEGREES :Number = 180/Math.PI;
static private var toRADIANS :Number = Math.PI/180;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/Matrix3D.as | ActionScript | art | 19,827 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Number3D
package org.papervision3d.core
{
/**
* The Number3D class represents a value in a three-dimensional coordinate system.
*
* Properties x, y and z represent the horizontal, vertical and z the depth axes respectively.
*
*/
public class Number3D
{
/**
* The horizontal coordinate value.
*/
public var x: Number;
/**
* The vertical coordinate value.
*/
public var y: Number;
/**
* The depth coordinate value.
*/
public var z: Number;
/**
* Creates a new Number3D object whose three-dimensional values are specified by the x, y and z parameters. If you call this constructor function without parameters, a Number3D with x, y and z properties set to zero is created.
*
* @param x The horizontal coordinate value. The default value is zero.
* @param y The vertical coordinate value. The default value is zero.
* @param z The depth coordinate value. The default value is zero.
*/
public function Number3D( x: Number=0, y: Number=0, z: Number=0 )
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Returns a new Number3D object that is a clone of the original instance with the same three-dimensional values.
*
* @return A new Number3D instance with the same three-dimensional values as the original Number3D instance.
*/
public function clone():Number3D
{
return new Number3D( this.x, this.y, this.z );
}
/**
* Copies the values of this number3d to the passed number3d.
*
*/
public function copyTo(n:Number3D):void
{
n.x = x;
n.y = y;
n.z = z;
}
// ______________________________________________________________________ MATH
/**
* Modulo
*/
public function get modulo():Number
{
return Math.sqrt( this.x*this.x + this.y*this.y + this.z*this.z );
}
/**
* Add
*/
public static function add( v:Number3D, w:Number3D ):Number3D
{
return new Number3D
(
v.x + w.x,
v.y + w.y,
v.z + w.z
);
}
/**
* Substract.
*/
public static function sub( v:Number3D, w:Number3D ):Number3D
{
return new Number3D
(
v.x - w.x,
v.y - w.y,
v.z - w.z
);
}
/**
* Dot product.
*/
public static function dot( v:Number3D, w:Number3D ):Number
{
return ( v.x * w.x + v.y * w.y + w.z * v.z );
}
/**
* Cross product.
*/
public static function cross( v:Number3D, w:Number3D ):Number3D
{
return new Number3D((w.y * v.z) - (w.z * v.y), (w.z * v.x) - (w.x * v.z), (w.x * v.y) - (w.y * v.x));
}
/**
* Normalize.
*/
public function normalize():void
{
var mod:Number = this.modulo;
if( mod != 0 && mod != 1)
{
this.x /= mod;
this.y /= mod;
this.z /= mod;
}
}
// ______________________________________________________________________
/**
* Returns a Number3D object with x, y and z properties set to zero.
*
* @return A Number3D object.
*/
static public function get ZERO():Number3D
{
return new Number3D( 0, 0, 0 );
}
/**
* Returns a string value representing the three-dimensional values in the specified Number3D object.
*
* @return A string.
*/
public function toString(): String
{
return 'x:' + x + ' y:' + y + ' z:' + z;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/Number3D.as | ActionScript | art | 4,906 |
package org.papervision3d.core.stat
{
public class RenderStatistics
{
public var performance:int = 0;
public var points:int = 0;
public var polys:int = 0;
public var rendered:int = 0;
public var triangles:int = 0;
public var culledTriangles:int = 0;
public var pixels:Number;
public var particles:Number;
public function RenderStatistics()
{
}
public function clear():void
{
performance = 0;
points = 0;
polys = 0;
rendered = 0;
triangles = 0;
pixels = 0;
particles = 0;
culledTriangles = 0;
}
public function toString():String
{
return new String("Performance:"+performance+", Points:"+points+" Polys:"+polys+" Rendered:"+rendered+" Culled:"+culledTriangles);
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/stat/RenderStatistics.as | ActionScript | art | 746 |
package org.papervision3d.core.draw
{
import flash.display.Graphics;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
import org.papervision3d.objects.DisplayObject3D;
public interface IFaceDrawer
{
function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/draw/IFaceDrawer.as | ActionScript | art | 405 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Face3D
package org.papervision3d.core.geom
{
import flash.display.*;
import flash.geom.Matrix;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.DisplayObject3D;
/**
* The Face3D class lets you render linear textured triangles. It also supports solid colour fill and hairline outlines.
*
*/
public class Face3D
{
/**
* An array of Vertex3D objects for the three vertices of the triangle.
*/
public var vertices :Array;
/**
* A material id TODO
*/
public var _materialName :String;
/**
* A MaterialObject3D object that contains the material properties of the back of a single sided triangle.
*/
// public var materialBack :MaterialObject3D;
/**
* An array of {x,y} objects for the corresponding UV pixel coordinates of each triangle vertex.
*/
public var uv :Array;
// ______________________________________________________________________
/**
* [read-only] The average depth (z coordinate) of the transformed triangle. Also known as the distance from the camera. Used internally for z-sorting.
*/
public var screenZ :Number;
/**
* [read-only] A Boolean value that indicates that the face is visible, i.e. it's vertices are in front of the camera.
*/
public var visible :Boolean;
/**
* The object where the face belongs.
*/
// public var object :Mesh3D;
/**
* [read-only] Unique id of this instance.
*/
public var id :Number;
/**
* Used to store references to the vertices.
*/
public var v0:Vertex3D;
public var v1:Vertex3D;
public var v2:Vertex3D;
/**
* The face normal
*/
public var faceNormal:Number3D;
/**
* The transformed Face3DInstance
*/
public var face3DInstance:Face3DInstance;
/**
* stores the material for this face.
*/
public var material:MaterialObject3D;
/**
* The Face3D constructor lets you create linear textured or solid colour triangles.
*
* @param vertices An array of Vertex3D objects for the three vertices of the triangle.
* @param material A MaterialObject3D object that contains the material properties of the triangle.
* @param uv An array of {x,y} objects for the corresponding UV pixel coordinates of each triangle vertex.
*/
public function Face3D( vertices:Array, material:MaterialObject3D=null, uv:Array=null )
{
// Vertices
this.vertices = vertices;
v0 = vertices[0];
v1 = vertices[1];
v2 = vertices[2];
// Material, if passed from a materials list.
this.material = material;
this.uv = uv;
this.id = _totalFaces++;
face3DInstance = new Face3DInstance(this);
createNormal();
}
// ______________________________________________________________________________
// RENDER
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR
/**
* Draws the triangle into its MovieClip container.
*
* @param container The default MovieClip that you draw into when rendering.
* @param randomFill A Boolean value that indicates whether random coloring is enabled. Typically used for debug purposes. Defaults to false.
* @return The number of triangles drawn. Either one if it is double sided or visible, or zero if it single sided and not visible.
*
*/
public function render( instance:DisplayObject3D, container:Sprite ): Number
{
renderMat = material ? material : instance.material;
return renderMat.drawFace3D(instance, this, container.graphics, v0.vertex2DInstance, v1.vertex2DInstance, v2.vertex2DInstance);
}
private var renderMat:MaterialObject3D; //Used to not use var above.
/*
public function UVatPoint( x : Number, y : Number ) : Object
{
var v0_x : Number = v2.vertex2DInstance.x - v0.vertex2DInstance.x;
var v0_y : Number = v2.vertex2DInstance.y - v0.vertex2DInstance.y;
var v1_x : Number = v1.vertex2DInstance.x - v0.vertex2DInstance.x;
var v1_y : Number = v1.vertex2DInstance.y - v0.vertex2DInstance.y;
var v2_x : Number = x - v0.vertex2DInstance.x;
var v2_y : Number = y - v0.vertex2DInstance.y;
var dot00 : Number = v0_x * v0_x + v0_y * v0_y;
var dot01 : Number = v0_x * v1_x + v0_y * v1_y;
var dot02 : Number = v0_x * v2_x + v0_y * v2_y;
var dot11 : Number = v1_x * v1_x + v1_y * v1_y;
var dot12 : Number = v1_x * v2_x + v1_y * v2_y;
var invDenom : Number = 1 / (dot00 * dot11 - dot01 * dot01);
var u : Number = (dot11 * dot02 - dot01 * dot12) * invDenom;
var v : Number = (dot00 * dot12 - dot01 * dot02) * invDenom;
return { u : u, v : v };
}
public function getCoordAtPoint( x : Number, y : Number ) : Vertex3D
{
var rUV : Object = UVatPoint(x,y);
var u : Number = rUV.u;
var v : Number = rUV.v;
var rX : Number = v0.x + ( v1.x - v0.x ) * v + ( v2.x - v0.x ) * u;
var rY : Number = v0.y + ( v1.y - v0.y ) * v + ( v2.y - v0.y ) * u;
var rZ : Number = v0.z + ( v1.z - v0.z ) * v + ( v2.z - v0.z ) * u;
return { x:rX, y:rY, z:rZ };
}
public function getMapCoordAtPoint( x : Number, y : Number ) : Object
{
var rUV : Object = UVatPoint(x,y);
var u : Number = rUV.u;
var v : Number = rUV.v;
var v_x : Number = ( uv[1].u - uv[0].u ) * v + (uv[2].u - uv[0].u) * u + uv[0].u;
var v_y : Number = ( uv[1].v - uv[0].v ) * v + (uv[2].v - uv[0].v) * u + uv[0].v;
return { x: v_x * face3DInstance.instance.material.bitmap.width, y: face3DInstance.instance.material.bitmap.height - v_y * face3DInstance.instance.material.bitmap.height };
}
*/
protected function createNormal():void
{
var vn0:Number3D = v0.toNumber3D(),
vn1:Number3D = v1.toNumber3D(),
vn2:Number3D = v2.toNumber3D(),
vt1:Number3D = Number3D.sub(vn1,vn0),
vt2:Number3D = Number3D.sub(vn2,vn0);
faceNormal = Number3D.cross(vt2,vt1);
faceNormal.normalize();
}
// ______________________________________________________________________________
// PRIVATE
private static var _totalFaces:Number = 0;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Face3D.as | ActionScript | art | 8,528 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Points
package org.papervision3d.core.geom
{
import org.papervision3d.core.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.scenes.*;
import org.papervision3d.objects.DisplayObject3D;
import flash.utils.Dictionary;
/**
* The Vertices3D class lets you create and manipulate groups of vertices.
*
*/
public class Vertices3D extends DisplayObject3D
{
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new Points object.
*
* The Points GeometryObject3D class lets you create and manipulate groups of vertices.
*
* @param vertices An array of Vertex3D objects for the vertices of the mesh.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Vertices3D( vertices:Array, name:String=null, initObject:Object=null )
{
super( name, new GeometryObject3D(), initObject );
this.geometry.vertices = vertices || new Array();
}
// ___________________________________________________________________________________________________
// T R A N S F O R M
// TTTTTT RRRRR AA NN NN SSSSS FFFFFF OOOO RRRRR MM MM
// TT RR RR AAAA NNN NN SS FF OO OO RR RR MMM MMM
// TT RRRRR AA AA NNNNNN SSSS FFFF OO OO RRRRR MMMMMMM
// TT RR RR AAAAAA NN NNN SS FF OO OO RR RR MM M MM
// TT RR RR AA AA NN NN SSSSS FF OOOO RR RR MM MM
/**
* Projects three dimensional coordinates onto a two dimensional plane to simulate the relationship of the camera to subject.
*
* This is the first step in the process of representing three dimensional shapes two dimensionally.
*
* @param camera Camera.
*/
public override function project( parent :DisplayObject3D, camera :CameraObject3D, sorted :Array=null ):Number
{
//var screenZ:Number =
super.project( parent, camera, sorted );
var view:Matrix3D = this.view,
// Camera
m11 :Number = view.n11,
m12 :Number = view.n12,
m13 :Number = view.n13,
m21 :Number = view.n21,
m22 :Number = view.n22,
m23 :Number = view.n23,
m31 :Number = view.n31,
m32 :Number = view.n32,
m33 :Number = view.n33,
vx :Number,
vy :Number,
vz :Number,
s_x :Number,
s_y :Number,
s_z :Number,
vertex:Vertex3D,
screen:Vertex2D,
persp :Number,
vertices :Array = this.geometry.vertices,
i :int = vertices.length,
focus :Number = camera.focus,
fz :Number = focus * camera.zoom;
while( vertex = vertices[--i] )
{
// Center position
vx = vertex.x;
vy = vertex.y;
vz = vertex.z;
s_z = vx * m31 + vy * m32 + vz * m33 + view.n34;
screen = vertex.vertex2DInstance;
if( screen.visible = ( s_z > 0 ) )
{
s_x = vx * m11 + vy * m12 + vz * m13 + view.n14;
s_y = vx * m21 + vy * m22 + vz * m23 + view.n24;
persp = fz / (focus + s_z);
screen.x = s_x * persp;
screen.y = s_y * persp;
screen.z = s_z;
}
}
return 0; //screenZ;
}
/**
* Calculates 3D bounding box.
*
* @return {minX, maxX, minY, maxY, minZ, maxZ}
*/
public function boundingBox():Object
{
var vertices :Object = this.geometry.vertices;
var bBox :Object = new Object();
bBox.min = new Number3D();
bBox.max = new Number3D();
bBox.size = new Number3D();
for( var i:String in vertices )
{
var v:Vertex3D = vertices[Number(i)];
bBox.min.x = (bBox.min.x == undefined)? v.x : Math.min( v.x, bBox.min.x );
bBox.max.x = (bBox.max.x == undefined)? v.x : Math.max( v.x, bBox.max.x );
bBox.min.y = (bBox.min.y == undefined)? v.y : Math.min( v.y, bBox.min.y );
bBox.max.y = (bBox.max.y == undefined)? v.y : Math.max( v.y, bBox.max.y );
bBox.min.z = (bBox.min.z == undefined)? v.z : Math.min( v.z, bBox.min.z );
bBox.max.z = (bBox.max.z == undefined)? v.z : Math.max( v.z, bBox.max.z );
}
bBox.size.x = bBox.max.x - bBox.min.x;
bBox.size.y = bBox.max.y - bBox.min.y;
bBox.size.z = bBox.max.z - bBox.min.z;
return bBox;
}
public function transformVertices( transformation:Matrix3D ):void
{
var m11 :Number = transformation.n11,
m12 :Number = transformation.n12,
m13 :Number = transformation.n13,
m21 :Number = transformation.n21,
m22 :Number = transformation.n22,
m23 :Number = transformation.n23,
m31 :Number = transformation.n31,
m32 :Number = transformation.n32,
m33 :Number = transformation.n33,
m14 :Number = transformation.n14,
m24 :Number = transformation.n24,
m34 :Number = transformation.n34,
vertices :Array = this.geometry.vertices,
i :int = vertices.length,
vertex :Vertex3D;
// trace( "transformed " + i ); // DEBUG
while( vertex = vertices[--i] )
{
// Center position
var vx :Number = vertex.x;
var vy :Number = vertex.y;
var vz :Number = vertex.z;
var tx :Number = vx * m11 + vy * m12 + vz * m13 + m14;
var ty :Number = vx * m21 + vy * m22 + vz * m23 + m24;
var tz :Number = vx * m31 + vy * m32 + vz * m33 + m34;
vertex.x = tx;
vertex.y = ty;
vertex.z = tz;
}
}
// ___________________________________________________________________________________________________
// R E N D E R
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR
// public function render() {}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Vertices3D.as | ActionScript | art | 8,310 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Mesh3D
package org.papervision3d.core.geom
{
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.*;
import org.papervision3d.core.culling.ITriangleCuller;
import org.papervision3d.core.proto.*;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.scenes.Scene3D;
/**
* The Mesh3D class lets you create and display solid 3D objects made of vertices and triangular polygons.
*/
public class Mesh3D extends Vertices3D
{
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new Mesh object.
*
* The Mesh DisplayObject3D class lets you create and display solid 3D objects made of vertices and triangular polygons.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param vertices An array of Vertex3D objects for the vertices of the mesh.
* <p/>
* @param faces An array of Face3D objects for the faces of the mesh.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created DisplayObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
* <ul>
* <li><b>sortFaces</b>: Z-depth sorting when rendering. Some objects might not need it. Default is false (faster).</li>
* <li><b>showFaces</b>: Use only if each face is on a separate MovieClip container. Default is false.</li>
* </ul>
*
*/
public function Mesh3D( material:MaterialObject3D, vertices:Array, faces:Array, name:String=null, initObject:Object=null )
{
super( vertices, name, initObject );
this.geometry.faces = faces || new Array();
this.material = material || MaterialObject3D.DEFAULT;
}
// ___________________________________________________________________________________________________
// P R O J E C T
// PPPPP RRRRR OOOO JJ EEEEEE CCCC TTTTTT
// PP PP RR RR OO OO JJ EE CC CC TT
// PPPPP RRRRR OO OO JJ EEEE CC TT
// PP RR RR OO OO JJ JJ EE CC CC TT
// PP RR RR OOOO JJJJ EEEEEE CCCC TT
/**
* Projects three dimensional coordinates onto a two dimensional plane to simulate the relationship of the camera to subject.
*
* This is the first step in the process of representing three dimensional shapes two dimensionally.
*
* @param camera Camera3D object to render from.
*/
public override function project( parent :DisplayObject3D, camera :CameraObject3D, sorted :Array=null ):Number
{
// Vertices
super.project( parent, camera, sorted );
if( ! sorted ) sorted = this._sorted;
// Faces
var faces:Array = this.geometry.faces, screenZs:Number = 0, visibleFaces :Number = 0, triCuller:ITriangleCuller = scene.triangleCuller, vertex0:Vertex2D, vertex1:Vertex2D, vertex2 :Vertex2D, iFace:Face3DInstance, face:Face3D;
var mat:MaterialObject3D;
for each(face in faces){
mat = face.material ? face.material : material;
iFace = face.face3DInstance;
iFace.instance = this; //We must be able to do something about this, right ?
vertex0 = face.v0.vertex2DInstance;
vertex1 = face.v1.vertex2DInstance;
vertex2 = face.v2.vertex2DInstance;
if( (iFace.visible = triCuller.testFace(this, iFace, vertex0, vertex1, vertex2)))
{
if(mat.needsFaceNormals){
face.faceNormal.copyTo(iFace.faceNormal);
Matrix3D.multiplyVector3x3( this.view, iFace.faceNormal );
}
if(mat.needsVertexNormals){
face.v0.normal.copyTo(face.v0.vertex2DInstance.normal);
Matrix3D.multiplyVector3x3(this.view, face.v0.vertex2DInstance.normal);
face.v1.normal.copyTo(face.v1.vertex2DInstance.normal);
Matrix3D.multiplyVector3x3(this.view, face.v1.vertex2DInstance.normal);
face.v2.normal.copyTo(face.v2.vertex2DInstance.normal);
Matrix3D.multiplyVector3x3(this.view, face.v2.vertex2DInstance.normal);
}
//Note to self ;-) Get the switch out of here.
switch(meshSort)
{
case DisplayObject3D.MESH_SORT_CENTER:
screenZs += iFace.screenZ = ( vertex0.z + vertex1.z + vertex2.z ) *.333;
break;
case DisplayObject3D.MESH_SORT_FAR:
screenZs += iFace.screenZ = Math.max(vertex0.z,vertex1.z,vertex2.z);
break;
case DisplayObject3D.MESH_SORT_CLOSE:
screenZs += iFace.screenZ = Math.min(vertex0.z,vertex1.z,vertex2.z);
break;
}
visibleFaces++;
sorted.push(iFace);
}else{
scene.stats.culledTriangles++;
}
}
return this.screenZ = screenZs / visibleFaces;
}
/**
* Planar projection from the specified plane.
*
* @param u The texture horizontal axis. Can be "x", "y" or "z". The default value is "x".
* @param v The texture vertical axis. Can be "x", "y" or "z". The default value is "y".
*/
public function projectTexture( u:String="x", v:String="y" ):void
{
var faces :Array = this.geometry.faces,
bBox :Object = this.boundingBox(),
minX :Number = bBox.min[u],
sizeX :Number = bBox.size[u],
minY :Number = bBox.min[v],
sizeY :Number = bBox.size[v];
var objectMaterial :MaterialObject3D = this.material;
for( var i:String in faces )
{
var myFace :Face3D = faces[Number(i)],
myVertices :Array = myFace.vertices,
a :Vertex3D = myVertices[0],
b :Vertex3D = myVertices[1],
c :Vertex3D = myVertices[2],
uvA :NumberUV = new NumberUV( (a[u] - minX) / sizeX, (a[v] - minY) / sizeY ),
uvB :NumberUV = new NumberUV( (b[u] - minX) / sizeX, (b[v] - minY) / sizeY ),
uvC :NumberUV = new NumberUV( (c[u] - minX) / sizeX, (c[v] - minY) / sizeY );
myFace.uv = [ uvA, uvB, uvC ];
}
}
/**
* Merges duplicated vertices.
*/
public function mergeVertices():void
{
var uniqueDic :Dictionary = new Dictionary(),
uniqueList :Array = new Array();
// Find unique vertices
for each( var v:Vertex3D in this.geometry.vertices )
{
for each( var vu:Vertex3D in uniqueDic )
{
if( v.x == vu.x && v.y == vu.y && v.z == vu.z )
{
uniqueDic[ v ] = vu;
break;
}
}
if( ! uniqueDic[ v ] )
{
uniqueDic[ v ] = v;
uniqueList.push( v );
}
}
// Use unique vertices list
this.geometry.vertices = uniqueList;
// Update faces
for each( var f:Face3D in this.geometry.faces )
{
f.v0 = uniqueDic[ f.v0 ];
f.v1 = uniqueDic[ f.v1 ];
f.v2 = uniqueDic[ f.v2 ];
}
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Mesh3D.as | ActionScript | art | 9,315 |
package org.papervision3d.core.geom
{
import flash.display.Sprite;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.Number3D;
public class Face3DInstance
{
public var face:Face3D;
public var instance:DisplayObject3D;
/**
* container is initialized via DisplayObject3D's render method IF DisplayObject3D.faceLevelMode is set to true
*/
public var container:Sprite;
public var visible:Boolean = false;
public var screenZ:Number;
public var faceNormal:Number3D;
public function Face3DInstance(face:Face3D, instance:DisplayObject3D = null)
{
this.face = face;
this.instance = instance;
faceNormal = new Number3D();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Face3DInstance.as | ActionScript | art | 694 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Vertex3D
package org.papervision3d.core.geom
{
import org.papervision3d.core.Number3D;
import com.blitzagency.xray.logger.util.ObjectTools;
import flash.utils.Dictionary;
/**
* The Vertex3D constructor lets you create 3D vertices.
*/
public class Vertex3D
{
/**
* An Number that sets the X coordinate of a object relative to the scene coordinate system.
*/
public var x :Number;
/**
* An Number that sets the Y coordinate of a object relative to the scene coordinates.
*/
public var y :Number;
/**
* An Number that sets the Z coordinate of a object relative to the scene coordinates.
*/
public var z :Number;
/**
* An object that contains user defined properties.
*/
public var extra :Object;
/**
* Vertex2D instance
*/
public var vertex2DInstance:Vertex2D;
//To be docced
public var normal:Number3D;
public var connectedFaces:Dictionary;
/**
* Creates a new Vertex3D object whose three-dimensional values are specified by the x, y and z parameters.
*
* @param x The horizontal coordinate value. The default value is zero.
* @param y The vertical coordinate value. The default value is zero.
* @param z The depth coordinate value. The default value is zero.
*
* */
public function Vertex3D( x:Number=0, y:Number=0, z:Number=0 )
{
this.x = x;
this.y = y;
this.z = z;
this.vertex2DInstance = new Vertex2D();
this.normal = new Number3D();
this.connectedFaces = new Dictionary();
}
public function toNumber3D():Number3D
{
return new Number3D(x,y,z);
}
public function clone():Vertex3D
{
var clone:Vertex3D = new Vertex3D(x,y,z);
clone.extra = extra;
clone.vertex2DInstance = vertex2DInstance.clone();
clone.normal = normal.clone();
return clone;
}
public function calculateNormal():void
{
var face:Face3D;
normal = new Number3D();
for each(face in connectedFaces)
{
normal = Number3D.add(face.faceNormal, normal);
}
normal.normalize();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Vertex3D.as | ActionScript | art | 3,852 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Vertex3D
package org.papervision3d.core.geom
{
import org.papervision3d.core.Number3D;
/**
* The Vertex2D constructor lets you create 2D projected vertices.
*/
public class Vertex2D
{
/**
* An Number that sets the X coordinate of a object relative to the scene coordinate system.
*/
public var x :Number;
/**
* An Number that sets the Y coordinate of a object relative to the scene coordinates.
*/
public var y :Number;
/**
* An Number that sets the Z coordinate of a object relative to the scene coordinates.
*/
public var z :Number;
/**
* An object that contains user defined properties.
*/
public var extra :Object;
/**
* [internal-use] A Boolean value that indicates whether the vertex is visible after projection.
*
* If false, it indicates that the vertex is behind the camera plane.
*
* */
public var visible :Boolean;
//To be docced
public var normal:Number3D;
/**
* Creates a new Vertex2D object whose three-dimensional values are specified by the x, y and z parameters.
*
* @param x The horizontal coordinate value. The default value is zero.
* @param y The vertical coordinate value. The default value is zero.
* @param z The depth coordinate value. The default value is zero.
*
* */
public function Vertex2D( x:Number=0, y:Number=0, z:Number=0 )
{
this.x = x;
this.y = y;
this.z = z;
this.visible = false;
this.normal = new Number3D();
}
public function clone():Vertex2D
{
var clone:Vertex2D = new Vertex2D(x,y,z);
clone.visible = visible;
clone.extra = extra; //TODO : FIX CLONING OF THE EXTRA OBJECT.
return clone;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/geom/Vertex2D.as | ActionScript | art | 3,498 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// SceneObject3D
package org.papervision3d.core.proto
{
import flash.display.Sprite;
import flash.utils.getTimer;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.culling.ITriangleCuller;
import org.papervision3d.core.culling.DefaultTriangleCuller;
import org.papervision3d.core.stat.RenderStatistics;
/**
* The SceneObject3D class is the base class for all scenes.
* <p/>
* A scene is the place where objects are placed, it contains the 3D environment.
* <p/>
* The scene manages all objects rendered in Papervision3D. It extends the DisplayObjectContainer3D class to arrange the display objects.
* <p/>
* SceneObject3D is an abstract base class; therefore, you cannot call SceneObject3D directly.
*/
public class SceneObject3D extends DisplayObjectContainer3D
{
// __________________________________________________________________________
// STATIC
/**
* The Sprite that you draw into when rendering.
*/
public var container :Sprite;
/**
* A list of the geometries in the scene.
*/
private var geometries :Dictionary;
/**
* An object that contains total and current statistics.
* <ul>
* <li>points</li>
* <li>polys</li>
* <li>triangles</li>
* <li>performance<li>
* <li>rendered<li>
* </ul>
*/
public var stats :RenderStatistics;
/**
* It contains a list of DisplayObject3D objects in the scene.
*/
public var objects :Array;
/**
* It contains a list of materials in the scene.
*/
public var materials :MaterialsList;
// ___________________________________________________________________ N E W
//
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* The SceneObject3D class lets you create scene classes.
*
* @param container The Sprite that you draw into when rendering. If not defined, each object must have it's own private container.
*/
public function SceneObject3D( container:Sprite )
{
if( container )
this.container = container;
else
Papervision3D.log( "Scene3D: container argument required." );
this.objects = new Array();
this.materials = new MaterialsList();
Papervision3D.log( Papervision3D.NAME + " " + Papervision3D.VERSION + " (" + Papervision3D.DATE + ")\n" );
this.stats = new RenderStatistics();
this.stats.points = 0;
this.stats.polys = 0;
this.stats.triangles = 0;
this.stats.performance = 0;
this.stats.rendered = 0;
this.root = this;
}
// ___________________________________________________________________ A D D C H I L D
//
// AA DDDDD DDDDD CCCC HH HH II LL DDDDD
// AAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DD DD DD DD CC HHHHHH II LL DD DD
// AAAAAA DD DD DD DD CC CC HH HH II LL DD DD
// AA AA DDDDD DDDDD CCCC HH HH II LLLLLL DDDDD
/**
* Adds a child DisplayObject3D instance to the scene.
*
* If you add a GeometryObject3D symbol, a new DisplayObject3D instance is created.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The GeometryObject3D symbol or DisplayObject3D instance to add as a child of the scene.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public override function addChild( child:DisplayObject3D, name:String=null ):DisplayObject3D
{
var newChild:DisplayObject3D = super.addChild( child, name );
// Added by John Grden for New culling code 7.18.2007
// setting the scene will spread to the child displayobject3d's
child.scene = this;
this.objects.push( newChild );
return newChild;
}
/**
* Removes the specified child DisplayObject3D instance from the child and object list of the scene.
* </p>
* [TODO: The parent property of the removed child is set to null, and the object is garbage collected if no other references to the child exist.]
* </p>
* The garbage collector is the process by which Flash Player reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
* </p>
* @param child The DisplayObject3D instance to remove.
* @return The DisplayObject3D instance that you pass in the child parameter.
*/
public override function removeChild( child:DisplayObject3D ):DisplayObject3D
{
super.removeChild( child );
for (var i:int = 0; i < this.objects.length; i++ )
{
if (this.objects[i] === child )
{
this.objects.splice(i, 1);
return child;
}
}
return child;
}
// ___________________________________________________________________ R E N D E R C A M E R A
//
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR CAMERA
/**
* Generates an image from the camera's point of view and the visible models of the scene.
*
* @param camera camera to render from.
*/
public function renderCamera( camera :CameraObject3D ):void
{
stats.clear();
// Render performance stats
stats.performance = getTimer();
// Materials
MovieMaterial.updateAnimatedBitmaps();
// 3D projection
if( camera )
{
// Transform camera
camera.transformView();
// Project objects
var objects :Array = this.objects;
var p :DisplayObject3D;
var i :Number = objects.length;
while( p = objects[--i] )
if( p.visible )
p.project( camera, camera );
}
// Z sort
if( camera.sort )
this.objects.sortOn( 'screenZ', Array.NUMERIC );
renderObjects( camera.sort );
}
public var triangleCuller:ITriangleCuller = new DefaultTriangleCuller();
/**
* [internal-use]
*
* @param sort
*/
protected function renderObjects( sort:Boolean ):void {}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/proto/SceneObject3D.as | ActionScript | art | 8,698 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// DisplayObjectContainer3D
package org.papervision3d.core.proto
{
import org.papervision3d.Papervision3D;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.core.*;
import org.papervision3d.scenes.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.DisplayObject3D;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
/**
* The GeometryObject3D class contains the mesh definition of an object.
*/
public class GeometryObject3D extends EventDispatcher
{
/**
* A MaterialObject3D object that contains the material properties of the triangle.
*/
// public var material :MaterialObject3D;
/*
public function get material():MaterialObject3D
{
return this._material;
}
public function set material( newMaterial:MaterialObject3D ):void
{
transformUV( newMaterial );
this._material = newMaterial;
}
public var materials :MaterialsList;
*/
/**
* Radius square of the mesh bounding sphere
*/
public function get boundingSphere2():Number
{
if( _boundingSphereDirty )
return getBoundingSphere2();
else
return _boundingSphere2;
}
/**
* An array of Face3D objects for the faces of the mesh.
*/
public var faces :Array;
/**
* An array of vertices.
*/
public var vertices :Array;
public var _ready:Boolean = false;
public function transformVertices( transformation:Matrix3D ):void {}
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
public function GeometryObject3D( initObject:Object=null ):void
{
// this.materials = new MaterialsList();
}
/**
* Returns a string value representing the three-dimensional values in the specified Number3D object.
*
* @return A string.
*/
//public function toString():String
//{
//return 'x:' + Math.floor(this.x) + ' y:' + Math.floor(this.y) + ' z:' + Math.floor(this.z);
//}
// public function project( instance :DisplayObject3D, camera :CameraObject3D, sorted :Array ):Number { return 0; }
// ___________________________________________________________________________________________________
// R E N D E R
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR
/**
* Draws the object into the MovieClip container.
*
* @param scene A Papervision3D object that contains the current scene.
*/
// public function render( instance:DisplayObject3D, scene:SceneObject3D, sorted :Array=null ):void {}
public function transformUV( material:MaterialObject3D ):void
{
if( material.bitmap )
for( var i:String in this.faces )
faces[i].transformUV( material );
}
public function getBoundingSphere2():Number
{
var max :Number = 0;
var d :Number;
for each( var v:Vertex3D in this.vertices )
{
d = v.x*v.x + v.y*v.y + v.z*v.z;
max = (d > max)? d : max;
}
this._boundingSphereDirty = false;
return _boundingSphere2 = max;
}
private function createVertexNormals():void
{
var tempVertices:Dictionary = new Dictionary(true);
var face:Face3D;
var vertex3D:Vertex3D;
for each(face in faces){
face.v0.connectedFaces[face] = face;
face.v1.connectedFaces[face] = face;
face.v2.connectedFaces[face] = face;
tempVertices[face.v0] = face.v0;
tempVertices[face.v1] = face.v1;
tempVertices[face.v2] = face.v2;
}
for each (vertex3D in tempVertices){
vertex3D.calculateNormal();
}
}
public function set ready(b:Boolean):void
{
if(b){
createVertexNormals();
}
_ready = b;
}
public function get ready():Boolean
{
return _ready;
}
// ___________________________________________________________________________________________________
// P R I V A T E
protected var _material :MaterialObject3D;
protected var _boundingSphere2 :Number;
protected var _boundingSphereDirty :Boolean = true;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/proto/GeometryObject3D.as | ActionScript | art | 6,596 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ DisplayObjectContainer3D
package org.papervision3d.core.proto
{
import org.papervision3d.Papervision3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.MaterialsList;
import flash.events.EventDispatcher;
import flash.utils.Dictionary;
/**
* The DisplayObjectContainer3D class is the base class for all objects that can serve as DisplayObject3D containers.
* <p/>
* Each DisplayObjectContainer3D object has its own child list.
*/
public class DisplayObjectContainer3D extends EventDispatcher
{
/**
* [read-only] [read-only] The scene, which is the top-most displayObjectContainer3D in the tree structure.
*/
public var root :DisplayObjectContainer3D;
// ___________________________________________________________________ C O L L A D A
/**
* This method has been deprecated.
*/
public function addCollada( filename :String, materials :MaterialsList=null, scale :Number=1 ):void
{
Papervision3D.log( "The addCollada() method has been deprecated. Use addChildren( new Collada( filename ) )" );
}
/**
* Returns the number of children of this object.
*/
public function get numChildren():int
{
return this._childrenTotal;
}
/**
* Returns the children object.
*/
public function get children():Object
{
return this._childrenByName;
}
// ___________________________________________________________________ N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new DisplayObjectContainer3D object.
*/
public function DisplayObjectContainer3D():void
{
this._children = new Dictionary( false );
this._childrenByName = new Dictionary( true );
this._childrenTotal = 0;
}
// ___________________________________________________________________ C H I L D R E N
/**
* Adds a child DisplayObject3D instance to this DisplayObjectContainer instance.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The DisplayObject3D instance to add as a child of this DisplayObjectContainer3D instance.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public function addChild( child :DisplayObject3D, name:String=null ):DisplayObject3D
{
// Choose name
name = name || child.name || String( child.id );
this._children[ child ] = name;
this._childrenByName[ name ] = child;
this._childrenTotal++;
child.parent = this;
child.root = this.root;
return child;
}
/**
* Adds all the children of a DisplayObject3D instance to this DisplayObjectContainer instance.
*
* @param child The DisplayObjectContainer3D instance that contains the children to add.
* @return The DisplayObject3D instance that you have added or created.
*/
public function addChildren( parent :DisplayObject3D ):DisplayObjectContainer3D
{
for each( var child:DisplayObject3D in parent.children )
{
parent.removeChild( child );
this.addChild( child );
}
return this;
}
/**
* Removes the specified child DisplayObject3D instance from the child list of the DisplayObjectContainer3D instance.
* </p>
* [TODO: The parent property of the removed child is set to null, and the object is garbage collected if no other references to the child exist.]
* </p>
* The garbage collector is the process by which Flash Player reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
* </p>
* @param child The DisplayObject3D instance to remove.
* @return The DisplayObject3D instance that you pass in the child parameter.
*/
/*
public function removeChild( child:DisplayObject3D ):DisplayObject3D
{
delete this._childrenByName[ this._children[ child ] ];
delete this._children[ child ];
child.parent = null;
child.root = null;
return child;
}
*/
/**
* @private
* Added from Bug #10 by John Grden 8/22/2007
*/
public function removeChild( child:DisplayObject3D ):DisplayObject3D
{
//removeChildByname(name:string) may return null // must check here
if(child){
delete this._childrenByName[ this._children[ child ] ];
delete this._children[ child ];
child.parent = null;
child.root = null;
return child;
}
return null;
}
/**
* Returns the child display object that exists with the specified name.
* </p>
* If more that one child display object has the specified name, the method returns the first object in the child list.
* </p>
* @param name The name of the child to return.
* @return The child display object with the specified name.
*/
public function getChildByName( name:String ):DisplayObject3D
{
return this._childrenByName[ name ];
}
/**
* Removes the child DisplayObject3D instance that exists with the specified name, from the child list of the DisplayObjectContainer3D instance.
* </p>
* If more that one child display object has the specified name, the method removes the first object in the child list.
* </p>
* [TODO: The parent property of the removed child is set to null, and the object is garbage collected if no other references to the child exist.]
* </p>
* The garbage collector is the process by which Flash Player reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
* </p>
* @param name The name of the child to remove.
* @return The DisplayObject3D instance that was removed.
*/
public function removeChildByName( name:String ):DisplayObject3D
{
return removeChild( getChildByName( name ) );
}
// ___________________________________________________________________ D E B U G
/**
* Returns a string value with the list of objects.
*
* @return A string.
*/
public override function toString():String
{
return childrenList();
}
/**
* Returns a string value with the list of objects.
*
* @return A string.
*/
public function childrenList():String
{
var list:String = "";
for( var name:String in this._children )
list += name + "\n";
return list;
}
// ___________________________________________________________________ P R O T E C T E D
/**
* [internal-use] Names indexed by children.
*/
protected var _children :Dictionary;
/**
* [internal-use] Children indexed by name.
*/
protected var _childrenByName :Object;
// ___________________________________________________________________ P R I V A T E
private var _childrenTotal :int;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/proto/DisplayObjectContainer3D.as | ActionScript | art | 8,983 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ MaterialObject3D
package org.papervision3d.core.proto
{
import flash.geom.Matrix;
import flash.display.BitmapData;
import flash.events.EventDispatcher;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.WireframeMaterial;
/**
* The MaterialObject3D class is the base class for all materials.
* <p/>
* Materials collects data about how objects appear when rendered.
* <p/>
* A material is data that you assign to objects or faces, so that they appear a certain way when rendered. Materials affect the line and fill colors.
* <p/>
* Materials create greater realism in a scene. A material describes how an object reflects or transmits light.
* <p/>
* You assign materials to individual objects or a selection of faces; a single object can contain different materials.
* <p/>
* MaterialObject3D is an abstract base class; therefore, you cannot call MaterialObject3D directly.
*/
public class MaterialObject3D extends EventDispatcher implements IFaceDrawer
{
/**
* A transparent or opaque BitmapData texture.
*/
public var bitmap :BitmapData;
/**
* A Boolean value that determines whether the BitmapData texture is smoothed when rendered.
*/
public var smooth :Boolean = false;
/**
* A Boolean value that determines whether the texture is tiled when rendered. Defaults to false.
*/
public var tiled :Boolean = false;
/**
* A RGB color value to draw the faces outline.
*/
public var lineColor :Number = DEFAULT_COLOR;
/**
* An 8-bit alpha value for the faces outline. If zero, no outline is drawn.
*/
public var lineAlpha :Number = 0;
/**
* An value for the thickness of the faces line.
*/
public var lineThickness:Number = 1;
/**
* A RGB color value to fill the faces with. Only used if no texture is provided.
*/
public var fillColor :Number = DEFAULT_COLOR;
/**
* An 8-bit alpha value fill the faces with. If this value is zero and no texture is provided or is undefined, a fill is not created.
*/
public var fillAlpha :Number = 0;
/**
* A Boolean value that indicates whether the faces are double sided.
*/
public function get doubleSided():Boolean
{
return ! this.oneSide;
}
public function set doubleSided( double:Boolean ):void
{
this.oneSide = ! double;
}
/**
* A Boolean value that indicates whether the faces are single sided. It has preference over doubleSided.
*/
public var oneSide :Boolean = true;
/**
* A Boolean value that indicates whether the faces are invisible (not drawn).
*/
public var invisible :Boolean = false;
/**
* A Boolean value that indicates whether the face is flipped. Only used if doubleSided or not singeSided.
*/
public var opposite :Boolean = false;
/**
* The scene where the object belongs.
*/
public var scene :SceneObject3D;
/**
* Color used for DEFAULT material.
*/
static public var DEFAULT_COLOR :int = 0x000000;
/**
* Color used for DEBUG material.
*/
static public var DEBUG_COLOR :int = 0xFF00FF;
/**
* The name of the material.
*/
public var name :String;
/**
* [internal-use] [read-only] Unique id of this instance.
*/
public var id :Number;
/**
* Internal use
*/
public var maxU :Number;
/**
* Internal use
*/
public var maxV :Number;
/**
* Defines if face normals need to be rotated for this material.
*/
public var needsFaceNormals:Boolean = false;
//To be docced
public var needsVertexNormals:Boolean = false;
/**
* Holds the original size of the bitmap before it was resized by Automip mapping
*/
public var widthOffset:Number = 0;
/**
* Holds the original size of the bitmap before it was resized by Automip mapping
*/
public var heightOffset:Number = 0;
// public var extra :Object;
/**
* Creates a new MaterialObject3D object.
*
* @param initObject [optional] - An object that contains properties for the newly created material.
*/
public function MaterialObject3D()
{
this.id = _totalMaterialObjects++;
}
/**
* Returns a MaterialObject3D object with the default magenta wireframe values.
*
* @return A MaterialObject3D object.
*/
static public function get DEFAULT():MaterialObject3D
{
var defMaterial :MaterialObject3D = new WireframeMaterial(); //RH, it now returns a wireframe material.
defMaterial.lineColor = 0xFFFFFF * Math.random();
defMaterial.lineAlpha = 1;
defMaterial.fillColor = DEFAULT_COLOR;
defMaterial.fillAlpha = 1;
defMaterial.doubleSided = false;
return defMaterial;
}
static public function get DEBUG():MaterialObject3D
{
var defMaterial :MaterialObject3D = new MaterialObject3D();
defMaterial.lineColor = 0xFFFFFF * Math.random();
defMaterial.lineAlpha = 1;
defMaterial.fillColor = DEBUG_COLOR;
defMaterial.fillAlpha = 0.37;
defMaterial.doubleSided = true;
return defMaterial;
}
/**
* drawFace3D();
*
* Draws the triangle to screen.
*
*/
public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
return 0;
}
/**
* Updates the BitmapData bitmap from the given texture.
*
* Draws the current MovieClip image onto bitmap.
*/
public function updateBitmap():void {}
/**
* Copies the properties of a material.
*
* @param material Material to copy from.
*/
public function copy( material :MaterialObject3D ):void
{
this.bitmap = material.bitmap;
// this.animated = material.animated;
this.smooth = material.smooth;
this.lineColor = material.lineColor;
this.lineAlpha = material.lineAlpha;
this.fillColor = material.fillColor;
this.fillAlpha = material.fillAlpha;
this.needsFaceNormals = material.needsFaceNormals;
this.needsVertexNormals = material.needsVertexNormals;
this.oneSide = material.oneSide;
this.opposite = material.opposite;
this.invisible = material.invisible;
this.scene = material.scene;
this.name = material.name;
this.maxU = material.maxU;
this.maxV = material.maxV;
}
/**
* Creates a copy of the material.
*
* @return A newly created material that contains the same properties.
*/
public function clone():MaterialObject3D
{
var cloned:MaterialObject3D = new MaterialObject3D();
cloned.copy(this);
return cloned;
}
/**
* Returns a string value representing the material properties.
*
* @return A string.
*/
override public function toString():String
{
return '[MaterialObject3D] bitmap:' + this.bitmap + ' lineColor:' + this.lineColor + ' fillColor:' + fillColor;
}
static private var _totalMaterialObjects :Number = 0;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/proto/MaterialObject3D.as | ActionScript | art | 9,023 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// DisplayObject3D: Camera3D
package org.papervision3d.core.proto
{
import org.papervision3d.Papervision3D;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.objects.DisplayObject3D;
/**
* The CameraObject3D class is the base class for all the cameras that can be placed in a scene.
* <p/>
* A camera defines the view from which a scene will be rendered. Different camera settings would present a scene from different points of view.
* <p/>
* 3D cameras simulate still-image, motion picture, or video cameras of the real world. When rendering, the scene is drawn as if you were looking through the camera lens.
*/
public class CameraObject3D extends DisplayObject3D
{
// __________________________________________________________________________
// PUBLIC
/**
* This value specifies the scale at which the 3D objects are rendered. Higher values magnify the scene, compressing distance. Use it in conjunction with focus.
*/
public var zoom :Number;
/**
* This value is a positive number representing the distance of the observer from the front clipping plane, which is the closest any object can be to the camera. Use it in conjunction with zoom.
* <p/>
* Higher focus values tend to magnify distance between objects while allowing greater depth of field, as if the camera had a wider lenses. One result of using a wide angle lens in proximity to the subject is an apparent perspective distortion: parallel lines may appear to converge and with a fisheye lens, straight edges will appear to bend.
* <p/>
* Different lenses generally require a different camera to subject distance to preserve the size of a subject. Changing the angle of view can indirectly distort perspective, modifying the apparent relative size of the subject and foreground.
*/
public var focus :Number;
/**
* A Boolean value that determines whether the 3D objects are z-depth sorted between themselves when rendering.
*/
public var sort :Boolean;
/**
* The default position for new cameras.
*/
public static var DEFAULT_POS :Number3D = new Number3D( 0, 0, -1000 );
// __________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* The CameraObject3D constructor lets you create cameras for setting up the view from which a scene will be rendered.
*
* Its initial position can be specified in the initObject.
*
* @param zoom This value specifies the scale at which the 3D objects are rendered. Higher values magnify the scene, compressing distance. Use it in conjunction with focus.
* <p/>
* @param focus This value is a positive number representing the distance of the observer from the front clipping plane, which is the closest any object can be to the camera. Use it in conjunction with zoom.
* <p/>
* @param initObject An optional object that contains user defined properties with which to populate the newly created DisplayObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
* <p/>
* The following initObject property is also recognized by the constructor:
* <ul>
* <li><b>sort</b>: A Boolean value that determines whether the 3D objects are z-depth sorted between themselves when rendering. The default value is true.</li>
* </ul>
*/
public function CameraObject3D( zoom:Number=3, focus:Number=500, initObject:Object=null )
{
super();
this.x = initObject? initObject.x || DEFAULT_POS.x : DEFAULT_POS.x;
this.y = initObject? initObject.y || DEFAULT_POS.y : DEFAULT_POS.y;
this.z = initObject? initObject.z || DEFAULT_POS.z : DEFAULT_POS.z;
this.zoom = zoom;
this.focus = focus;
this.sort = initObject? (initObject.sort != false) : true;
}
// ___________________________________________________________________________________________________
// T R A N S F O R M
// TTTTTT RRRRR AA NN NN SSSSS FFFFFF OOOO RRRRR MM MM
// TT RR RR AAAA NNN NN SS FF OO OO RR RR MMM MMM
// TT RRRRR AA AA NNNNNN SSSS FFFF OO OO RRRRR MMMMMMM
// TT RR RR AAAAAA NN NNN SS FF OO OO RR RR MM M MM
// TT RR RR AA AA NN NN SSSSS FF OOOO RR RR MM MM
/**
* [internal-use] Transforms world coordinates into camera space.
*/
// TODO: OPTIMIZE (LOW) Resolve + inline
public function transformView( transform:Matrix3D=null ):void
{
this.view = Matrix3D.inverse( Matrix3D.multiply( transform || this.transform, _flipY ) );
}
static private var _flipY :Matrix3D = Matrix3D.scaleMatrix( 1, -1, 1 );
/**
* Rotate the camera in its vertical plane.
* <p/>
* Tilting the camera results in a motion similar to someone nodding their head "yes".
*
* @param angle Angle to tilt the camera.
*/
public function tilt( angle:Number ):void
{
super.pitch( angle );
}
/**
* Rotate the camera in its horizontal plane.
* <p/>
* Panning the camera results in a motion similar to someone shaking their head "no".
*
* @param angle Angle to pan the camera.
*/
public function pan( angle:Number ):void
{
super.yaw( angle );
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/proto/CameraObject3D.as | ActionScript | art | 7,612 |
package org.papervision3d.core.culling
{
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Face3DInstance;
import org.papervision3d.objects.DisplayObject3D;
public interface ITriangleCuller
{
function testFace(displayObject:DisplayObject3D, faceInstance:Face3DInstance, vertex0:Vertex2D, vertex1:Vertex2D, vertex2:Vertex2D):Boolean;
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/culling/ITriangleCuller.as | ActionScript | art | 420 |
package org.papervision3d.core.culling
{
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3DInstance;
public class CompositeTriangleCuller implements ITriangleCuller
{
private var cullers:Array;
public function CompositeTriangleCuller()
{
init();
}
private function init():void
{
cullers = new Array();
}
public function addCuller(culler:ITriangleCuller):void
{
cullers.push(culler);
}
public function removeCuller(culler:ITriangleCuller):void
{
cullers.splice(cullers.indexOf(culler),1);
}
public function clearCullers():void
{
cullers = new Array();
}
public function testFace(displayObject:DisplayObject3D, faceInstance:Face3DInstance, vertex0:Vertex2D, vertex1:Vertex2D, vertex2:Vertex2D):Boolean
{
for each(var culler:ITriangleCuller in cullers)
{
//Add "modes here". Like inclusive or exclusive
}
return true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/culling/CompositeTriangleCuller.as | ActionScript | art | 1,053 |
package org.papervision3d.core.culling
{
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Face3DInstance;
import org.papervision3d.objects.DisplayObject3D;
public class DepthTriangleCuller implements ITriangleCuller
{
public function DepthTriangleCuller()
{
}
public function testFace(displayObject:DisplayObject3D, faceInstance:Face3DInstance, vertex0:Vertex2D, vertex1:Vertex2D, vertex2:Vertex2D):Boolean
{
return false;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/culling/DepthTriangleCuller.as | ActionScript | art | 540 |
package org.papervision3d.core.culling
{
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.geom.Face3DInstance;
import org.papervision3d.objects.DisplayObject3D;
public class DefaultTriangleCuller implements ITriangleCuller
{
private static var x0:Number;
private static var y0:Number;
private static var x1:Number;
private static var y1:Number;
private static var x2:Number;
private static var y2:Number;
public function DefaultTriangleCuller()
{
}
public function testFace(displayObject3D:DisplayObject3D, faceInstance:Face3DInstance, vertex0:Vertex2D, vertex1:Vertex2D, vertex2:Vertex2D):Boolean
{
//Material checks & backface culling
if(vertex0.visible && vertex1.visible && vertex2.visible){
var material:MaterialObject3D = faceInstance.face.material ? faceInstance.face.material : displayObject3D.material;
if(material.invisible){
return false
};
x0 = vertex0.x;
y0 = vertex0.y;
x1 = vertex1.x;
y1 = vertex1.y;
x2 = vertex2.x;
y2 = vertex2.y;
if( material.oneSide ){
if( material.opposite ){
if( ( x2 - x0 ) * ( y1 - y0 ) - ( y2 - y0 ) * ( x1 - x0 ) > 0 )
{
return false;
}
}else{
if( ( x2 - x0 ) * ( y1 - y0 ) - ( y2 - y0 ) * ( x1 - x0 ) < 0 )
{
return false;
}
}
}
return true;
}
return false;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/culling/DefaultTriangleCuller.as | ActionScript | art | 1,478 |
package org.papervision3d.core.culling
{
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Face3D;
import flash.geom.Rectangle;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3DInstance;
public class RectangleTriangleCuller extends DefaultTriangleCuller implements ITriangleCuller
{
private static const DEFAULT_RECT_W:Number = 640;
private static const DEFAULT_RECT_H:Number = 480;
private static const DEFAULT_RECT_X:Number = -(DEFAULT_RECT_W/2);
private static const DEFAULT_RECT_Y:Number = -(DEFAULT_RECT_H/2);
private static var hitRect:Rectangle = new Rectangle();
public var cullingRectangle:Rectangle = new Rectangle(DEFAULT_RECT_X, DEFAULT_RECT_Y, DEFAULT_RECT_W, DEFAULT_RECT_H);
/**
* @Author Ralph Hauwert
*
* RectangleTriangleCuller
*
* This Triangle Culler culls faces based upon the visibility of it vertices and their visibility in a defined rectangle.
*/
public function RectangleTriangleCuller(cullingRectangle:Rectangle = null):void
{
if(cullingRectangle){
this.cullingRectangle = cullingRectangle;
}
}
override public function testFace(displayObject3D:DisplayObject3D, faceInstance:Face3DInstance, vertex0:Vertex2D, vertex1:Vertex2D, vertex2:Vertex2D):Boolean
{
if(super.testFace(displayObject3D, faceInstance, vertex0, vertex1, vertex2)){
hitRect.x = Math.min(vertex2.x, Math.min(vertex1.x, vertex0.x));
hitRect.width = Math.max(vertex2.x, Math.max(vertex1.x, vertex0.x)) + Math.abs(hitRect.x);
hitRect.y = Math.min(vertex2.y, Math.min(vertex1.y, vertex0.y));
hitRect.height = Math.max(vertex2.y, Math.max(vertex1.y, vertex0.y)) + Math.abs(hitRect.y);
return cullingRectangle.intersects(hitRect);
}
return false;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/core/culling/RectangleTriangleCuller.as | ActionScript | art | 1,826 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Ase
package org.papervision3d.objects
{
import org.papervision3d.Papervision3D;
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.events.FileLoadEvent;
//import com.blitzagency.xray.logger.XrayLog;
import flash.display.BitmapData;
import flash.events.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
/**
* The Ase class lets you load and parse ASE format objects exported from 3DS Max.
* <p/>
* Only the geometry and mapping of one mesh is currently parsed.
* <p/>
* For more complex objects, it is recommended to import Collada scenes with addCollada method.
*/
public class Ase extends Mesh3D
{
/**
* Whether or not the scene has been loaded.
*/
public var loaded :Boolean;
/**
* Default scaling value for constructor.
*/
static public var DEFAULT_SCALING :Number = 1;
/**
* Internal scaling value.
*/
static public var INTERNAL_SCALING :Number = 50;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new Ase object that will load and parse a 3DS Max exported .ASE mesh.
* <p/>
* Only the geometry and mapping of one mesh is currently parsed.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param filename Filename of the .ASE object to parse.
* <p/>
* @param scale Scaling factor.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Ase( material:MaterialObject3D, filename:String, scale:Number=1, initObject:Object=null )
{
super( material, new Array(), new Array(), null, initObject );
this._scaleAse = scale;
this._filename = filename;
this.loaded = false;
loadAse( filename );
}
private function loadAse( filename:String ):void
{
_loaderAse = new URLLoader();
_loaderAse.addEventListener( Event.COMPLETE, parseAse );
_loaderAse.addEventListener( ProgressEvent.PROGRESS, progressHandler);
_loaderAse.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler);
var request:URLRequest = new URLRequest(filename);
try
{
_loaderAse.load(request);
}
catch(e:Error)
{
Papervision3D.log( "error in loading ase file" );
}
}
// ___________________________________________________________________________________________________
// A S E
// AA SSSSS EEEEEE
// AAAA SS EE
// AA AA SSSS EEEE
// AAAAAA SS EE
// AA AA SSSSS EEEEEE PARSER
/**
* Taken from w3d at http://blog.andre-michelle.com/2005/flash8-sourcecodes
* By Andre Michelle, with much respect
*/
private function parseAse( e:Event ):void
{
var scale:Number = this._scaleAse;
scale *= INTERNAL_SCALING;
var vertices :Array = this.geometry.vertices = new Array();
var faces :Array = this.geometry.faces = new Array();
var loader:URLLoader = URLLoader(e.target);
var lines: Array = unescape(loader.data).split( '\r\n' );
var line: String;
var chunk: String;
var content: String;
var uvs:Array = new Array();
var material :MaterialObject3D = this.material;
while( lines.length )
{
line = String( lines.shift() );
//-- clear white space from beginn
line = line.substr( line.indexOf( '*' ) + 1 );
//-- clear closing brackets
if( line.indexOf( '}' ) >= 0 ) line = '';
//-- get chunk description
chunk = line.substr( 0, line.indexOf( ' ' ) );
switch( chunk )
{
case 'MESH_VERTEX_LIST':
try
{
while( ( content = String( lines.shift() ) ).indexOf( '}' ) < 0 )
{
content = content.split("*")[1];
//content = content.split(" ").join("\t");
var mvl: Array = content.split( '\t' ); // separate here
var x:Number = Number( mvl[1] ) * scale;
var y:Number = Number( mvl[3] ) * scale;
var z:Number = Number( mvl[2] ) * scale; // Swapped Y and Z
vertices.push( new Vertex3D( x, y, z ) );
}
}
catch(e:Error)
{
Papervision3D.log( "MESH_VERTEX_LIST error" );
}
break;
case 'MESH_FACE_LIST':
try
{
while( ( content = String( lines.shift() ) ).indexOf( '}' ) < 0 )
{
content = content.split("*")[1];
var mfl: String = content.split('\t')[0]; // ignore: [MESH_SMOOTHING,MESH_MTLID]
var drc: Array = mfl.split( ':' ); // separate here
var con: String;
con = drc[2]
var a:Vertex3D = vertices[ int( con.substr( 0, con.lastIndexOf( ' ' ) ) ) ];
con = drc[3];
var b:Vertex3D = vertices[ int( con.substr( 0, con.lastIndexOf( ' ' ) ) ) ];
con = drc[4];
var c:Vertex3D = vertices[ int( con.substr( 0, con.lastIndexOf( ' ' ) ) ) ];
// Swap b/c
faces.push( new Face3D( [a, b, c], null, [new NumberUV(), new NumberUV(), new NumberUV()] ) );
}
}
catch(e:Error)
{
Papervision3D.log( "MESH_FACE_LIST : " );
}
break;
case 'MESH_TVERTLIST':
try
{
while( ( content = String( lines.shift() ) ).indexOf( '}' ) < 0 )
{
content = content.split("*")[1];
var mtvl: Array = content.split( '\t' ); // separate here
uvs.push( new NumberUV( parseFloat( mtvl[1] ), parseFloat( mtvl[2] ) ) );
}
}
catch(e:Error)
{
Papervision3D.log( "MESH_TVERTLIST error" + e.message );
}
break;
case 'MESH_TFACELIST':
try
{
var num: int = 0;
while( ( content = String( lines.shift() ) ).indexOf( '}' ) < 0 )
{
content = content.substr( content.indexOf( '*' ) + 1 );
var mtfl: Array = content.split( '\t' ); // separate here
var faceUV:Array = faces[ num ].uv;
faceUV[0] = uvs[ parseInt( mtfl[1] )];
faceUV[1] = uvs[ parseInt( mtfl[2] )];
faceUV[2] = uvs[ parseInt( mtfl[3] )];
num++;
}
}
catch(e:Error)
{
Papervision3D.log( "MESH_TFACELIST ERROR" + e.message );
}
break;
}
}
// dispatch event
var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_COMPLETE, _filename );
dispatchEvent( fileEvent );
this.loaded = true;
this.geometry.ready = true;
Papervision3D.log( "Parsed ASE: " + this._filename + " [vertices:" + vertices.length + " faces:" + faces.length + "]" );
}
// ___________________________________________________________________________________________________
private function ioErrorHandler(event:IOErrorEvent):void
{
var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_ERROR, _filename );
dispatchEvent( fileEvent );
throw new Error("Ase: ioErrorHandler Error.");
}
private function progressHandler(event:ProgressEvent):void
{
Papervision3D.log("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
}
// ___________________________________________________________________________________________________
private var _scaleAse :Number;
private var _loaderAse :URLLoader;
private var _filename :String
//private var log:XrayLog = new XrayLog();
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Ase.as | ActionScript | art | 9,966 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Cone
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Cone class lets you create and display Cones.
* <p/>
* The Cone is divided in vertical and horizontal segment, the smallest combination is two vertical and three horizontal segments.
*/
public class Cone extends Cylinder
{
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Cone object.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param radius [optional] - Desired radius.
* <p/>
* @param segmentsW [optional] - Number of segments horizontally. Defaults to 8.
* <p/>
* @param segmentsH [optional] - Number of segments vertically. Defaults to 6.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Cone( material:MaterialObject3D=null, radius:Number=100, height:Number=100, segmentsW:int=8, segmentsH:int=6, initObject:Object=null )
{
super( material, radius, height, segmentsW, segmentsH, 0, initObject );
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Cone.as | ActionScript | art | 3,728 |
package org.papervision3d.objects
{
// ______________________________________________________________________________
// PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
// AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
// PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
// ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
// RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV
// PAPERVISION 5 Alpha
// Carlos Ulloa Matesanz
// C4RL054321@gmail.com
// www.noventaynueve.com
// noventaynueve.com/blog
import org.papervision3d.scenes.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.materials.*;
import org.papervision3d.core.geom.*;
import org.papervision3d.Papervision3D;
//import org.papervision3d.core.*;
//import org.papervision3d.core.proto.*;
import flash.display.*;
import flash.geom.Point;
import flash.utils.Dictionary;
import com.blitzagency.xray.logger.XrayLog;
/**
* The Stars GeometryObject3D class lets you create and display 3D starfields.
* <p/>
*/
import flash.display.MovieClip;
public class Stars extends org.papervision3d.core.geom.Vertices3D
{
/**
* A BitmapMaterial object that contains the material properties of the triangle.
*/
//public var material :BitmapMaterial;
/**
* The number of stars.
*/
public var quantity :Number;
/**
* The width.
*/
public var width :Number;
/**
* Height
*/
public var height :Number;
/**
* Depth
*/
public var depth :Number;
public var target:Sprite;
/**
* Default size of Plane if not texture is defined.
*/
static public var DEFAULT_SIZE :Number = 1000;
/**
* Default size of Plane if not texture is defined.
*/
static public var DEFAULT_STAGE_WIDTH :Number = 2048;
static public var DEFAULT_STAGE_HEIGHT :Number = 2048;
/**
* Size of the stage.
*/
public var stageWidth :Number;
/**
* Size of the stage.
*/
public var stageHeight :Number;
private var log:XrayLog = new XrayLog();
private var _bdCanvas :BitmapData;
private var bm:Bitmap = new Bitmap();
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create new Stars object.
* <p/>
* @param material A BitmapMaterial object that contains the material properties of the object.
* <p/>
* @param width Width.
* <p/>
* @param height Height.
* <p/>
* @param depth Depth.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined data object.
* <p/>
* If data is not an object, it is ignored. All properties of the data field are copied into the new instance. The properties specified with data are publicly available.
*/
public function Stars( material:ColorMaterial, target:Sprite, quantity:Number=900, width:Number=1000, height:Number=1000, depth:Number=1000, initObject:Object=null )
{
if( target is Sprite )
{
super( new Array(), "Stars", initObject );
this.material = material// || BitmapMaterial.DEFAULT;
this.target = target;
this.quantity = quantity || DEFAULT_SIZE;
this.width = width || DEFAULT_SIZE;
this.height = height || DEFAULT_SIZE;
this.depth = depth || DEFAULT_SIZE;
this.stageWidth = target.width || DEFAULT_STAGE_WIDTH;
this.stageHeight = target.height || DEFAULT_STAGE_HEIGHT;
buildStars();
_bdCanvas = new BitmapData( this.stageWidth, this.stageHeight, false, 0x00000000);
// _bdCanvas.copyPixels( this.material.texture, this.material.texture.rect, new Point( 0, 0 ) );
// Attach bitmap to canvas
//var canvas :Sprite = target; //.createEmptyMovieClip( "iCentered", 10 );
//canvas.addChildAt( _bdCanvas, canvas.getNextHighestDepth() );
bm.bitmapData = _bdCanvas;
target.addChild(bm);
bm.x = -stageWidth/2; // - this.stageWidth /2;
bm.y = -stageHeight/2;// - this.stageHeight /2;
//target.graphics.beginBitmapFill( _bdCanvas );
//target.graphics.endFill();
//canvas.x = 0;//stage.stageWidth/2 - this.stageWidth /2;
//canvas.y = 0; //stage.stageHeight/2 - this.stageHeight /2;
//this.canvas = canvas;
// this.screenZ = 66666666; // Backdrop
}
//else if( Papervision3D.VERBOSE )
//log.debug( "Stars: Canvas not found" );
}
private function buildStars():void
{
var quantity:Number = this.quantity;
var vertices:Array = this.geometry.vertices;
var width :Number = this.width;
var height :Number = this.height;
var depth :Number = this.depth;
var width2 :Number = width /2;
var height2 :Number = height /2;
var depth2 :Number = depth /2;
// Vertices
for( var i:Number = 0; i < quantity; i++ )
{
var x :Number = Math.random() * width - width2;
var y :Number = Math.random() * height - height2;
var z :Number = Math.random() * depth - depth2;
var v :Vertex3D = new Vertex3D( x, y, z );
//v.data = new Object();
//v.data.color =(Math.floor( 0x60 + 0x80 * Math.random() ) << 24) + 0xFFFFFF;
//var data:Object = new Object();
//data.color =(Math.floor( 0x60 + 0x80 * Math.random() ) << 24) + 0xFFFFFF;
//v.extra = data;
vertices.push( v );
}
}
public override function render( scene :SceneObject3D ):void
{
try
{
// Clear bitmap
var sW2: Number = this.stageWidth /2;
var sH2: Number = this.stageHeight /2;
//log.debug("0", sW2 + ", " + sH2);
var bd:BitmapData = this._bdCanvas;
bd.fillRect( bd.rect, 0x000000);
//log.debug("1", bd.width);
// Paint stars
var pixels :Number = 0;
//log.debug("2");
var color:int = material.fillColor || 0xFFFFFF;
//log.debug("3");
var v3d:Vertex3D;
var v2d:Vertex2D;
for each(v3d in geometry.vertices)
{
v2d = v3d.vertex2DInstance;
//log.debug("4", v.visible);
if( v2d.visible )
{
_bdCanvas.setPixel( sW2 + v2d.x, sH2 + v2d.y, color );
pixels++;
}
}
}catch(e:Error)
{
log.error("stars.render error", e.message);
}
// Update stats
scene.stats.pixels += pixels;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Stars.as | ActionScript | art | 6,866 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org blog.papervision3d.org osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ PaperPlane
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The PaperPlane class lets you create a paper plane object.
* <p/>
* Paper planes are useful for testing, when you want to know the direction an object is facing.
*/
public class PaperPlane extends Mesh3D
{
/**
* Default value of segments.
*/
static public var DEFAULT_SCALE :Number = 1;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new PaperPlane object.
* <p/>
* @param material A Material3D object that contains the material properties of the object.
* <p/>
* @param scale [optional] - Scaling factor
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function PaperPlane( material :MaterialObject3D=null, scale :Number=0, initObject :Object=null )
{
super( material, new Array(), new Array(), null, initObject );
scale = scale || DEFAULT_SCALE;
buildPaperPlane( scale );
}
private function buildPaperPlane( scale :Number ):void
{
var a :Number = 100 * scale;
var b :Number = a/2;
var c :Number = b/3;
var v:Array =
[
new Vertex3D( 0, 0, a ),
new Vertex3D( -b, c, -a ),
new Vertex3D( -c, c, -a ),
new Vertex3D( 0, -c, -a ),
new Vertex3D( c, c, -a ),
new Vertex3D( b, c, -a )
];
this.geometry.vertices = v;
this.geometry.faces =
[
new Face3D( [v[0], v[1], v[2]] ),
new Face3D( [v[0], v[2], v[3]] ),
new Face3D( [v[0], v[3], v[4]] ),
new Face3D( [v[0], v[4], v[5]] )
];
this.projectTexture( "x", "z" );
this.geometry.ready = true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/PaperPlane.as | AngelScript | art | 4,237 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Sphere
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Sphere class lets you create and display spheres.
* <p/>
* The sphere is divided in vertical and horizontal segment, the smallest combination is two vertical and three horizontal segments.
*/
public class Sphere extends Mesh3D
{
/**
* Number of segments horizontally. Defaults to 8.
*/
public var segmentsW :Number;
/**
* Number of segments vertically. Defaults to 6.
*/
public var segmentsH :Number;
/**
* Default radius of Sphere if not defined.
*/
static public var DEFAULT_RADIUS :Number = 100;
/**
* Default scale of Sphere texture if not defined.
*/
static public var DEFAULT_SCALE :Number = 1;
/**
* Default value of gridX if not defined.
*/
static public var DEFAULT_SEGMENTSW :Number = 8;
/**
* Default value of gridY if not defined.
*/
static public var DEFAULT_SEGMENTSH :Number = 6;
/**
* Minimum value of gridX.
*/
static public var MIN_SEGMENTSW :Number = 3;
/**
* Minimum value of gridY.
*/
static public var MIN_SEGMENTSH :Number = 2;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Sphere object.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param radius [optional] - Desired radius.
* <p/>
* @param segmentsW [optional] - Number of segments horizontally. Defaults to 8.
* <p/>
* @param segmentsH [optional] - Number of segments vertically. Defaults to 6.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Sphere( material:MaterialObject3D=null, radius:Number=100, segmentsW:int=8, segmentsH:int=6, initObject:Object=null )
{
super( material, new Array(), new Array(), null, initObject );
this.segmentsW = Math.max( MIN_SEGMENTSW, segmentsW || DEFAULT_SEGMENTSW); // Defaults to 8
this.segmentsH = Math.max( MIN_SEGMENTSH, segmentsH || DEFAULT_SEGMENTSH); // Defaults to 6
if (radius==0) radius = DEFAULT_RADIUS; // Defaults to 100
var scale :Number = DEFAULT_SCALE;
buildSphere( radius );
}
private function buildSphere( fRadius:Number ):void
{
var i:Number, j:Number, k:Number;
var iHor:Number = Math.max(3,this.segmentsW);
var iVer:Number = Math.max(2,this.segmentsH);
var aVertice:Array = this.geometry.vertices;
var aFace:Array = this.geometry.faces;
var aVtc:Array = new Array();
for (j=0;j<(iVer+1);j++) { // vertical
var fRad1:Number = Number(j/iVer);
var fZ:Number = -fRadius*Math.cos(fRad1*Math.PI);
var fRds:Number = fRadius*Math.sin(fRad1*Math.PI);
var aRow:Array = new Array();
var oVtx:Vertex3D;
for (i=0;i<iHor;i++) { // horizontal
var fRad2:Number = Number(2*i/iHor);
var fX:Number = fRds*Math.sin(fRad2*Math.PI);
var fY:Number = fRds*Math.cos(fRad2*Math.PI);
if (!((j==0||j==iVer)&&i>0)) { // top||bottom = 1 vertex
oVtx = new Vertex3D(fY,fZ,fX);
aVertice.push(oVtx);
}
aRow.push(oVtx);
}
aVtc.push(aRow);
}
var iVerNum:int = aVtc.length;
for (j=0;j<iVerNum;j++) {
var iHorNum:int = aVtc[j].length;
if (j>0) { // &&i>=0
for (i=0;i<iHorNum;i++) {
// select vertices
var bEnd:Boolean = i==(iHorNum-0);
var aP1:Vertex3D = aVtc[j][bEnd?0:i];
var aP2:Vertex3D = aVtc[j][(i==0?iHorNum:i)-1];
var aP3:Vertex3D = aVtc[j-1][(i==0?iHorNum:i)-1];
var aP4:Vertex3D = aVtc[j-1][bEnd?0:i];
// uv
var fJ0:Number = j / iVerNum;
var fJ1:Number = (j-1) / iVerNum;
var fI0:Number = (i+1) / iHorNum;
var fI1:Number = i / iHorNum;
var aP4uv:NumberUV = new NumberUV(fI0,fJ1);
var aP1uv:NumberUV = new NumberUV(fI0,fJ0);
var aP2uv:NumberUV = new NumberUV(fI1,fJ0);
var aP3uv:NumberUV = new NumberUV(fI1,fJ1);
// 2 faces
if (j<(aVtc.length-1)) aFace.push( new Face3D(new Array(aP1,aP2,aP3), null, new Array(aP1uv,aP2uv,aP3uv)) );
if (j>1) aFace.push( new Face3D(new Array(aP1,aP3,aP4), null, new Array(aP1uv,aP3uv,aP4uv)) );
}
}
}
this.geometry.ready = true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Sphere.as | ActionScript | art | 6,855 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Cube
package org.papervision3d.objects
{
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Cube class lets you create and display flat rectangle objects.
* <p/>
* The rectangle can be divided in smaller segments. This is usually done to reduce linear mapping artifacts.
* <p/>
* Dividing the Cube in the direction of the perspective or vanishing point, helps to reduce this problem. Perspective distortion dissapears when the Cube is facing straignt to the camera, i.e. it is perpendicular with the vanishing point of the scene.
*/
public class Cube extends Mesh3D
{
/**
* Number of segments per axis. Defaults to 1.
*/
public var segments :Number3D;
/**
* No faces selected.
*/
static public var NONE :int = 0x00;
/**
* Front face selection
*/
static public var FRONT :int = 0x01;
/**
* Back face selection
*/
static public var BACK :int = 0x02;
/**
* Right face selection
*/
static public var RIGHT :int = 0x04;
/**
* Left face selection
*/
static public var LEFT :int = 0x08;
/**
* Top face selection
*/
static public var TOP :int = 0x10;
/**
* Bottom face selection
*/
static public var BOTTOM :int = 0x20;
/**
* All faces selected.
*/
static public var ALL :int = FRONT + BACK + RIGHT + LEFT + TOP + BOTTOM;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Cube object.
* <p/>
* @param materials A MaterialObject3D object that contains the material properties of the object.
*
* Supported materials are: front, back, right, left, top, bottom & all, for example:
*
* var materials:MaterialsList = new MaterialsList(
* {
* all: new MovieAssetMaterial( "Front", true ), // This is the default material
* front: new MovieAssetMaterial( "Front", true ),
* back: new MovieAssetMaterial( "Back", true ),
* right: new MovieAssetMaterial( "Right", true ),
* left: new MovieAssetMaterial( "Left", true ),
* top: new MovieAssetMaterial( "Top", true ),
* bottom: new MovieAssetMaterial( "Bottom", true )
* } );
*
* <p/>
* @param width [optional] - Desired width.
* <p/>
* @param depth [optional] - Desired depth.
* <p/>
* @param height [optional] - Desired height.
* <p/>
* @param segmentsS [optional] - Number of segments sagitally (plane perpendicular to width). Defaults to 1.
* <p/>
* @param segmentsT [optional] - Number of segments transversally (plane perpendicular to depth). Defaults to segmentsS.
* <p/>
* @param segmentsH [optional] - Number of segments horizontally (plane perpendicular to height). Defaults to segmentsS.
* <p/>
* @param insideFaces [optional] - Faces that are visible from the inside. Defaults to Cube.NONE.
*
* You can add or sustract faces to your selection. For examples: Cube.FRONT+Cube.BACK or Cube.ALL-Cube.Top.
*
* <p/>
* @param excludeFaces [optional] - Faces that will not be created. Defaults to Cube.NONE.
*
* You can add or sustract faces to your selection. For examples: Cube.FRONT+Cube.BACK or Cube.ALL-Cube.Top.
*
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Cube( materials:MaterialsList, width:Number=500, depth:Number=500, height:Number=500, segmentsS:int=1, segmentsT:int=1, segmentsH:int=1, insideFaces:int=0, excludeFaces:int=0, initObject:Object=null )
{
super( materials.getMaterialByName( "all" ), new Array(), new Array(), null, initObject );
this.materials = materials;
this.insideFaces = insideFaces;
this.excludeFaces = excludeFaces;
segments = new Number3D( segmentsS, segmentsT, segmentsH );
buildCube( width, height, depth );
}
private function buildCube( width:Number, height:Number, depth:Number ):void
{
var width2 :Number = width /2;
var height2 :Number = height /2;
var depth2 :Number = depth /2;
if( ! (excludeFaces & FRONT) )
buildPlane( "front", "x", "y", width, height, depth2, ! Boolean( insideFaces & FRONT ) );
if( ! (excludeFaces & BACK) )
buildPlane( "back", "x", "y", width, height, -depth2, Boolean( insideFaces & BACK ) );
if( ! (excludeFaces & RIGHT) )
buildPlane( "right", "z", "y", depth, height, width2, Boolean( insideFaces & RIGHT ) );
if( ! (excludeFaces & LEFT) )
buildPlane( "left", "z", "y", depth, height, -width2, ! Boolean( insideFaces & LEFT ) );
if( ! (excludeFaces & TOP) )
buildPlane( "top", "x", "z", width, depth, height2, Boolean( insideFaces & TOP ) );
if( ! (excludeFaces & BOTTOM) )
buildPlane( "bottom", "x", "z", width, depth, -height2, ! Boolean( insideFaces & BOTTOM ) );
mergeVertices();
this.geometry.ready = true;
}
private function buildPlane( mat:String, u:String, v:String, width:Number, height:Number, depth:Number, reverse:Boolean=false ):void
{
var matInstance:MaterialObject3D;
if( ! (matInstance= materials.getMaterialByName( mat )))
{
if(!(matInstance=materials.getMaterialByName( "all" ))){
Papervision3D.log( "Cube: Required material not found in given materials list. Supported materials are: front, back, right, left, top, bottom & all." );
return;
}
}
// Find w depth axis
var w :String;
if( (u=="x" && v=="y") || (u=="y" && v=="x") ) w = "z";
else if( (u=="x" && v=="z") || (u=="z" && v=="x") ) w = "y";
else if( (u=="z" && v=="y") || (u=="y" && v=="z") ) w = "x";
// Mirror
var rev :Number = reverse? -1 : 1;
// Build plane
var gridU :Number = this.segments[ u ];
var gridV :Number = this.segments[ v ];
var gridU1 :Number = gridU + 1;
var gridV1 :Number = gridV + 1;
var vertices :Array = this.geometry.vertices;
var faces :Array = this.geometry.faces;
var planeVerts :Array = new Array();
var textureU :Number = width /2;
var textureV :Number = height /2;
var incU :Number = width / gridU;
var incV :Number = height / gridV;
// Vertices
for( var iu:int = 0; iu < gridU1; iu++ )
{
for( var iv:int = 0; iv < gridV1; iv++ )
{
var vertex:Vertex3D = new Vertex3D();
vertex[ u ] = (iu * incU - textureU) * rev;
vertex[ v ] = iv * incV - textureV;
vertex[ w ] = depth;
vertices.push( vertex );
planeVerts.push( vertex );
}
}
// Faces
var uvA :NumberUV;
var uvC :NumberUV;
var uvB :NumberUV;
for( iu = 0; iu < gridU; iu++ )
{
for( iv= 0; iv < gridV; iv++ )
{
// Triangle A
var a:Vertex3D = planeVerts[ iu * gridV1 + iv ];
var c:Vertex3D = planeVerts[ iu * gridV1 + (iv+1) ];
var b:Vertex3D = planeVerts[ (iu+1) * gridV1 + iv ];
uvA = new NumberUV( iu / gridU, iv / gridV );
uvC = new NumberUV( iu / gridU, (iv+1) / gridV );
uvB = new NumberUV( (iu+1) / gridU, iv / gridV );
faces.push( new Face3D( [ a, b, c ], matInstance, [ uvA, uvB, uvC ] ) );
// Triangle B
a = planeVerts[ (iu+1) * gridV1 + (iv+1) ];
c = planeVerts[ (iu+1) * gridV1 + iv ];
b = planeVerts[ iu * gridV1 + (iv+1) ];
uvA = new NumberUV( (iu+1) / gridU, (iv+1) / gridV );
uvC = new NumberUV( (iu+1) / gridU, iv / gridV );
uvB = new NumberUV( iu / gridU, (iv+1) / gridV );
faces.push( new Face3D( [ a, b, c ], matInstance, [ uvA, uvB, uvC ] ) );
}
}
}
private var insideFaces :int;
private var excludeFaces :int
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Cube.as | ActionScript | art | 10,250 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Cube
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Cube class lets you create and display flat rectangle objects.
* <p/>
* The rectangle can be divided in smaller segments. This is usually done to reduce linear mapping artifacts.
* <p/>
* Dividing the Cube in the direction of the perspective or vanishing point, helps to reduce this problem. Perspective distortion dissapears when the Cube is facing straignt to the camera, i.e. it is perpendicular with the vanishing point of the scene.
*/
public class OldCube extends Mesh3D
{
/**
* Number of segments sagitally. Defaults to 1.
*/
public var segmentsS :Number;
/**
* Number of segments transversally. Defaults to 1.
*/
public var segmentsT :Number;
/**
* Number of segments horizontally. Defaults to 1.
*/
public var segmentsH :Number;
/**
* Default size of Cube if not texture is defined.
*/
static public var DEFAULT_SIZE :Number = 500;
/**
* Default size of Cube if not texture is defined.
*/
static public var DEFAULT_SCALE :Number = 1;
/**
* Default value of gridX if not defined. The default value of gridY is gridX.
*/
static public var DEFAULT_SEGMENTS :Number = 1;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Cube object.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param width [optional] - Desired width or scaling factor if there's bitmap texture in material and no height is supplied.
* <p/>
* @param depth [optional] - Desired depth.
* <p/>
* @param height [optional] - Desired height.
* <p/>
* @param segmentsS [optional] - Number of segments sagitally (plane perpendicular to width). Defaults to 1.
* <p/>
* @param segmentsT [optional] - Number of segments transversally (plane perpendicular to depth). Defaults to segmentsS.
* <p/>
* @param segmentsH [optional] - Number of segments horizontally (plane perpendicular to height). Defaults to segmentsS.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*
* This object has been deprecated in favour of the new Cube.
*/
public function OldCube( material:MaterialObject3D=null, width:Number=500, depth:Number=500, height:Number=500, segmentsS:Number=1, segmentsT:Number=1, segmentsH:Number=1, initObject:Object=null )
{
super( material, new Array(), new Array(), null, initObject );
this.segmentsS = segmentsS;//!=null?segmentsW:DEFAULT_SEGMENTS; // Defaults to 1
this.segmentsT = segmentsT;//!=null?segmentsH:this.segmentsW; // Defaults to segmentsW
this.segmentsH = segmentsH;//!=null?segmentsT:this.segmentsW; // Defaults to segmentsW
var scale :Number = DEFAULT_SCALE;
if( ! height ) {
if( width ) scale = width;
if( material && material.bitmap ) {
width = material.bitmap.width * scale;
height = material.bitmap.height * scale;
} else {
width = DEFAULT_SIZE * scale;
height = DEFAULT_SIZE * scale;
}
}
if( ! depth ) {
if( width ) scale = width;
//if( material && material.bitmap ) {
// width = material.bitmap.width * scale;
// depth = material.bitmap.depth * scale;
//} else {
width = DEFAULT_SIZE * scale;
depth = DEFAULT_SIZE * scale;
//}
}
buildCube( width, height, depth );
}
private function buildCube( fWidth:Number, fHeight:Number, fDepth:Number ):void {
var i:Number;
var j:Number;
var k:Number;
var iSag:Number = Math.max(1,this.segmentsS); // sagittal
var iTrv:Number = Math.max(1,this.segmentsT); // transversal
var iHor:Number = Math.max(1,this.segmentsH); // horizontal
var aVertice :Array = this.geometry.vertices;
var aFace :Array = this.geometry.faces;
// vertices
var aTopBottom:Array = new Array(new Array(),new Array());
var aVtc:Array = new Array();
var fZ:Number, fX:Number, fY:Number, oVtx:Vertex3D, iJsbs:int, aPlane:Array;
for (i=0;i<(iHor+1);i++) {
fZ = -fHeight/2 + fHeight*(i/iHor);
var aLyr:Array = new Array();
var iJ:int, iJrel:int;
for (j=0;j<2*(iTrv+iSag);j++) {
if (j<iSag) { // side 1
fX = -fWidth/2 + j*(fWidth/iSag);
fY = -fDepth/2;
} else if (j<(iTrv+iSag)) { // side 2
iJ = j-iSag; //
fX = fWidth/2;
fY = -fDepth/2 + iJ*(fDepth/iTrv);
} else if (j<(iTrv+2*iSag)) { // side 3
iJ = j-iTrv-iSag;
fX = fWidth/2 - iJ*(fWidth/iSag);
fY = fDepth/2;
} else { // side 4
iJ = j-iTrv-2*iSag; //
fX = -fWidth/2;
fY = fDepth/2 - iJ*(fDepth/iTrv);
}
oVtx = new Vertex3D( fY, fZ, fX );
aLyr.push(oVtx);
aVertice.push(oVtx);
// if top or bottom
if (i==0||i==iHor) {
var iTopBot:int = i==0?0:1;
if (j<iSag) { // side 1
aTopBottom[iTopBot][j] = oVtx; // "top"+j; //
} else if (j<(iTrv+iSag)) { // side 2
iJ = j-iSag;
iJrel = iSag + (iSag+1)*iJ;
aTopBottom[iTopBot][iJrel] = oVtx; // "right"+iJ; //
} else if (j<(iTrv+2*iSag)) { // side 3
iJ = j-iTrv-iSag;
iJrel = (iSag+1)*(iTrv) + 1 + (iSag-1) - iJ;
aTopBottom[iTopBot][iJrel] = oVtx; // "bot"+iJ; //
} else { // side 4
iJ = j-iTrv-2*iSag;
iJrel = (iSag+1)*(iTrv-iJ);
aTopBottom[iTopBot][iJrel] = oVtx; // "left"+iJ; //
}
}
}
aVtc.push(aLyr);
}
// top and bottom
var iTBnum:int = (iTrv+1)*(iSag+1) - 2*iTrv - 2*iSag;
for (i=0;i<2;i++) {
aPlane = new Array();
fZ = (i==0?1:-1)*fHeight/2;
for (j=0;j<iTBnum;j++) {
var iXps:int = j%(iSag-1);
var iYps:int = Math.floor(j/(iSag-1));
fX = -fWidth/2 + (iXps+1)*(fWidth/iSag);
fY = -fDepth/2 + (iYps+1)*(fDepth/iTrv);
oVtx = new Vertex3D( fY, fZ, fX );
aVertice.push(oVtx);
aTopBottom[1-i][(iSag+1)*(iYps+1)+(iXps+1)] = oVtx;
}
}
//
// faces
var aP1:Vertex3D, aP2:Vertex3D, aP3:Vertex3D, aP4:Vertex3D;
var aP4uv:NumberUV, aP1uv:NumberUV, aP2uv:NumberUV, aP3uv:NumberUV;
var iVerNum:int = aVtc.length;
for (i=0;i<iVerNum;i++) {
var iHorNum:int = aVtc[i].length;
if (i>0) {
for (j=0;j<iHorNum;j++) {
// select vertices
aP1 = aVtc[i][j];
aP2 = aVtc[i][(j==0?iHorNum:j)-1];
aP3 = aVtc[i-1][(j==0?iHorNum:j)-1];
aP4 = aVtc[i-1][j];
// uv
var iTrSg:int; // transversal or sagital
var jj:Number = (j-1+iHorNum)%iHorNum;
if (jj<iSag) { // side 1
iJsbs = jj;
iTrSg = iSag;
} else if (jj<(iTrv+iSag)) { // side 2
iJsbs = jj-iSag;
iTrSg = iTrv;
} else if (jj<(iTrv+2*iSag)) { // side 3
iJsbs = jj-iTrv-iSag;
iTrSg = iSag;
} else { // side 4
iJsbs = jj-iTrv-2*iSag;
iTrSg = iTrv;
}
var fI0:Number = (i-1)/(iVerNum-1);
var fI1:Number = (i+0)/(iVerNum-1);
var fJ0:Number = (1-(iJsbs+1)*(1/iTrSg));
var fJ1:Number = (1-(iJsbs+0)*(1/iTrSg));
aP4uv = new NumberUV(fJ0,fI0);
aP1uv = new NumberUV(fJ0,fI1);
aP2uv = new NumberUV(fJ1,fI1);
aP3uv = new NumberUV(fJ1,fI0);
// 2 faces
aFace.push( new Face3D(new Array(aP1,aP3,aP2), null, new Array(aP1uv,aP3uv,aP2uv)) );
aFace.push( new Face3D(new Array(aP1,aP4,aP3), null, new Array(aP1uv,aP4uv,aP3uv)) );
}
}
}
// top and bottom
for (i=0;i<aTopBottom.length;i++) {
aPlane = new Array();
var aLine:Array = new Array();
// poor into double array for easier use
for (j=0;j<aTopBottom[i].length;j++) {
aLine.push(aTopBottom[i][j]);
if (j%(iSag+1)==iSag) {
aPlane.push(aLine.slice(0));
aLine = new Array();
}
}
for (j=1;j<aPlane.length;j++) {
for (k=1;k<aPlane[j].length;k++) {
// select vertices
aP1 = aPlane[j][k];
aP2 = aPlane[j][k-1];
aP3 = aPlane[j-1][k-1];
aP4 = aPlane[j-1][k];
// 2 faces
var bTop:Boolean = i==0;
// uv
aP1uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*((j+0)/iTrv) ,(k+0)/iSag );
aP2uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*((j+0)/iTrv) ,(k-1)/iSag );
aP3uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*((j-1)/iTrv) ,(k-1)/iSag );
aP4uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*((j-1)/iTrv) ,(k+0)/iSag );
if (i==0) {
aFace.push( new Face3D(new Array(aP1,aP2,aP3), null, new Array(aP1uv,aP2uv,aP3uv)) );
aFace.push( new Face3D(new Array(aP1,aP3,aP4), null, new Array(aP1uv,aP3uv,aP4uv)) );
} else {
aFace.push( new Face3D(new Array(aP1,aP3,aP2), null, new Array(aP1uv,aP3uv,aP2uv)) );
aFace.push( new Face3D(new Array(aP1,aP4,aP3), null, new Array(aP1uv,aP4uv,aP3uv)) );
}
}
}
}
this.geometry.ready = true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/OldCube.as | ActionScript | art | 11,502 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ DisplayObject3D
package org.papervision3d.objects
{
import com.blitzagency.xray.logger.XrayLog;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.geom.Face3DInstance;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.proto.DisplayObjectContainer3D;
import org.papervision3d.core.proto.GeometryObject3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.materials.MaterialsList;
import org.papervision3d.scenes.InteractiveScene3D;
import org.papervision3d.utils.InteractiveSceneManager;
import org.papervision3d.utils.InteractiveSprite;
/**
* The DisplayObject class represents instances of 3D objects that are contained in the scene.
* <p/>
* That includes all objects in the scene, not only those that can be rendered, but also the camera and its target.
* <p/>
* The DisplayObject3D class supports basic functionality like the x, y and z position of an object, as well as rotationX, rotationY, rotationZ, scaleX, scaleY and scaleZ and visible. It also supports more advanced properties of the object such as its transform Matrix3D.
* <p/>
* <p/>
* DisplayObject3D is not an abstract base class; therefore, you can call DisplayObject3D directly. Invoking new DisplayObject() creates a new empty object in 3D space, like when you used createEmptyMovieClip().
*
*/
public class DisplayObject3D extends DisplayObjectContainer3D
{
// ___________________________________________________________________ P O S I T I O N
/**
* An Number that sets the X coordinate of a object relative to the origin of its parent.
*/
public function get x():Number
{
return this.transform.n14;
}
public function set x( value:Number ):void
{
this.transform.n14 = value;
}
/**
* An Number that sets the Y coordinate of a object relative to the origin of its parent.
*/
public function get y():Number
{
return this.transform.n24;
}
public function set y( value:Number ):void
{
this.transform.n24 = value;
}
/**
* An Number that sets the Z coordinate of a object relative to the origin of its parent.
*/
public function get z():Number
{
return this.transform.n34;
}
public function set z( value:Number ):void
{
this.transform.n34 = value;
}
// ___________________________________________________________________ R O T A T I O N
/**
* Specifies the rotation around the X axis from its original orientation.
*/
public function get rotationX():Number
{
if( this._rotationDirty ) updateRotation();
return Papervision3D.useDEGREES? -this._rotationX * toDEGREES : -this._rotationX;
}
public function set rotationX( rot:Number ):void
{
this._rotationX = Papervision3D.useDEGREES? -rot * toRADIANS : -rot;
this._transformDirty = true;
}
/**
* Specifies the rotation around the Y axis from its original orientation.
*/
public function get rotationY():Number
{
if( this._rotationDirty ) updateRotation();
return Papervision3D.useDEGREES? -this._rotationY * toDEGREES : -this._rotationY;
}
public function set rotationY( rot:Number ):void
{
this._rotationY = Papervision3D.useDEGREES? -rot * toRADIANS : -rot;
this._transformDirty = true;
}
/**
* Specifies the rotation around the Z axis from its original orientation.
*/
public function get rotationZ():Number
{
if( this._rotationDirty ) updateRotation();
return Papervision3D.useDEGREES? -this._rotationZ * toDEGREES : -this._rotationZ;
}
public function set rotationZ( rot:Number ):void
{
this._rotationZ = Papervision3D.useDEGREES? -rot * toRADIANS : -rot;
this._transformDirty = true;
}
// Update rotation values
private function updateRotation():void
{
var rot:Number3D = Matrix3D.matrix2euler( this.transform );
this._rotationX = rot.x * toRADIANS;
this._rotationY = rot.y * toRADIANS;
this._rotationZ = rot.z * toRADIANS;
this._rotationDirty = false;
}
// ___________________________________________________________________ S C A L E
/**
* Sets the 3D scale as applied from the registration point of the object.
*/
public function get scale():Number
{
if( this._scaleX == this._scaleY && this._scaleX == this._scaleZ )
if( Papervision3D.usePERCENT ) return this._scaleX * 100;
else return this._scaleX;
else return NaN;
}
public function set scale( scale:Number ):void
{
if( Papervision3D.usePERCENT ) scale /= 100;
this._scaleX = this._scaleY = this._scaleZ = scale;
this._transformDirty = true;
}
/**
* Sets the scale along the local X axis as applied from the registration point of the object.
*/
public function get scaleX():Number
{
if( Papervision3D.usePERCENT ) return this._scaleX * 100;
else return this._scaleX;
}
public function set scaleX( scale:Number ):void
{
if( Papervision3D.usePERCENT ) this._scaleX = scale / 100;
else this._scaleX = scale;
this._transformDirty = true;
}
/**
* Sets the scale along the local Y axis as applied from the registration point of the object.
*/
public function get scaleY():Number
{
if( Papervision3D.usePERCENT ) return this._scaleY * 100;
else return this._scaleY;
}
public function set scaleY( scale:Number ):void
{
if( Papervision3D.usePERCENT ) this._scaleY = scale / 100;
else this._scaleY = scale;
this._transformDirty = true;
}
/**
* Sets the scale along the local Z axis as applied from the registration point of the object.
*/
public function get scaleZ():Number
{
if( Papervision3D.usePERCENT ) return this._scaleZ * 100;
else return this._scaleZ;
}
public function set scaleZ( scale:Number ):void
{
if( Papervision3D.usePERCENT ) this._scaleZ = scale / 100;
else this._scaleZ = scale;
this._transformDirty = true;
}
// ___________________________________________________________________ W O R L D
/**
* The X coordinate of a object relative to the scene coordinate system.
*/
public function get sceneX():Number
{
return this.world.n14;
}
/**
* The Y coordinate of a object relative to the scene coordinate system.
*/
public function get sceneY():Number
{
return this.world.n24;
}
/**
* The Z coordinate of a object relative to the scene coordinate system.
*/
public function get sceneZ():Number
{
return this.world.n34;
}
// ___________________________________________________________________ S C R E E N
/**
* [read-only] The coordinate of the object on screen.
*/
public var screen :Number3D = new Number3D();
// ___________________________________________________________________ P R O P E R T I E S
/**
* Whether or not the display object is visible.
* <p/>
* A Boolean value that indicates whether the object is projected, transformed and rendered. A value of false will effectively ignore the object. The default value is true.
*/
public var visible :Boolean;
/**
* An optional object name.
*/
public var name :String;
/**
* [read-only] Unique id of this instance.
*/
public var id :int;
/**
* An object that contains user defined properties.
* <p/>
* All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public var extra :Object // = {}; TBD
/**
* The Sprite that you draw into when rendering in a MovieScene3D.
*
* While Scene3D uses a single Sprite container for all the objects, MovieScene3D renders each object in its own unique Sprite.
*
* You can use the container like any other Sprite. For example, you can add events to it, apply filters or change the blend mode.
*/
public var container :Sprite;
/**
* The default material for the object instance. Materials collect data about how objects appear when rendered.
*/
public var material :MaterialObject3D;
/**
* The list of materials for this instance.
*/
public var materials :MaterialsList;
/**
* If an InteractiveScene3D is used, this will DisplayObject3D will be registered with the InteractiveSceneManager
*/
public var interactiveSceneManager:InteractiveSceneManager;
/**
* The scene where the object belongs.
*/
protected var _scene :SceneObject3D = null;
public function set scene(p_scene:SceneObject3D):void
{
// set scene property
_scene = p_scene;
for each( var child:DisplayObject3D in this._childrenByName )
{
if(child.scene == null) child.scene = _scene;
}
// if this is NOT an interactiveScene3D, just return
if(_scene is InteractiveScene3D == false) return;
// if we have an InteractiveScene3D, register this and the children to add them to the InteractiveSceneManager
interactiveSceneManager = InteractiveScene3D(_scene).interactiveSceneManager;
}
public function get scene():SceneObject3D { return _scene; }
/**
* [read-only] Indicates the DisplayObjectContainer3D object that contains this display object.
*/
public var parent :DisplayObjectContainer3D;
/**
* tells Mesh3D's render() method to sort by measuring from the center of a triangle
*/
public static const MESH_SORT_CENTER:uint = 1;
/**
* tells Mesh3D's render() method to sort by measuring from the farthest point of a triangle
*/
public static const MESH_SORT_FAR:uint = 2;
/**
* tells Mesh3D's render() method to sort by measuring from the closest point of a triangle
*/
public static const MESH_SORT_CLOSE:uint = 3;
/**
* tells Mesh3D's render() method to compare the measurement choice of the user for a triangle's sorting
*/
public var meshSort:uint = MESH_SORT_CENTER;
/**
* Returns an empty DiplayObject3D object positioned in the center of the 3D coordinate system (0, 0 ,0).
*/
static public function get ZERO():DisplayObject3D
{
return new DisplayObject3D();
}
/**
* Relative directions.
*/
static private var FORWARD :Number3D = new Number3D( 0, 0, 1 );
static private var BACKWARD :Number3D = new Number3D( 0, 0, -1 );
static private var LEFT :Number3D = new Number3D( -1, 0, 0 );
static private var RIGHT :Number3D = new Number3D( 1, 0, 0 );
static private var UP :Number3D = new Number3D( 0, 1, 0 );
static private var DOWN :Number3D = new Number3D( 0, -1, 0 );
/**
* A Matrix3D object containing values that affect the scaling, rotation, and translation of the display object.
*/
public var transform :Matrix3D;
/**
* [internal-use] A camera transformed Matrix3D object.
*/
public var view :Matrix3D;
/**
* World transformation.
*/
public var world :Matrix3D;
/**
* [internal-use]
*/
public var faces :Array = new Array();
/**
* This allows objects faces to have their own containers.
*/
public static var faceLevelMode :Boolean;
/**
* The GeometryObject3D object that contains the 3D definition of this instance.
* <p/>
* When different objects share the same geometry, they become instances. They are the same object, displayed multiple times. Changing the shape of this object changes the shape of all of its instances.
* <p/>
* Instancing an object saves system memory, and is useful to display an object multiple times while maintaining its shape.
* <p/>
* For example, you could create armies and forests full of duplicate objects without needing the memory to handle that much actual geometry. Each instance has its own transform node so it can have its own position, rotation, and scaling.
*/
public var geometry :GeometryObject3D;
/**
* [internal-use] The average depth of the object faces center. Used internally for z-sorting.
*/
public var screenZ :Number;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new DisplayObject3D instance. After creating the instance, call the addChild() method of a DisplayObjectContainer3D.
*
* @param name [optional] - The name of the newly created object.
* @param geometry [optional] - The geometry of the newly created object.
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created DisplayObject3D.
*
* <ul>
* <li><b>x</b></b>: An Number that sets the X coordinate of a object relative to the scene coordinate system.</li>
* <p/>
* <li><b>y</b>: An Number that sets the Y coordinate of a object relative to the scene coordinate system.</li>
* <p/>
* <li><b>z</b>: An Number that sets the Z coordinate of a object relative to the scene coordinate system.</li>
* <p/>
* <li><b>rotationX</b>: Specifies the rotation around the X axis from its original orientation.</li>
* <p/>
* <li><b>rotationY</b>: Specifies the rotation around the Y axis from its original orientation.</li>
* <p/>
* <li><b>rotationZ</b>: Specifies the rotation around the Z axis from its original orientation.</li>
* <p/>
* <li><b>scaleX</b>: Sets the scale along the local X axis as applied from the registration point of the object.</li>
* <p/>
* <li><b>scaleY</b>: Sets the scale along the local Y axis as applied from the registration point of the object.</li>
* <p/>
* <li><b>scaleZ</b>: Sets the scale along the local Z axis as applied from the registration point of the object.</li>
* <p/>
* <li><b>visible</b>: Whether or not the display object is visible.
* <p/>
* A Boolean value that indicates whether the object is projected, transformed and rendered. A value of false will effectively ignore the object. The default value is true.</li>
* <p/>
* <li><b>container</b>: The MovieClip that you draw into when rendering. Use only when the object is rendered in its own unique MovieClip.
* <p/>
* It's Boolean value determines whether the container MovieClip should be cleared before rendering.</li>
* <p/>
* <li><b>extra</b>: An object that contains user defined properties.
* <p/>
* All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.</li>
* </ul>
*/
public function DisplayObject3D( name:String=null, geometry:GeometryObject3D=null, initObject:Object=null ):void
{
super();
Papervision3D.log( "DisplayObject3D: " + name );
this.transform = Matrix3D.IDENTITY;
this.world = Matrix3D.IDENTITY;
this.view = Matrix3D.IDENTITY;
// TODO if( initObject )...
this.x = initObject? initObject.x || 0 : 0;
this.y = initObject? initObject.y || 0 : 0;
this.z = initObject? initObject.z || 0 : 0;
rotationX = initObject? initObject.rotationX || 0 : 0;
rotationY = initObject? initObject.rotationY || 0 : 0;
rotationZ = initObject? initObject.rotationZ || 0 : 0;
var scaleDefault:Number = Papervision3D.usePERCENT? 100 : 1;
scaleX = initObject? initObject.scaleX || scaleDefault : scaleDefault;
scaleY = initObject? initObject.scaleY || scaleDefault : scaleDefault;
scaleZ = initObject? initObject.scaleZ || scaleDefault : scaleDefault;
if( initObject && initObject.extra ) this.extra = initObject.extra;
if( initObject && initObject.container ) this.container = initObject.container;
this.visible = true;
this.id = _totalDisplayObjects++;
this.name = name || String( this.id );
if( geometry ) addGeometry( geometry );
}
// ___________________________________________________________________________________________________
// U T I L S
/**
* Adds a child DisplayObject3D instance to this DisplayObjectContainer instance.
*
* [TODO: If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.]
*
* @param child The DisplayObject3D instance to add as a child of this DisplayObjectContainer3D instance.
* @param name An optional name of the child to add or create. If no name is provided, the child name will be used.
* @return The DisplayObject3D instance that you have added or created.
*/
public override function addChild( child :DisplayObject3D, name:String=null ):DisplayObject3D
{
child = super.addChild( child, name );
if( child.scene == null ) child.scene = scene;
return child;
}
/**
* Adds a geometry definition to the instance.
*
* A geometry describes the visual shape and appearance of an object in a scene.
*
* @param geometry A geometry definition.
*/
public function addGeometry( geometry:GeometryObject3D=null ):void
{
if( geometry )
this.geometry = geometry;
/*
if( geometry.material )
this.material = geometry.material.clone();
if( geometry.materials )
this.materials = geometry.materials.clone();
*/
}
// ___________________________________________________________________________________________________
// C O L L I S I O N
/**
* Gets the distance to the position of the given object.
*
* @param obj The display object to measure the distance to.
* @return The distance to the registration point of the given object.
*/
public function distanceTo( obj:DisplayObject3D ):Number
{
var x :Number = this.x - obj.x;
var y :Number = this.y - obj.y;
var z :Number = this.z - obj.z;
return Math.sqrt( x*x + y*y + z*z );
}
/**
* Evaluates the display object to see if it overlaps or intersects with the point specified by the x, y and z parameters.
* <p/>
* The x, y and z parameters specify a point in the coordinate space of the instance parent object, not the scene (unless that parent object is the scene).
*
* @param x The x coordinate to test against this object.
* @param y The y coordinate to test against this object.
* @param z The z coordinate to test against this object.
* @return true if the display object overlaps or intersects with the specified point; false otherwise.
*/
public function hitTestPoint( x:Number, y:Number, z:Number ):Boolean
{
var dx :Number = this.x - x;
var dy :Number = this.y - y;
var dz :Number = this.z - z;
var d2 :Number = x*x + y*y + z*z;
var sA :Number = this.geometry? this.geometry.boundingSphere2 : 0;
return sA > d2;
}
/**
* Evaluates the display object to see if it overlaps or intersects with the obj display object.
*
* @param obj The display object to test against.
* @return true if the display objects intersect; false if not.
*/
// TODO: Use group boundingSphere
public function hitTestObject( obj:DisplayObject3D, multiplier:Number=1 ):Boolean
{
var dx :Number = this.x - obj.x;
var dy :Number = this.y - obj.y;
var dz :Number = this.z - obj.z;
var d2 :Number = dx*dx + dy*dy + dz*dz;
var sA :Number = this.geometry? this.geometry.boundingSphere2 : 0;
var sB :Number = obj.geometry? obj.geometry.boundingSphere2 : 0;
sA = sA * multiplier;
return sA + sB > d2;
}
// ___________________________________________________________________________________________________
// M A T E R I A L S
/**
* Returns the material that exists with the specified name in the materials list.
* </p>
* If more that one material object has the specified name, the method returns the first material object in the materials list.
* </p>
* @param name The name of the material to return.
* @return The material object with the specified name.
*/
// TODO: Recursive
public function getMaterialByName( name:String ):MaterialObject3D
{
var material:MaterialObject3D = this.materials.getMaterialByName( name );
if( material )
return material;
else
for each( var child :DisplayObject3D in this._childrenByName )
{
material = child.getMaterialByName( name );
if( material ) return material;
}
return null;
}
/**
* Returns a string value with the list of material names of the materials list.
*
* @return A string.
*/
// TODO: Recursive
public function materialsList():String
{
var list:String = "";
for( var name:String in this.materials )
list += name + "\n";
for each( var child :DisplayObject3D in this._childrenByName )
{
for( name in child.materials.materialsByName )
list += "+ " + name + "\n";
}
return list;
}
// ___________________________________________________________________________________________________
// P R O J E C T
// PPPPP RRRRR OOOO JJ EEEEEE CCCC TTTTTT
// PP PP RR RR OO OO JJ EE CC CC TT
// PPPPP RRRRR OO OO JJ EEEE CC TT
// PP RR RR OO OO JJ JJ EE CC CC TT
// PP RR RR OOOO JJJJ EEEEEE CCCC TT
/**
* [internal-use] Projects three dimensional coordinates onto a two dimensional plane to simulate the relationship of the camera to subject.
* <p/>
* This is the first step in the process of representing three dimensional shapes two dimensionally.
*
* @param parent The DisplayObject3D object that contains this display object.
* @param camera Camera3D object to render from.
* @param sorted The list of faces of the current sort branch.
*/
public function project( parent :DisplayObject3D, camera :CameraObject3D, sorted :Array=null ):Number
{
if( this._transformDirty ) updateTransform();
this.view.calculateMultiply( parent.view, this.transform );
this.world.calculateMultiply( parent.world, this.transform );
calculateScreenCoords( camera );
var screenZs :Number = 0;
var children :Number = 0;
if( ! sorted ) this._sorted = sorted = new Array();
for each( var child:DisplayObject3D in this._childrenByName )
{
if( child.visible )
{
screenZs += child.project( this, camera, sorted );
children++;
}
}
return this.screenZ = screenZs / children;
}
private function calculateScreenCoords( camera :CameraObject3D ):void
{
var persp:Number = (camera.focus * camera.zoom) / (camera.focus + view.n34);
screen.x = view.n14 * persp;
screen.y = view.n24 * persp;
screen.z = view.n34;
}
// ___________________________________________________________________________________________________
// R E N D E R
// RRRRR EEEEEE NN NN DDDDD EEEEEE RRRRR
// RR RR EE NNN NN DD DD EE RR RR
// RRRRR EEEE NNNNNN DD DD EEEE RRRRR
// RR RR EE NN NNN DD DD EE RR RR
// RR RR EEEEEE NN NN DDDDD EEEEEE RR RR
/**
* [internal-use] Render the projected object.
*
* @param scene The scene where the object belongs.
*/
public function render( scene :SceneObject3D ):void
{
var iFaces :Array = this._sorted;
iFaces.sortOn( 'screenZ', Array.DESCENDING | Array.NUMERIC );
// Render
var container :Sprite = this.container || scene.container,
rendered :Number = 0,
iFace :Face3DInstance,
length :Number = iFaces.length,
i :int = 0;
//for( var i:int = 0; iFace = iFaces[i]; i++ )
//for( var i:int = 0; i < length ; i++ )
while(i < length)
{
iFace = iFaces[i];
if( faceLevelMode )
{
if( !iFace.container )
{
iFace.container = new InteractiveSprite(this);
scene.container.addChild(iFace.container);
}
else
{
iFace.container.graphics.clear();
}
if( iFace.visible )
rendered += iFace.face.render( iFace.instance, iFace.container)
}else
{
// if we're not in faceLevelMode, then it's render as usual - no extra checks in the render loop
if( iFace.visible )
rendered += iFace.face.render( iFace.instance, container );
}
i++;
}
// Update stats
scene.stats.rendered += rendered;
}
// ___________________________________________________________________________________________________
// L O C A L T R A N S F O R M S
// LL OOOO CCCC AA LL
// LL OO OO CC CC AAAA LL
// LL OO OO CC AA AA LL
// LL OO OO CC CC AAAAAA LL
// LLLLLL OOOO CCCC AA AA LLLLLL
/**
* Translate the display object in the direction it is facing, i.e. it's positive Z axis.
*
* @param distance The distance that the object should move forward.
*/
public function moveForward ( distance:Number ):void { translate( distance, FORWARD ); }
/**
* Translate the display object in the opposite direction it is facing, i.e. it's negative Z axis.
*
* @param distance The distance that the object should move backward.
*/
public function moveBackward ( distance:Number ):void { translate( distance, BACKWARD ); }
/**
* Translate the display object lateraly, to the left of the direction it is facing, i.e. it's negative X axis.
*
* @param distance The distance that the object should move left.
*/
public function moveLeft ( distance:Number ):void { translate( distance, LEFT ); }
/**
* Translate the display object lateraly, to the right of the direction it is facing, i.e. it's positive X axis.
*
* @param distance The distance that the object should move right.
*/
public function moveRight ( distance:Number ):void { translate( distance, RIGHT ); }
/**
* Translate the display object upwards, with respect to the direction it is facing, i.e. it's positive Y axis.
*
* @param distance The distance that the object should move up.
*/
public function moveUp ( distance:Number ):void { translate( distance, UP ); }
/**
* Translate the display object downwards, with respect to the direction it is facing, i.e. it's negative Y axis.
*
* @param distance The distance that the object should move down.
*/
public function moveDown ( distance:Number ):void { translate( distance, DOWN ); }
// ___________________________________________________________________________________________________
// L O C A L T R A N S L A T I O N
/**
* Move the object along a given direction.
*
* @param distance The distance that the object should travel.
* @param axis The direction that the object should move towards.
*/
public function translate( distance:Number, axis:Number3D ):void
{
var vector:Number3D = axis.clone();
if( this._transformDirty ) updateTransform();
Matrix3D.rotateAxis( transform, vector )
this.x += distance * vector.x;
this.y += distance * vector.y;
this.z += distance * vector.z;
}
// ___________________________________________________________________________________________________
// L O C A L R O T A T I O N
/**
* Rotate the display object around its lateral or transverse axis —an axis running from the pilot's left to right in piloted aircraft, and parallel to the wings of a winged aircraft; thus the nose pitches up and the tail down, or vice-versa.
*
* @param angle The angle to rotate.
*/
public function pitch( angle:Number ):void
{
angle = Papervision3D.useDEGREES? angle * toRADIANS : angle;
var vector:Number3D = RIGHT.clone();
if( this._transformDirty ) updateTransform();
Matrix3D.rotateAxis( transform, vector );
var m:Matrix3D = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle );
// this.transform.copy3x3( Matrix3D.multiply3x3( m ,transform ) );
this.transform.calculateMultiply3x3( m ,transform );
this._rotationDirty = true;
}
/**
* Rotate the display object around about the vertical axis —an axis drawn from top to bottom.
*
* @param angle The angle to rotate.
*/
public function yaw( angle:Number ):void
{
angle = Papervision3D.useDEGREES? angle * toRADIANS : angle;
var vector:Number3D = UP.clone();
if( this._transformDirty ) updateTransform();
Matrix3D.rotateAxis( transform, vector );
var m:Matrix3D = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle );
this.transform.calculateMultiply3x3( m ,transform );
this._rotationDirty = true;
}
/**
* Rotate the display object around the longitudinal axis —an axis drawn through the body of the vehicle from tail to nose in the normal direction of flight, or the direction the object is facing.
*
* @param angle
*/
public function roll( angle:Number ):void
{
angle = Papervision3D.useDEGREES? angle * toRADIANS : angle;
var vector:Number3D = FORWARD.clone();
if( this._transformDirty ) updateTransform();
Matrix3D.rotateAxis( transform, vector );
var m:Matrix3D = Matrix3D.rotationMatrix( vector.x, vector.y, vector.z, angle );
this.transform.calculateMultiply3x3( m ,transform );
this._rotationDirty = true;
}
/**
* Make the object look at a specific position.
*
* @param targetObject Object to look at.
* @param upAxis The vertical axis of the universe. Normally the positive Y axis.
*/
public function lookAt( targetObject:DisplayObject3D, upAxis:Number3D=null ):void
{
var position :Number3D = new Number3D( this.x, this.y, this.z );
var target :Number3D = new Number3D( targetObject.x, targetObject.y, targetObject.z );
var zAxis :Number3D = Number3D.sub( target, position );
zAxis.normalize();
if( zAxis.modulo > 0.1 )
{
var xAxis :Number3D = Number3D.cross( zAxis, upAxis || UP );
xAxis.normalize();
var yAxis :Number3D = Number3D.cross( zAxis, xAxis );
yAxis.normalize();
var look :Matrix3D = this.transform;
/*
look.n11 = xAxis.x;
look.n21 = xAxis.y;
look.n31 = xAxis.z;
look.n12 = -yAxis.x;
look.n22 = -yAxis.y;
look.n32 = -yAxis.z;
look.n13 = zAxis.x;
look.n23 = zAxis.y;
look.n33 = zAxis.z;
*/
// scale fix for lookAt()
look.n11 = xAxis.x * _scaleX;
look.n21 = xAxis.y * _scaleX;
look.n31 = xAxis.z * _scaleX;
look.n12 = -yAxis.x * _scaleY;
look.n22 = -yAxis.y * _scaleY;
look.n32 = -yAxis.z * _scaleY;
look.n13 = zAxis.x * _scaleZ;
look.n23 = zAxis.y * _scaleZ;
look.n33 = zAxis.z * _scaleZ;
this._transformDirty = false;
this._rotationDirty = true;
// TODO: Implement scale
}
else
{
var log:XrayLog = new XrayLog();
log.debug( "lookAt Error" );
}
}
// ___________________________________________________________________________________________________
// T R A N S F O R M
// TTTTTT RRRRR AA NN NN SSSSS FFFFFF OOOO RRRRR MM MM
// TT RR RR AAAA NNN NN SS FF OO OO RR RR MMM MMM
// TT RRRRR AA AA NNNNNN SSSS FFFF OO OO RRRRR MMMMMMM
// TT RR RR AAAAAA NN NNN SS FF OO OO RR RR MM M MM
// TT RR RR AA AA NN NN SSSSS FF OOOO RR RR MM MM
/**
* Copies the position information (x, y and z coordinates) from another object or Matrix3D.
*
* @param reference A DisplayObject3D or Matrix3D object to copy the position from.
*/
public function copyPosition( reference:* ):void
{
var trans :Matrix3D = this.transform;
var matrix :Matrix3D = (reference is DisplayObject3D)? reference.transform : reference;
trans.n14 = matrix.n14;
trans.n24 = matrix.n24;
trans.n34 = matrix.n34;
}
/**
* Copies the transformation information (position, rotation and scale) from another object or Matrix3D.
*
* @param reference A DisplayObject3D or Matrix3D object to copy the position from.
*/
public function copyTransform( reference:* ):void
{
var trans :Matrix3D = this.transform;
var matrix :Matrix3D = (reference is DisplayObject3D)? reference.transform : reference;
trans.n11 = matrix.n11; trans.n12 = matrix.n12;
trans.n13 = matrix.n13; trans.n14 = matrix.n14;
trans.n21 = matrix.n21; trans.n22 = matrix.n22;
trans.n23 = matrix.n23; trans.n24 = matrix.n24;
trans.n31 = matrix.n31; trans.n32 = matrix.n32;
trans.n33 = matrix.n33; trans.n34 = matrix.n34;
this._transformDirty = false;
this._rotationDirty = true;
}
/**
* [internal-use] Updates the transform Matrix3D with the current rotation and scale values.
*/
// TODO OPTIMIZE (HIGH)
protected function updateTransform():void
{
var q:Object = Matrix3D.euler2quaternion( -this._rotationY, -this._rotationZ, this._rotationX ); // Swapped
var m:Matrix3D = Matrix3D.quaternion2matrix( q.x, q.y, q.z, q.w );
var transform:Matrix3D = this.transform;
m.n14 = transform.n14;
m.n24 = transform.n24;
m.n34 = transform.n34;
transform.copy( m );
// Scale
var scaleM:Matrix3D = Matrix3D.IDENTITY;
scaleM.n11 = this._scaleX;
scaleM.n22 = this._scaleY;
scaleM.n33 = this._scaleZ;
this.transform.calculateMultiply( transform, scaleM );
this._transformDirty = false;
}
// ___________________________________________________________________________________________________
/**
* Returns a string value representing the three-dimensional position values of the display object instance.
*
* @return A string.
*/
public override function toString(): String
{
return this.name + ': x:' + Math.round(this.x) + ' y:' + Math.round(this.y) + ' z:' + Math.round(this.z);
}
// ___________________________________________________________________________________________________
// P R I V A T E
/**
* [internal-use]
*/
protected var _transformDirty :Boolean = false;
private var _rotationX :Number;
private var _rotationY :Number;
private var _rotationZ :Number;
private var _rotationDirty :Boolean = false;
private var _scaleX :Number;
private var _scaleY :Number;
private var _scaleZ :Number;
private var _scaleDirty :Boolean = false;
protected var _sorted :Array;
static private var _totalDisplayObjects :int = 0;
static private var toDEGREES :Number = 180/Math.PI;
static private var toRADIANS :Number = Math.PI/180;
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/DisplayObject3D.as | ActionScript | art | 37,093 |
package org.papervision3d.objects
{
import org.papervision3d.objects.particles.StarParticle;
import flash.display.Sprite;
/**
* @Author Ralph Hauwert
*/
public class ParticleField extends VertexParticles
{
private var fieldDepth:Number;
private var fieldHeight:Number;
private var fieldWidth:Number;
private var quantity:int;
private var color:int;
/**
* The ParticleField class creates an object with an amount of particles randomly distributed over a specied 3d area.
*
* @param quantity The amount of particles to create
* @param color The color of the created particles
* @param container An alternate container to render to, if needed.
* @param fieldWidth The width of the area
* @param fieldHeight The height of the area
* @param fieldDepth The depth of the area
*/
public function ParticleField(quantity:int = 200, color:int = 0xFFFFFF, container:Sprite = null, fieldWidth:Number = 2000, fieldHeight:Number = 2000, fieldDepth:Number = 2000)
{
super("ParticleField");
this.quantity = quantity;
this.color = color;
this.container = container;
this.fieldWidth = fieldWidth;
this.fieldHeight = fieldHeight;
this.fieldDepth = fieldDepth;
createParticles();
}
private function createParticles():void
{
var vertices:Array = this.geometry.vertices;
var width2 :Number = fieldWidth /2;
var height2 :Number = fieldHeight /2;
var depth2 :Number = fieldDepth /2;
var c:int;
var r:int;
for( var i:Number = 0; i < quantity; i++ )
{
addParticle(new StarParticle(color, 1,Math.random() * fieldWidth - width2, Math.random() * fieldHeight - height2, Math.random() * fieldDepth - depth2 ));
}
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/ParticleField.as | ActionScript | art | 1,732 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// Collada
package org.papervision3d.objects
{
import com.blitzagency.xray.logger.XrayLog;
import org.papervision3d.components.as3.collections.MaterialsListItem;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.Matrix3D;
import org.papervision3d.core.NumberUV;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Mesh3D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.core.proto.DisplayObjectContainer3D;
import org.papervision3d.core.proto.GeometryObject3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.MaterialsList;
/**
* The Collada class lets you load and parse Collada scenes.
* <p/>
* Recommended DCC Settings:
* <ul><li><b>Maya</b>:
* <ul><li>General Export Options
* <ul><li>Relative Paths, Triangulate.</li></ul>
* <li>Filter Export
* <ul><li>Polygon meshes, Normals, Texture Coordinates.</li></ul>
* </li></ul>
* <li><b>3DS Max</b>:
* <ul><li>Standard Options
* <ul><li>Relative Paths.</li></ul>
* <li>Geometry
* <ul><li>Normals, Triangulate.</li></ul>
* </li></ul>
*/
public class Collada extends DisplayObject3D
{
/**
* Default scaling value for constructor.
*/
static public var DEFAULT_SCALING :Number = 1;
/**
* Internal scaling value.
*/
static private var INTERNAL_SCALING :Number = 100;
/**
* Whether or not the scene has been loaded.
*/
public var loaded :Boolean;
public var materialsToLoad:int =0;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a new Collada object.
* <p/>
* The Collada class lets you load and parse a Collada scene.
* <p/>
* COLLADA is a COLLAborative Design Activity for establishing an interchange file format for interactive 3D applications.
* <p/>
* COLLADA defines an open standard XML schema for exchanging digital assets among various container software applications that might otherwise store their assets in incompatible formats.
* <p/>
* COLLADA documents that describe digital assets are XML files, usually identified with a .dae (digital asset exchange) filename extension.
* <p/>
* @param COLLADA An XML COLLADA object or the filename of the .dae scene to load.
* <p/>
* @param materials A MaterialsList object.
* <p/>
* @param scale Scaling factor.
* <p/>
*/
public function Collada( COLLADA :*, materials :MaterialsList=null, scale :Number=1, initObject :Object=null )
{
super(null, null, initObject);
this._materials = materials || new MaterialsList();
this._container = this;
this.loaded = false;
this._scaling = scale || DEFAULT_SCALING;
this._scaling *= INTERNAL_SCALING;
this._geometries = new Object();
if( COLLADA is XML )
{
this.COLLADA = COLLADA;
this._filename = "";
buildCollada();
}
else if( COLLADA is String )
{
this._filename = COLLADA;
loadCollada();
}
}
// _______________________________________________________________________ PRIVATE
private function loadCollada():void
{
this._loader = new URLLoader();
this._loader.addEventListener( Event.COMPLETE, onComplete );
this._loader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
this._loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityLoadError);
this._loader.addEventListener( ProgressEvent.PROGRESS, handleLoadProgress );
this._loader.load( new URLRequest( this._filename ) );
}
private function handleLoadProgress( e:ProgressEvent ):void
{
var progressEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_PROGRESS, this._filename, e.bytesLoaded, e.bytesTotal);
dispatchEvent( progressEvent );
}
private function handleIOError(e:IOErrorEvent):void
{
trace("COLLADA file load error", e.text);
dispatchEvent(new FileLoadEvent(FileLoadEvent.LOAD_ERROR,this._filename,0,0,e.text));
}
private function handleSecurityLoadError(e:SecurityErrorEvent):void
{
trace("COLLADA file security load error", e.text);
dispatchEvent(new FileLoadEvent(FileLoadEvent.SECURITY_LOAD_ERROR,this._filename, 0, 0, e.text));
}
private function onComplete(evt:Event):void
{
this.COLLADA = new XML( this._loader.data );
buildCollada();
}
// _______________________________________________________________________
private function buildCollada():void
{
//Reset the number of materials to load.
materialsToLoad = 0;
default xml namespace = COLLADA.namespace();
// Get up axis
this._yUp = (COLLADA.asset.up_axis == "Y_UP");
// Parse first scene
var sceneId:String = getId( COLLADA.scene.instance_visual_scene.@url );
var scene:XML = COLLADA.library_visual_scenes.visual_scene.(@id == sceneId)[0];
parseScene( scene );
var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_COMPLETE, _filename );
this.dispatchEvent( fileEvent );
this.loaded = true;
}
// _______________________________________________________________________ parseScene
private function parseScene( scene:XML ):void
{
for each( var node:XML in scene.node )
parseNode( node, this._container );
}
// _______________________________________________________________________ parseNode
private function parseNode( node:XML, parent:DisplayObjectContainer3D ):void
{
var matrix :Matrix3D = Matrix3D.IDENTITY;
//if( ! this._yUp && parent == this._container )
//{
//matrix = Matrix3D.rotationX( Math.PI/2 );
//matrix = Matrix3D.multiply( matrix, Matrix3D.rotationZ( Math.PI ) );
//}
var newNode:DisplayObject3D;
if( String( node.instance_geometry ) == "" )
newNode = new DisplayObject3D( node.@name );
else
newNode = new Mesh3D( null, null, null, node.@name );
var instance :DisplayObject3D = parent.addChild( newNode, node.@name );
var children :XMLList = node.children();
var totalChildren :int = children.length();
for( var i:int = 0; i < totalChildren; i++ )
{
var child:XML = children[i];
switch( child.name().localName )
{
case "translate":
matrix = Matrix3D.multiply( matrix, translateMatrix( getArray( child ) ) );
break;
case "rotate":
matrix = Matrix3D.multiply( matrix, rotateMatrix( getArray( child ) ) );
break;
case "scale":
matrix = Matrix3D.multiply( matrix, scaleMatrix( getArray( child ) ) );
break;
// Baked transform matrix
case "matrix":
matrix = Matrix3D.multiply( matrix, bakedMatrix( new Matrix3D( getArray( child ) ) ) );
break;
case "node":
parseNode( child, instance );
break;
case "instance_geometry":
// Instance materials
var bindMaterial:Object = new Object();
for each( var instance_material:XML in child..instance_material )
{
bindMaterial[ instance_material.@symbol ] = instance_material.@target.split("#")[1];
}
// Instance geometry
for each( var geometry:XML in child )
{
var geoId:String = getId( geometry.@url );
var geo:XML = COLLADA.library_geometries.geometry.(@id == geoId)[0];
parseGeometry( geo, instance, Matrix3D.clone( matrix ), bindMaterial );
}
break;
}
}
instance.copyTransform( matrix );
}
// _______________________________________________________________________ parseGeometry
private function parseGeometry( geometry:XML, instance:DisplayObject3D, matrix2:Matrix3D=null, bindMaterial:Object=null ):void
{
var matrix:Matrix3D = Matrix3D.clone( matrix2 ) || Matrix3D.IDENTITY; // TODO: Cleanup
// DEBUG
//trace( "parseGeometry: " + geometry.@id ); // DEBUG
// Semantics
var semantics :Object = new Object();
semantics.name = geometry.@id;
var faces:Array = semantics.triangles = new Array();
// Multi material
var multiMaterial:Boolean = (geometry.mesh.triangles.length() > 1);
// Triangles
for each( var triangles:XML in geometry.mesh.triangles )
{
// Input
var field:Array = new Array();
for each( var input:XML in triangles.input )
{
semantics[ input.@semantic ] = deserialize( input, geometry );
field.push( input.@semantic );
}
var data :Array = triangles.p.split(' ');
var len :Number = triangles.@count;
var material :String = triangles.@material;
// DEBUG
//trace( "triangles: " + len );
addMaterial( instance, material, bindMaterial );
for( var j:Number = 0; j < len; j++ )
{
var t:Object = new Object();
for( var v:Number = 0; v < 3; v++ )
{
var fld:String;
for( var k:Number = 0; fld = field[k]; k++ )
{
if( ! t[ fld ] ) t[ fld ] = new Array();
t[ fld ].push( Number( data.shift() ) );
}
t["material"] = material; //multiMaterial? material : null;
}
faces.push( t );
}
}
buildObject( semantics, instance, matrix );
}
// _______________________________________________________________________ buildObject
private function buildObject( semantics:Object, instance:DisplayObject3D, matrix:Matrix3D=null ):void
{
matrix = matrix || Matrix3D.IDENTITY;
// var mesh :Mesh3D = new Mesh3D( null, new Array(), new Array() )
instance.addGeometry( new GeometryObject3D() );
// Vertices
var vertices :Array = instance.geometry.vertices = new Array();
var scaling :Number = this._scaling;
var accVerts :Number = vertices.length;
var semVertices :Array = semantics.VERTEX;
var len:Number = semVertices.length;
// DEBUG
//trace( "Vertices: " + len );
var i:int;
for( i=0; i < len; i++ )
{
// Swap z & y for Max (to make Y up and Z depth)
var vert:Object = semVertices[ i ];
var x :Number = Number( vert.X ) * scaling;
var y :Number = Number( vert.Y ) * scaling;
var z :Number = Number( vert.Z ) * scaling;
if( this._yUp )
vertices.push( new Vertex3D( -x, y, z ) );
else
vertices.push( new Vertex3D( x, z, y ) );
}
// Faces
var faces :Array = instance.geometry.faces = new Array();
var semFaces :Array = semantics.triangles;
len = semFaces.length;
// DEBUG
//trace( "Faces: " + len );
for( i=0; i < len; i++ )
{
// Triangle
var tri :Array = semFaces[i].VERTEX;
var a :Vertex3D = vertices[ accVerts + tri[ 0 ] ];
var b :Vertex3D = vertices[ accVerts + tri[ 1 ] ];
var c :Vertex3D = vertices[ accVerts + tri[ 2 ] ];
var faceList :Array = [ a, b, c ];
var tex :Array = semantics.TEXCOORD;
var uv :Array = semFaces[i].TEXCOORD;
var uvList :Array, uvA :NumberUV, uvB :NumberUV, uvC :NumberUV;
if( uv && tex )
{
uvA = new NumberUV( tex[ uv[0] ].S, tex[ uv[0] ].T );
uvB = new NumberUV( tex[ uv[1] ].S, tex[ uv[1] ].T );
uvC = new NumberUV( tex[ uv[2] ].S, tex[ uv[2] ].T );
uvList = [ uvA, uvB, uvC ];
}
else uvList = null;
var materialName:String = semFaces[i].material || null;
var face:Face3D = new Face3D( faceList, _materials.getMaterialByName(materialName), uvList );
faces.push( face );
}
// Activate object
instance.geometry.ready = true;
matrix.n14 *= scaling;
matrix.n24 *= scaling;
matrix.n34 *= scaling;
instance.material = MaterialObject3D.DEFAULT;
instance.visible = true;
}
private function getArray( spaced:String ):Array
{
var strings :Array = spaced.split(" ");
var numbers :Array = new Array();
var totalStrings:Number = strings.length;
for( var i:Number=0; i < totalStrings; i++ )
numbers[i] = Number( strings[i] );
return numbers;
}
private function addMaterial( instance:DisplayObject3D, name:String, bindMaterial:Object ):void
{
//trace( "Collada: addMaterial: " + instance.name + " > " + name ); // DEBUG
var material:MaterialObject3D;
if( this._materials ){
material = this._materials.getMaterialByName( name );
}else{
_materials = new MaterialsList();
}
if( ! material )
{
// Find object path
var path :String = this._filename.slice( 0, this._filename.lastIndexOf("/") +1 );
// Retrieve texture url
var filename :String = getTexture( bindMaterial[name] );
if( filename )
{
// Load relative to the object
materialsToLoad++;
material = new BitmapFileMaterial( path + filename );
material.addEventListener(FileLoadEvent.LOAD_COMPLETE, onMaterialLoadComplete);
material.addEventListener(FileLoadEvent.LOAD_ERROR, onMaterialLoadError);
}
else
{
material = MaterialObject3D.DEFAULT;
Papervision3D.log( "Collada material " + name + " not found." ); // TODO: WARNING
}
material.name = name;
}
_materials.addMaterial(material);
if( ! instance.materials ) instance.materials = new MaterialsList();
instance.materials.addMaterial( material, name );
}
private function onMaterialLoadComplete(event:FileLoadEvent):void
{
materialsToLoad--;
if(materialsToLoad == 0){
materials = new MaterialsList();
dispatchEvent(new FileLoadEvent(FileLoadEvent.COLLADA_MATERIALS_DONE));
}
}
private function onMaterialLoadError(event:FileLoadEvent):void
{
var mat:BitmapFileMaterial = event.target as BitmapFileMaterial;
trace("Colllada failed to load material : " +mat);
//Do error handling here.
materialsToLoad--;
if(materialsToLoad == 0){
dispatchEvent(new FileLoadEvent(FileLoadEvent.COLLADA_MATERIALS_DONE));
}
}
// Retrieves the filename of a material
private function getTexture( name:String ):String
{
var filename :String = null;
var material:XML = COLLADA.library_materials.material.(@id == name)[0];
if( material )
{
var effectId:String = getId( material.instance_effect.@url );
var effect:XML = COLLADA.library_effects.effect.(@id == effectId)[0];
if (effect..texture.length() == 0) return null;
var textureId:String = effect..texture[0].@texture;
var sampler:XML = effect..newparam.(@sid == textureId)[0];
// Blender
var imageId:String = textureId;
// Not Blender
if( sampler )
{
var sourceId:String = sampler..source[0];
var source:XML = effect..newparam.(@sid == sourceId)[0];
imageId = source..init_from[0];
}
var image:XML = COLLADA.library_images.image.(@id == imageId)[0];
filename = image.init_from;
if (filename.substr(0, 2) == "./")
{
filename = filename.substr( 2 );
}
}
return filename;
}
// _______________________________________________________________________
// Matrices
private function rotateMatrix( vector:Array ):Matrix3D
{
if( this._yUp )
return Matrix3D.rotationMatrix( vector[0], vector[1], vector[2], -vector[3] *toRADIANS );
else
return Matrix3D.rotationMatrix( vector[0], vector[2], vector[1], -vector[3] *toRADIANS );
}
private function translateMatrix( vector:Array ):Matrix3D
{
if( this._yUp )
return Matrix3D.translationMatrix( -vector[0] *this._scaling, vector[1] *this._scaling, vector[2] *this._scaling );
else
return Matrix3D.translationMatrix( vector[0] *this._scaling, vector[2] *this._scaling, vector[1] *this._scaling );
}
private function scaleMatrix( vector:Array ):Matrix3D
{
if( this._yUp )
return Matrix3D.scaleMatrix( vector[0], vector[1], vector[2] );
else
return Matrix3D.scaleMatrix( vector[0], vector[2], vector[1] );
}
private function bakedMatrix( matrix:Matrix3D ):Matrix3D
{
matrix.n14 *= _scaling;
matrix.n24 *= _scaling;
matrix.n34 *= _scaling;
return matrix;
}
// _______________________________________________________________________
// XML
private function deserialize( input:XML, geo:XML ):Array
{
var output :Array = new Array();
var id :String = input.@source.split("#")[1];
// Source?
var acc:XMLList = geo..source.(@id == id).technique_common.accessor;
if( acc != new XMLList() )
{
// Build source floats array
var floId :String = acc.@source.split("#")[1];
var floXML :XMLList = COLLADA..float_array.(@id == floId);
var floStr :String = floXML.toString();
var floats :Array = floStr.split(" ");
// Build params array
var params :Array = new Array();
for each( var par:XML in acc.param )
params.push( par.@name );
// Build output array
var count :int = acc.@count;
var stride :int = acc.@stride;
for( var i:int=0; i < count; i++ )
{
var element :Object = new Object();
for( var j:int=0; j < stride; j++ )
element[ params[j] ] = floats.shift();
//for( j=0; j < stride; j++ ) trace( params[j] + " " + element[ params[j] ] ); // DEBUG
output.push( element );
}
}
else
{
// Store indexes if no source
var recursive :XMLList = geo..vertices.(@id == id)[INPUTTAG];
output = deserialize( recursive[0], geo );
}
return output;
}
public function getMaterialsList():MaterialsList
{
return _materials;
}
private function getId( url:String ):String
{
return url.split("#")[1];
}
// _______________________________________________________________________
// COLLADA tag names
private static var COLLADASECTION :String = "COLLADA";
private static var LIBRARYSECTION :String = "library";
private static var ASSETSECTION :String = "asset";
private static var SCENESECTION :String = "scene";
private static var LIGHTPREFAB :String = "light";
private static var CAMERAPREFAB :String = "camera";
private static var MATERIALSECTION :String = "material";
private static var GEOMETRYSECTION :String = "geometry";
private static var MESHSECTION :String = "mesh";
private static var SOURCESECTION :String = "source";
private static var ARRAYSECTION :String = "array";
private static var ACCESSORSECTION :String = "accessor";
private static var VERTICESSECTION :String = "vertices";
private static var INPUTTAG :String = "input";
private static var POLYGONSSECTION :String = "polygons";
private static var POLYGON :String = "p";
private static var NODESECTION :String = "node";
private static var LOOKATNODE :String = "lookat";
private static var MATRIXNODE :String = "matrix";
private static var PERSPECTIVENODE :String = "perspective";
private static var ROTATENODE :String = "rotate";
private static var SCALENODE :String = "scale";
private static var TRANSLATENODE :String = "translate";
private static var SKEWNODE :String = "skew";
private static var INSTANCENODE :String = "instance";
private static var INSTACESCENE :String = "instance_visual_scene";
private static var PARAMTAG :String = "param";
private static var POSITIONINPUT :String = "POSITION";
private static var VERTEXINPUT :String = "VERTEX";
private static var NORMALINPUT :String = "NORMAL";
private static var TEXCOORDINPUT :String = "TEXCOORD";
private static var UVINPUT :String = "UV";
private static var TANGENTINPUT :String = "TANGENT";
// _______________________________________________________________________
private var COLLADA :XML;
private var _container :DisplayObjectContainer3D;
private var _geometries :Object;
private var _loader :URLLoader;
private var _filename :String;
private var _materials :MaterialsList;
private var _scaling :Number;
private var _yUp :Boolean;
static private var toDEGREES :Number = 180/Math.PI;
static private var toRADIANS :Number = Math.PI/180;
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Collada.as | ActionScript | art | 23,161 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Cylinder
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Cylinder class lets you create and display Cylinders.
* <p/>
* The Cylinder is divided in vertical and horizontal segment, the smallest combination is two vertical and three horizontal segments.
*/
public class Cylinder extends Mesh3D
{
/**
* Number of segments horizontally. Defaults to 8.
*/
public var segmentsW :Number;
/**
* Number of segments vertically. Defaults to 6.
*/
public var segmentsH :Number;
/**
* Default radius of Cylinder if not defined.
*/
static public var DEFAULT_RADIUS :Number = 100;
/**
* Default height if not defined.
*/
static public var DEFAULT_HEIGHT :Number = 100;
/**
* Default scale of Cylinder texture if not defined.
*/
static public var DEFAULT_SCALE :Number = 1;
/**
* Default value of gridX if not defined.
*/
static public var DEFAULT_SEGMENTSW :Number = 8;
/**
* Default value of gridY if not defined.
*/
static public var DEFAULT_SEGMENTSH :Number = 6;
/**
* Minimum value of gridX.
*/
static public var MIN_SEGMENTSW :Number = 3;
/**
* Minimum value of gridY.
*/
static public var MIN_SEGMENTSH :Number = 2;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Cylinder object.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param radius [optional] - Desired radius.
* <p/>
* @param segmentsW [optional] - Number of segments horizontally. Defaults to 8.
* <p/>
* @param segmentsH [optional] - Number of segments vertically. Defaults to 6.
* <p/>
* @param topRadius [optional] - An optional parameter for con- or diverging cylinders
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Cylinder( material:MaterialObject3D=null, radius:Number=100, height:Number=100, segmentsW:int=8, segmentsH:int=6, topRadius:Number=0, initObject:Object=null )
{
super( material, new Array(), new Array(), null, initObject );
this.segmentsW = Math.max( MIN_SEGMENTSW, segmentsW || DEFAULT_SEGMENTSW); // Defaults to 8
this.segmentsH = Math.max( MIN_SEGMENTSH, segmentsH || DEFAULT_SEGMENTSH); // Defaults to 6
if (radius==0) radius = DEFAULT_RADIUS; // Defaults to 100
if (height==0) height = DEFAULT_HEIGHT; // Defaults to 100
// if (typeOf(initObject)=="object") for each (prop in initObject) this[prop] = initObject[prop];
if (topRadius==0) topRadius = radius;
var scale :Number = DEFAULT_SCALE;
buildCylinder( radius, height, topRadius );
}
private function buildCylinder( fRadius:Number, fHeight:Number, fTopRadius:Number ):void
{
var i:Number, j:Number, k:Number;
var iHor:Number = Math.max(3,this.segmentsW);
var iVer:Number = Math.max(2,this.segmentsH);
var aVertice:Array = this.geometry.vertices;
var aFace:Array = this.geometry.faces;
var aVtc:Array = new Array();
for (j=0;j<(iVer+1);j++) { // vertical
var fRad1:Number = Number(j/iVer);
var fZ:Number = fHeight*(j/(iVer+0))-fHeight/2;//-fRadius*Math.cos(fRad1*Math.PI);
var fRds:Number = fTopRadius+(fRadius-fTopRadius)*(1-j/(iVer));//*Math.sin(fRad1*Math.PI);
var aRow:Array = new Array();
var oVtx:Vertex3D;
for (i=0;i<iHor;i++) { // horizontal
var fRad2:Number = Number(2*i/iHor);
var fX:Number = fRds*Math.sin(fRad2*Math.PI);
var fY:Number = fRds*Math.cos(fRad2*Math.PI);
//if (!((j==0||j==iVer)&&i>0)) { // top||bottom = 1 vertex
oVtx = new Vertex3D(fY,fZ,fX);
aVertice.push(oVtx);
//}
aRow.push(oVtx);
}
aVtc.push(aRow);
}
var iVerNum:int = aVtc.length;
var aP4uv:NumberUV, aP1uv:NumberUV, aP2uv:NumberUV, aP3uv:NumberUV;
var aP1:Vertex3D, aP2:Vertex3D, aP3:Vertex3D, aP4:Vertex3D;
for (j=0;j<iVerNum;j++) {
var iHorNum:int = aVtc[j].length;
for (i=0;i<iHorNum;i++) {
if (j>0&&i>=0) {
// select vertices
var bEnd:Boolean = i==(iHorNum-0);
aP1 = aVtc[j][bEnd?0:i];
aP2 = aVtc[j][(i==0?iHorNum:i)-1];
aP3 = aVtc[j-1][(i==0?iHorNum:i)-1];
aP4 = aVtc[j-1][bEnd?0:i];
// uv
var fJ0:Number = j / iVerNum;
var fJ1:Number = (j-1) / iVerNum;
var fI0:Number = (i+1) / iHorNum;
var fI1:Number = i / iHorNum;
aP4uv = new NumberUV(fI0,fJ1);
aP1uv = new NumberUV(fI0,fJ0);
aP2uv = new NumberUV(fI1,fJ0);
aP3uv = new NumberUV(fI1,fJ1);
// 2 faces
aFace.push( new Face3D(new Array(aP1,aP2,aP3), null, new Array(aP1uv,aP2uv,aP3uv)) );
aFace.push( new Face3D(new Array(aP1,aP3,aP4), null, new Array(aP1uv,aP3uv,aP4uv)) );
}
}
if (j==0||j==(iVerNum-1)) {
for (i=0;i<(iHorNum-2);i++) {
// uv
var iI:int = Math.floor(i/2);
aP1 = aVtc[j][iI];
aP2 = (i%2==0)? (aVtc[j][iHorNum-2-iI]) : (aVtc[j][iI+1]);
aP3 = (i%2==0)? (aVtc[j][iHorNum-1-iI]) : (aVtc[j][iHorNum-2-iI]);
var bTop:Boolean = j==0;
aP1uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*(aP1.x/fRadius/2+.5), aP1.z/fRadius/2+.5 );
aP2uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*(aP2.x/fRadius/2+.5), aP2.z/fRadius/2+.5 );
aP3uv = new NumberUV( (bTop?1:0)+(bTop?-1:1)*(aP3.x/fRadius/2+.5), aP3.z/fRadius/2+.5 );
// face
if (j==0) aFace.push( new Face3D(new Array(aP1,aP3,aP2), null, new Array(aP1uv,aP3uv,aP2uv)) );
else aFace.push( new Face3D(new Array(aP1,aP2,aP3), null, new Array(aP1uv,aP2uv,aP3uv)) );
}
}
}
this.geometry.ready = true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Cylinder.as | ActionScript | art | 8,441 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org + blog.papervision3d.org + osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________
// GeometryObject3D: Plane
package org.papervision3d.objects
{
import org.papervision3d.core.*;
import org.papervision3d.core.proto.*;
import org.papervision3d.core.geom.*;
import flash.display.BitmapData;
/**
* The Plane class lets you create and display flat rectangle objects.
* <p/>
* The rectangle can be divided in smaller segments. This is usually done to reduce linear mapping artifacts.
* <p/>
* Dividing the plane in the direction of the perspective or vanishing point, helps to reduce this problem. Perspective distortion dissapears when the plane is facing straignt to the camera, i.e. it is perpendicular with the vanishing point of the scene.
*/
public class Plane extends Mesh3D
{
/**
* Number of segments horizontally. Defaults to 1.
*/
public var segmentsW :Number;
/**
* Number of segments vertically. Defaults to 1.
*/
public var segmentsH :Number;
/**
* Default size of Plane if not texture is defined.
*/
static public var DEFAULT_SIZE :Number = 500;
/**
* Default size of Plane if not texture is defined.
*/
static public var DEFAULT_SCALE :Number = 1;
/**
* Default value of gridX if not defined. The default value of gridY is gridX.
*/
static public var DEFAULT_SEGMENTS :Number = 1;
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Create a new Plane object.
* <p/>
* @param material A MaterialObject3D object that contains the material properties of the object.
* <p/>
* @param width [optional] - Desired width or scaling factor if there's bitmap texture in material and no height is supplied.
* <p/>
* @param height [optional] - Desired height.
* <p/>
* @param segmentsW [optional] - Number of segments horizontally. Defaults to 1.
* <p/>
* @param segmentsH [optional] - Number of segments vertically. Defaults to segmentsW.
* <p/>
* @param initObject [optional] - An object that contains user defined properties with which to populate the newly created GeometryObject3D.
* <p/>
* It includes x, y, z, rotationX, rotationY, rotationZ, scaleX, scaleY scaleZ and a user defined extra object.
* <p/>
* If extra is not an object, it is ignored. All properties of the extra field are copied into the new instance. The properties specified with extra are publicly available.
*/
public function Plane( material:MaterialObject3D=null, width:Number=0, height:Number=0, segmentsW:Number=0, segmentsH:Number=0, initObject:Object=null )
{
super( material, new Array(), new Array(), null, initObject );
this.segmentsW = segmentsW || DEFAULT_SEGMENTS; // Defaults to 1
this.segmentsH = segmentsH || this.segmentsW; // Defaults to segmentsW
var scale :Number = DEFAULT_SCALE;
if( ! height )
{
if( width )
scale = width;
if( material && material.bitmap )
{
width = material.bitmap.width * scale;
height = material.bitmap.height * scale;
}
else
{
width = DEFAULT_SIZE * scale;
height = DEFAULT_SIZE * scale;
}
}
buildPlane( width, height );
}
private function buildPlane( width:Number, height:Number ):void
{
var gridX :Number = this.segmentsW;
var gridY :Number = this.segmentsH;
var gridX1 :Number = gridX + 1;
var gridY1 :Number = gridY + 1;
var vertices :Array = this.geometry.vertices;
var faces :Array = this.geometry.faces;
var textureX :Number = width /2;
var textureY :Number = height /2;
var iW :Number = width / gridX;
var iH :Number = height / gridY;
// Vertices
for( var ix:int = 0; ix < gridX + 1; ix++ )
{
for( var iy:int = 0; iy < gridY1; iy++ )
{
var x :Number = ix * iW - textureX;
var y :Number = iy * iH - textureY;
vertices.push( new Vertex3D( x, y, 0 ) );
}
}
// Faces
var uvA :NumberUV;
var uvC :NumberUV;
var uvB :NumberUV;
for( ix = 0; ix < gridX; ix++ )
{
for( iy= 0; iy < gridY; iy++ )
{
// Triangle A
var a:Vertex3D = vertices[ ix * gridY1 + iy ];
var c:Vertex3D = vertices[ ix * gridY1 + (iy+1) ];
var b:Vertex3D = vertices[ (ix+1) * gridY1 + iy ];
uvA = new NumberUV( ix / gridX, iy / gridY );
uvC = new NumberUV( ix / gridX, (iy+1) / gridY );
uvB = new NumberUV( (ix+1) / gridX, iy / gridY );
faces.push( new Face3D( [ a, b, c ], null, [ uvA, uvB, uvC ] ) );
// Triangle B
a = vertices[ (ix+1) * gridY1 + (iy+1) ];
c = vertices[ (ix+1) * gridY1 + iy ];
b = vertices[ ix * gridY1 + (iy+1) ];
uvA = new NumberUV( (ix+1) / gridX, (iy+1) / gridY );
uvC = new NumberUV( (ix+1) / gridX, iy / gridY );
uvB = new NumberUV( ix / gridX, (iy+1) / gridY );
faces.push( new Face3D( [ a, b, c ], null, [ uvA, uvB, uvC ] ) );
}
}
this.geometry.ready = true;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/Plane.as | ActionScript | art | 7,054 |
package org.papervision3d.objects.particles
{
import flash.display.Sprite;
import org.papervision3d.core.geom.Vertex3D;
public class AbstractParticle implements IParticle
{
public var color:int;
public var size:int;
public var vertex3D:Vertex3D;
public function AbstractParticle(color:int=0xFFFFFF, size:int=1, x:Number=0, y:Number=0, z:Number=0)
{
this.color = color;
this.size = size;
vertex3D = new Vertex3D(x,y,z);
}
public function render(container:Sprite):int
{
return 0;
}
public function update():void
{
}
public function set x(x:Number):void
{
vertex3D.x = x;
}
public function get x():Number
{
return vertex3D.x;
}
public function set y(y:Number):void
{
vertex3D.y = y;
}
public function get y():Number
{
return vertex3D.y;
}
public function set z(z:Number):void
{
vertex3D.z = z;
}
public function get z():Number
{
return vertex3D.z;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/particles/AbstractParticle.as | ActionScript | art | 985 |
package org.papervision3d.objects.particles
{
import org.papervision3d.core.geom.Vertex3D;
import flash.display.Sprite;
public class StarParticle extends AbstractParticle implements IParticle
{
/**
* StarParticle
*
* used by the ParticleField as the Particle object to render.
*/
public function StarParticle(color:int=0xFFFFFF, size:int=1, x:Number=0, y:Number=0, z:Number=0)
{
super(color, size, x, y, z);
}
override public function render(container:Sprite):int
{
if(vertex3D.vertex2DInstance.visible){
container.graphics.beginFill(color, 1);
container.graphics.drawCircle(vertex3D.vertex2DInstance.x, vertex3D.vertex2DInstance.y,size);
container.graphics.endFill();
}
return 1;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/particles/StarParticle.as | ActionScript | art | 750 |
package org.papervision3d.objects.particles
{
import flash.display.Sprite;
public interface IParticle
{
function render(container:Sprite):int;
function update():void;
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/particles/IParticle.as | ActionScript | art | 180 |
package org.papervision3d.objects
{
/**
* @Author Ralph Hauwert
*/
import flash.display.Sprite;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Vertex3D;
import org.papervision3d.core.geom.Vertices3D;
import org.papervision3d.core.proto.SceneObject3D;
import org.papervision3d.objects.particles.AbstractParticle;
import org.papervision3d.objects.particles.IParticle;
public class VertexParticles extends Vertices3D
{
private var vertices:Array;
private var particles:Array;
/**
* VertexParticles
*
* A simple Particle Renderer for Papervision3D.
*
* Renders added particles to a given container using Flash's drawing API.
*/
public function VertexParticles(name:String = "VertexParticles")
{
this.vertices = new Array();
this.particles = new Array();
super(vertices, name);
}
/**
* render(scene);
*
* Renders the particles added to this VertexParticles Object
*/
public override function render(scene:SceneObject3D ):void
{
var vertices:Array = this.geometry.vertices;
var container:Sprite = this.container || scene.container;
var particle:IParticle;
if(this.container){
container.graphics.clear();
}
for each(particle in particles)
{
scene.stats.particles += particle.render(container);
}
}
/**
* addParticle(particle);
*
* @param particle partical to be added and rendered by to this VertexParticles Object.
*/
public function addParticle(particle:AbstractParticle):void
{
particles.push(particle);
vertices.push(particle.vertex3D);
}
/**
* removeParticle(particle);
*
* @param particle partical to be removed from this VertexParticles Object.
*/
public function removeParticle(particle:AbstractParticle):void
{
particles.splice(particles.indexOf(particle,0));
vertices.splice(vertices.indexOf(particle.vertex3D,0));
}
/**
* removeAllParticles()
*
* removes all particles in this VertexParticles Object.
*/
public function removeAllParticles():void
{
particles = new Array();
vertices = new Array();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/objects/VertexParticles.as | ActionScript | art | 2,155 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* @author John Grden
* NOTE: ported by Andy Zupko
*/
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Matrix;
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.materials.IPreciseMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
public class PreciseMovieAssetMaterial extends MovieAssetMaterial implements IPreciseMaterial
{
public var precision:Number = 1;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;
public var focus:Number = 100;
public function PreciseMovieAssetMaterial( linkageID:String="", transparent:Boolean=false, animated:Boolean=false )
{
super( linkageID, transparent, animated );
precision = precision * precision * 1.4;
}
public override function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var mapping:Matrix = transformUV(face3D);
renderRec(graphics, mapping.a, mapping.b, mapping.c, mapping.d, mapping.tx, mapping.ty, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z,0);
return 1;
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
{
if ((az <= 0) && (bz <= 0) && (cz <= 0))
return;
if (index >= 100 || (focus == Infinity) || (Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx) < 1) || (Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy) < 1))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
var faz:Number = focus + az;
var fbz:Number = focus + bz;
var fcz:Number = focus + cz;
var mabz:Number = 2 / (faz + fbz);
var mbcz:Number = 2 / (fbz + fcz);
var mcaz:Number = 2 / (fcz + faz);
var mabx:Number = (ax*faz + bx*fbz)*mabz;
var maby:Number = (ay*faz + by*fbz)*mabz;
var mbcx:Number = (bx*fbz + cx*fcz)*mbcz;
var mbcy:Number = (by*fbz + cy*fcz)*mbcz;
var mcax:Number = (cx*fcz + ax*faz)*mcaz;
var mcay:Number = (cy*fcz + ay*faz)*mcaz;
var dabx:Number = ax + bx - mabx;
var daby:Number = ay + by - maby;
var dbcx:Number = bx + cx - mbcx;
var dbcy:Number = by + cy - mbcy;
var dcax:Number = cx + ax - mcax;
var dcay:Number = cy + ay - mcay;
var dsab:Number = (dabx*dabx + daby*daby);
var dsbc:Number = (dbcx*dbcx + dbcy*dbcy);
var dsca:Number = (dcax*dcax + dcay*dcay);
if ((dsab <= precision) && (dsca <= precision) && (dsbc <= precision))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
//Debug.trace(num(ta)+" "+num(tb)+" "+num(tc)+" "+num(td)+" "+num(tx)+" "+num(ty));
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
//graphics.lineStyle();
graphics.beginBitmapFill(bitmap, matrix, repeat, smooth && (v0x*(v2y - v1y) + v1x*(v0y - v2y) + v2x*(v1y - v0y) > 400));
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
private static function num(n:Number):Number
{
return int(n*1000)/1000;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/PreciseMovieAssetMaterial.as | ActionScript | art | 8,945 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* @author John Grden
* NOTE: ported by Andy Zupko
*/
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Matrix;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.IPreciseMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
public class PreciseMovieMaterial extends MovieMaterial implements IPreciseMaterial
{
public var precision:Number = 1;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;
public var focus:Number = 100;
public function PreciseMovieMaterial( movieAsset:Sprite=null, transparent:Boolean=false, animated:Boolean=false )
{
super( movieAsset, transparent, animated );
precision = precision * precision * 1.4;
}
public override function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var mapping:Matrix = transformUV(face3D);
renderRec(graphics, mapping.a, mapping.b, mapping.c, mapping.d, mapping.tx, mapping.ty, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z,0);
return 1;
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
{
if ((az <= 0) && (bz <= 0) && (cz <= 0))
return;
if (index >= 100 || (focus == Infinity) || (Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx) < 2) || (Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy) < 2))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
var faz:Number = focus + az;
var fbz:Number = focus + bz;
var fcz:Number = focus + cz;
var mabz:Number = 2 / (faz + fbz);
var mbcz:Number = 2 / (fbz + fcz);
var mcaz:Number = 2 / (fcz + faz);
var mabx:Number = (ax*faz + bx*fbz)*mabz;
var maby:Number = (ay*faz + by*fbz)*mabz;
var mbcx:Number = (bx*fbz + cx*fcz)*mbcz;
var mbcy:Number = (by*fbz + cy*fcz)*mbcz;
var mcax:Number = (cx*fcz + ax*faz)*mcaz;
var mcay:Number = (cy*fcz + ay*faz)*mcaz;
var dabx:Number = ax + bx - mabx;
var daby:Number = ay + by - maby;
var dbcx:Number = bx + cx - mbcx;
var dbcy:Number = by + cy - mbcy;
var dcax:Number = cx + ax - mcax;
var dcay:Number = cy + ay - mcay;
var dsab:Number = (dabx*dabx + daby*daby);
var dsbc:Number = (dbcx*dbcx + dbcy*dbcy);
var dsca:Number = (dcax*dcax + dcay*dcay);
if ((dsab <= precision) && (dsca <= precision) && (dsbc <= precision))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
//Debug.trace(num(ta)+" "+num(tb)+" "+num(tc)+" "+num(td)+" "+num(tx)+" "+num(ty));
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
graphics.lineStyle();
graphics.beginBitmapFill(bitmap, matrix, repeat, smooth && (v0x*(v2y - v1y) + v1x*(v0y - v2y) + v2x*(v1y - v0y) > 400));
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
private static function num(n:Number):Number
{
return int(n*1000)/1000;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/PreciseMovieMaterial.as | ActionScript | art | 8,913 |
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Matrix;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.objects.DisplayObject3D;
public class BitmapWireframeMaterial extends BitmapMaterial implements IFaceDrawer
{
private static const BITMAP_WIDTH:int = 64;
private static const BITMAP_HEIGHT:int = 64;
private var uvMatrix:Matrix;
public function BitmapWireframeMaterial(color:Number=0xFF00FF, alpha:Number=1, thickness:Number=3)
{
bitmap = new BitmapData(BITMAP_WIDTH,BITMAP_HEIGHT,true,0x00000000);
lineColor = color;
lineAlpha = alpha;
lineThickness = thickness;
init();
}
private function init():void
{
createBitmapData();
createStaticUVMatrix();
}
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
if(bitmap){
var x0:Number = v0.x;
var y0:Number = v0.y;
var x1:Number = v1.x;
var y1:Number = v1.y;
var x2:Number = v2.x;
var y2:Number = v2.y;
_triMatrix.a = x1 - x0;
_triMatrix.b = y1 - y0;
_triMatrix.c = x2 - x0;
_triMatrix.d = y2 - y0;
_triMatrix.tx = x0;
_triMatrix.ty = y0;
_localMatrix.a = uvMatrix.a;
_localMatrix.b = uvMatrix.b;
_localMatrix.c = uvMatrix.c;
_localMatrix.d = uvMatrix.d;
_localMatrix.tx = uvMatrix.tx;
_localMatrix.ty = uvMatrix.ty;
_localMatrix.concat(_triMatrix);
graphics.beginBitmapFill( bitmap, _localMatrix, tiled, smooth);
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.endFill();
return 1;
}
return 0;
}
private function createBitmapData():void
{
var sprite:Sprite = new Sprite();
var graphics:Graphics = sprite.graphics;
graphics.lineStyle(lineThickness,lineColor,lineAlpha);
graphics.moveTo( 1, 1 );
graphics.lineTo( BITMAP_WIDTH-1,1 );
graphics.lineTo( BITMAP_WIDTH-1,BITMAP_HEIGHT-1);
graphics.lineTo( 1, 1 );
graphics.endFill();
bitmap.draw(sprite);
}
private function createStaticUVMatrix():void
{
var w :Number = BITMAP_WIDTH;
var h :Number = BITMAP_HEIGHT;
var u0 :Number = w;
var v0 :Number = 0;
var u1 :Number = 0;
var v1 :Number = 0;
var u2 :Number = w;
var v2 :Number = h;
// Precalculate matrix & correct for mip mapping
var at :Number = ( u1 - u0 );
var bt :Number = ( v1 - v0 );
var ct :Number = ( u2 - u0 );
var dt :Number = ( v2 - v0 );
uvMatrix = new Matrix( at, bt, ct, dt, u0, v0 );
uvMatrix.invert();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/BitmapWireframeMaterial.as | ActionScript | art | 2,856 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org blog.papervision3d.org osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// __________________________________________________________________________ WIREFRAME MATERIAL
package org.papervision3d.materials
{
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
import org.papervision3d.objects.DisplayObject3D;
/**
* The WireframeMaterial class creates a wireframe material, where only the outlines of the faces are drawn.
* <p/>
* Materials collects data about how objects appear when rendered.
*/
public class WireframeMaterial extends MaterialObject3D implements IFaceDrawer
{
// ______________________________________________________________________ NEW
/**
* The WireframeMaterial class creates a wireframe material, where only the outlines of the faces are drawn.
*
* @param asset A BitmapData object.
* @param initObject [optional] - An object that contains additional properties with which to populate the newly created material.
*/
public function WireframeMaterial( color:Number=0xFF00FF, alpha:Number=100 )
{
this.lineColor = color;
this.lineAlpha = alpha;
this.doubleSided = false;
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var x0:Number = v0.x;
var y0:Number = v0.y;
var x1:Number = v1.x;
var y1:Number = v1.y;
var x2:Number = v2.x;
var y2:Number = v2.y;
if( lineAlpha )
{
graphics.lineStyle( 0, lineColor, lineAlpha );
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.lineStyle();
return 1;
}
else
return 0;
}
// ______________________________________________________________________ TO STRING
/**
* Returns a string value representing the material properties in the specified WireframeMaterial object.
*
* @return A string.
*/
public override function toString(): String
{
return 'WireframeMaterial - color:' + this.lineColor + ' alpha:' + this.lineAlpha;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/WireframeMaterial.as | ActionScript | art | 4,043 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// __________________________________________________________________________ MOVIE MATERIAL
package org.papervision3d.materials
{
import flash.geom.Matrix;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
/**
* The MovieMaterial class creates a texture from an existing MovieClip instance.
* <p/>
* The texture can be animated and/or transparent. Current scale and color values of the MovieClip instance will be used. Rotation will be discarded.
* <p/>
* The MovieClip's content needs to be top left aligned with the registration point.
* <p/>
* Materials collects data about how objects appear when rendered.
*/
public class MovieMaterial extends BitmapMaterial
{
// ______________________________________________________________________ PUBLIC
/**
* The MovieClip that is used as a texture.
*/
public var movie :DisplayObject;
/**
* A Boolean value that determines whether the MovieClip is transparent. The default value is false, which is much faster.
*/
public var movieTransparent :Boolean;
/**
* When updateBitmap() is called on an animated material, it looks to handle a change in size on the texture.
*
* This is true by default, but in certain situations, like drawing on an object, you wouldn't want the size to change
*/
public var allowAutoResize:Boolean = true;
// ______________________________________________________________________ ANIMATED
/**
* A Boolean value that determines whether the texture is animated.
*
* If set, the material must be included into the scene so the BitmapData texture can be updated when rendering. For performance reasons, the default value is false.
*/
public function get animated():Boolean
{
return animatedMaterials[ this ];
}
public function set animated( status:Boolean ):void
{
animatedMaterials[ this ] = status;
}
/**
* A texture object.
*/
override public function get texture():Object
{
return this._texture;
}
/**
* @private
*/
override public function set texture( asset:Object ):void
{
if( asset is DisplayObject == false )
{
Papervision3D.log("Error: MovieMaterial.texture requires a Sprite to be passed as the object");
return;
}
bitmap = createBitmapFromSprite( DisplayObject(asset) );
_texture = asset;
}
// ______________________________________________________________________ NEW
/**
* The MovieMaterial class creates a texture from an existing MovieClip instance.
*
* @param movieAsset A reference to an existing MovieClip loaded into memory or on stage
* @param transparent [optional] - If it's not transparent, the empty areas of the MovieClip will be of fill32 color. Default value is false.
* @param animated [optional] - a flag setting whether or not this material has animation. If set to true, it will be updated during each render loop
*/
public function MovieMaterial( movieAsset:DisplayObject=null, transparent:Boolean=false, animated:Boolean=false )
{
movieTransparent = transparent;
this.animated = animated;
if( movieAsset ) texture = movieAsset
}
// ______________________________________________________________________ CREATE BITMAP
/**
*
* @param asset
* @return
*/
protected function createBitmapFromSprite( asset:DisplayObject ):BitmapData
{
// Set the new movie reference
movie = asset;
// initialize the bitmap since it's new
initBitmap( movie );
// Draw
drawBitmap();
// Call super.createBitmap to centralize the bitmap specific code.
// Here only MovieClip specific code, all bitmap code (maxUVs, AUTO_MIP_MAP, correctBitmap) in BitmapMaterial.
bitmap = super.createBitmap( bitmap );
return bitmap;
}
protected function initBitmap( asset:DisplayObject ):void
{
// Cleanup previous bitmap if needed
if( bitmap )
bitmap.dispose();
// Create new bitmap
bitmap = new BitmapData( asset.width, asset.height, this.movieTransparent );
}
// ______________________________________________________________________ UPDATE
/**
* Updates animated MovieClip bitmap.
*
* Draws the current MovieClip image onto bitmap.
*/
public override function updateBitmap():void
{
// using int is much faster than using Math.floor. And casting the variable saves in speed from having the avm decide what to cast it as
var mWidth:int = int(movie.width);
var mHeight:int = int(movie.height);
if( allowAutoResize && ( mWidth != bitmap.width || mHeight != bitmap.height ) )
{
// Init new bitmap size
initBitmap( movie );
}
drawBitmap();
}
public function drawBitmap():void
{
bitmap.fillRect( bitmap.rect, this.fillColor );
var mtx:Matrix = new Matrix();
mtx.scale( movie.scaleX, movie.scaleY );
bitmap.draw( movie, mtx, movie.transform.colorTransform );
}
// ______________________________________________________________________ CREATE BITMAP
/**
* Updates bitmap on all animated MovieMaterial instances.
*/
static public function updateAnimatedBitmaps():void
{
for( var material:Object in animatedMaterials )
{
if( animatedMaterials[ material ] )
{
material.updateBitmap();
}
}
}
// ______________________________________________________________________ PRIVATE
static private var animatedMaterials :Dictionary = new Dictionary( false );
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/MovieMaterial.as | ActionScript | art | 7,186 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveWireframeMaterial extends WireframeMaterial
{
public function InteractiveWireframeMaterial( color:Number=0xFF00FF, alpha:Number=1 )
{
super( color, alpha );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y)
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveWireframeMaterial.as | ActionScript | art | 891 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// __________________________________________________________________________ BITMAP MATERIAL
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.objects.DisplayObject3D;
/**
* The BitmapMaterial class creates a texture from a BitmapData object.
*
* Materials collect data about how objects appear when rendered.
*
*/
public class BitmapMaterial extends MaterialObject3D implements IFaceDrawer
{
/**
* Indicates if mip mapping is forced.
*/
static public var AUTO_MIP_MAPPING :Boolean = false;
/**
* Levels of mip mapping to force.
*/
static public var MIP_MAP_DEPTH :Number = 8;
// ______________________________________________________________________ TEXTURE
protected var _texture :Object;
/**
* A texture object.
*/
public function get texture():Object
{
return this._texture;
}
/**
* @private
*/
public function set texture( asset:Object ):void
{
if( asset is BitmapData == false )
{
Papervision3D.log("Error: BitmapMaterial.texture requires a BitmapData object for the texture");
return;
}
bitmap = createBitmap( BitmapData(asset) );
_texture = asset;
}
public var uvMatrices:Dictionary = new Dictionary();
/**
* @private
*/
protected static var _triMatrix:Matrix = new Matrix();
/**
* @private
*/
protected static var _localMatrix:Matrix = new Matrix();
// ______________________________________________________________________ NEW
/**
* The BitmapMaterial class creates a texture from a BitmapData object.
*
* @param asset A BitmapData object.
*/
public function BitmapMaterial( asset:BitmapData=null )
{
// texture calls createBitmap. That's where all the init happens. This allows to reinit when changing texture. -C4RL05
// if we have an asset passed in, this means we're the subclass, not the super. Set the texture, let the fun begin.
if( asset ) texture = asset;
}
/**
* Resets the mapping coordinates. Use when the texture has been resized.
*/
public function resetMapping():void
{
uvMatrices = new Dictionary();
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
if( lineAlpha )
graphics.lineStyle( 0, lineColor, lineAlpha );
if( bitmap )
{
var map:Matrix = (uvMatrices[face3D] || transformUV(face3D, instance)),
x0:Number = v0.x,
y0:Number = v0.y,
x1:Number = v1.x,
y1:Number = v1.y,
x2:Number = v2.x,
y2:Number = v2.y;
_triMatrix.a = x1 - x0;
_triMatrix.b = y1 - y0;
_triMatrix.c = x2 - x0;
_triMatrix.d = y2 - y0;
_triMatrix.tx = x0;
_triMatrix.ty = y0;
_localMatrix.a = map.a;
_localMatrix.b = map.b;
_localMatrix.c = map.c;
_localMatrix.d = map.d;
_localMatrix.tx = map.tx;
_localMatrix.ty = map.ty;
_localMatrix.concat(_triMatrix);
graphics.beginBitmapFill( bitmap, _localMatrix, tiled, smooth);
}
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
if( bitmap )
graphics.endFill();
if( lineAlpha )
graphics.lineStyle();
return 1;
}
/**
* Applies the updated UV texture mapping values to the triangle. This is required to speed up rendering.
*
*/
public function transformUV(face3D:Face3D, instance:DisplayObject3D=null):Matrix
{
if( ! face3D.uv )
{
Papervision3D.log( "MaterialObject3D: transformUV() uv not found!" );
}
else if( bitmap )
{
var uv :Array = face3D.uv;
var w :Number = bitmap.width * maxU;
var h :Number = bitmap.height * maxV;
var u0 :Number = w * uv[0].u;
var v0 :Number = h * ( 1 - uv[0].v );
var u1 :Number = w * uv[1].u;
var v1 :Number = h * ( 1 - uv[1].v );
var u2 :Number = w * uv[2].u;
var v2 :Number = h * ( 1 - uv[2].v );
// Fix perpendicular projections
if( (u0 == u1 && v0 == v1) || (u0 == u2 && v0 == v2) )
{
u0 -= (u0 > 0.05)? 0.05 : -0.05;
v0 -= (v0 > 0.07)? 0.07 : -0.07;
}
if( u2 == u1 && v2 == v1 )
{
u2 -= (u2 > 0.05)? 0.04 : -0.04;
v2 -= (v2 > 0.06)? 0.06 : -0.06;
}
// Precalculate matrix & correct for mip mapping
var at :Number = ( u1 - u0 );
var bt :Number = ( v1 - v0 );
var ct :Number = ( u2 - u0 );
var dt :Number = ( v2 - v0 );
var m :Matrix = new Matrix( at, bt, ct, dt, u0, v0 );
m.invert();
var mapping:Matrix = uvMatrices[face3D] || (uvMatrices[face3D] = m.clone() );
mapping.a = m.a;
mapping.b = m.b;
mapping.c = m.c;
mapping.d = m.d;
mapping.tx = m.tx;
mapping.ty = m.ty;
}
else Papervision3D.log( "MaterialObject3D: transformUV() material.bitmap not found!" );
return mapping;
}
// ______________________________________________________________________ TO STRING
/**
* Returns a string value representing the material properties in the specified BitmapMaterial object.
*
* @return A string.
*/
public override function toString(): String
{
return 'Texture:' + this.texture + ' lineColor:' + this.lineColor + ' lineAlpha:' + this.lineAlpha;
}
// ______________________________________________________________________ CREATE BITMAP
protected function createBitmap( asset:BitmapData ):BitmapData
{
resetMapping();
if( AUTO_MIP_MAPPING )
{
return correctBitmap( asset );
}
else
{
this.maxU = this.maxV = 1;
return ( asset );
}
}
// ______________________________________________________________________ CORRECT BITMAP FOR MIP MAPPING
protected function correctBitmap( bitmap :BitmapData ):BitmapData
{
var okBitmap :BitmapData;
var levels :Number = 1 << MIP_MAP_DEPTH;
// this is faster than Math.ceil
var bWidth :Number = bitmap.width / levels;
bWidth = bWidth == uint(bWidth) ? bWidth : uint(bWidth)+1;
var bHeight :Number = bitmap.height / levels;
bHeight = bHeight == uint(bHeight) ? bHeight : uint(bHeight)+1;
var width :Number = levels * bWidth;
var height :Number = levels * bHeight;
// Check for BitmapData maximum size
var ok:Boolean = true;
if( width > 2880 )
{
width = bitmap.width;
ok = false;
}
if( height > 2880 )
{
height = bitmap.height;
ok = false;
}
if( ! ok ) Papervision3D.log( "Material " + this.name + ": Texture too big for mip mapping. Resizing recommended for better performance and quality." );
// Create new bitmap?
if( bitmap && ( bitmap.width % levels !=0 || bitmap.height % levels != 0 ) )
{
okBitmap = new BitmapData( width, height, bitmap.transparent, 0x00000000 );
// this is for ISM and offsetting bitmaps that have been resized
widthOffset = bitmap.width;
heightOffset = bitmap.height;
this.maxU = bitmap.width / width;
this.maxV = bitmap.height / height;
okBitmap.draw( bitmap );
// PLEASE DO NOT REMOVE
extendBitmapEdges( okBitmap, bitmap.width, bitmap.height );
}
else
{
this.maxU = this.maxV = 1;
okBitmap = bitmap;
}
return okBitmap;
}
protected function extendBitmapEdges( bmp:BitmapData, originalWidth:Number, originalHeight:Number ):void
{
var srcRect :Rectangle = new Rectangle();
var dstPoint :Point = new Point();
var i :int;
// Check width
if( bmp.width > originalWidth )
{
// Extend width
srcRect.x = originalWidth-1;
srcRect.y = 0;
srcRect.width = 1;
srcRect.height = originalHeight;
dstPoint.y = 0;
for( i = originalWidth; i < bmp.width; i++ )
{
dstPoint.x = i;
bmp.copyPixels( bmp, srcRect, dstPoint );
}
}
// Check height
if( bmp.height > originalHeight )
{
// Extend height
srcRect.x = 0;
srcRect.y = originalHeight-1;
srcRect.width = bmp.width;
srcRect.height = 1;
dstPoint.x = 0;
for( i = originalHeight; i < bmp.height; i++ )
{
dstPoint.y = i;
bmp.copyPixels( bmp, srcRect, dstPoint );
}
}
}
// ______________________________________________________________________
/**
* Copies the properties of a material.
*
* @param material Material to copy from.
*/
override public function copy( material :MaterialObject3D ):void
{
super.copy( material );
this.maxU = material.maxU;
this.maxV = material.maxV;
}
/**
* Creates a copy of the material.
*
* @return A newly created material that contains the same properties.
*/
override public function clone():MaterialObject3D
{
var cloned:MaterialObject3D = super.clone();
cloned.maxU = this.maxU;
cloned.maxV = this.maxV;
return cloned;
}
// ______________________________________________________________________ PRIVATE VAR
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/BitmapMaterial.as | ActionScript | art | 11,445 |
package org.papervision3d.materials
{
import flash.display.Graphics;
import flash.utils.Dictionary;
import org.papervision3d.core.Number3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.objects.DisplayObject3D;
/**
*
*/
public class ShadedColorMaterial extends MaterialObject3D
{
public var light:Number3D;
/**
*
* @param fillColor
* @param fillAlpha
*/
public function ShadedColorMaterial(fillColor:uint, fillAlpha:Number= 1.0):void
{
this.fillColor = fillColor;
this.fillAlpha = fillAlpha;
this.light = new Number3D(0, 0, 100);
needsFaceNormals = true;
}
/**
* @param instance
* @param face3D
* @param graphics
* @param v0
* @param v1
* @param v2
* @return
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var s:Number;
var lt:Number3D = new Number3D();
light.copyTo(lt);
lt.normalize();
s = Number3D.dot(face3D.face3DInstance.faceNormal, lt)*255;
if(s>0){
var c:Number = s<<16|s<<8|s;
}
graphics.beginFill( c, fillAlpha );
graphics.moveTo( v0.x, v0.y );
graphics.lineTo( v1.x, v1.y );
graphics.lineTo( v2.x, v2.y );
graphics.lineTo( v0.x, v0.y );
graphics.endFill();
return 1;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/ShadedColorMaterial.as | ActionScript | art | 2,148 |
package org.papervision3d.materials.utils
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.InteractiveBitmapMaterial;
public class BitmapMaterialTools
{
public static function createBitmapMaterial(bitmapClass:Class, oneSided:Boolean=true):BitmapMaterial
{
var texture:BitmapData = getTexture(bitmapClass);
var material:BitmapMaterial = new BitmapMaterial(texture);
material.oneSide = oneSided;
return material;
}
public static function createInteractiveBitmapMaterial(bitmapClass:Class, oneSided:Boolean=true):InteractiveBitmapMaterial
{
var texture:BitmapData = getTexture(bitmapClass);
var material:InteractiveBitmapMaterial = new InteractiveBitmapMaterial(texture);
material.oneSide = oneSided;
return material;
}
public static function getTexture(bitmapClass:Class):BitmapData
{
var bm:Bitmap = Bitmap(new bitmapClass());
var texture :BitmapData = new BitmapData(bm.width, bm.height, true,0xFFFFFF);
texture.draw(bm, new Matrix());
return texture;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/utils/BitmapMaterialTools.as | ActionScript | art | 1,192 |
package org.papervision3d.materials
{
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.objects.DisplayObject3D;
public class CompositeMaterial extends MaterialObject3D implements IFaceDrawer
{
private var materials:Array;
public function CompositeMaterial()
{
init();
}
private function init():void
{
materials = new Array();
}
public function addMaterial(material:MaterialObject3D):void
{
materials.push(material);
}
public function removeMaterial(material:MaterialObject3D):void
{
materials.splice(materials.indexOf(material),1);
}
public function removeAllMaterials(material:MaterialObject3D):void
{
materials = new Array();
}
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var num:int = 0;
for each(var n:MaterialObject3D in materials){
num += n.drawFace3D(instance, face3D, graphics, v0, v1, v2);
}
return num;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/CompositeMaterial.as | ActionScript | art | 1,244 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveBitmapWireframeMaterial extends BitmapWireframeMaterial
{
public function InteractiveBitmapWireframeMaterial(color:Number=0xFF00FF, alpha:Number=1, thickness:Number=3)
{
super(color, alpha, thickness);
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveBitmapWireframeMaterial.as | ActionScript | art | 937 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org blog.papervision3d.org osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Patrick Pietens
* @author John Grden
* @author Carlos Ulloa
*
* @note Special thanks to Patrick Pietens for putting this together and flushing it out!
*/
// __________________________________________________________________________ VIDEO MATERIAL
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.events.NetStatusEvent;
import flash.geom.Matrix;
import flash.media.Video;
import flash.net.NetStream;
/*
* The VideoMaterial class creates a texture from an existing Video instance and is for use with a Video and NetStream objects with an RTMP stream.
* <p/>
* The texture can be animated and/or transparent.
* <p/>
* Materials collects data about how objects appear when rendered.
*/
public class VideoStreamMaterial extends MovieMaterial
{
// ______________________________________________________________________ PUBLIC
/**
* The NetStream and Vdeo that are used as a texture.
*/
public var stream:NetStream;
public var video:Video;
// ______________________________________________________________________ NEW
/**
* The MovieMaterial class creates a texture from an existing Video instance.
*
* @param video A video object that display the FLV file
* @param stream Stream that is used to play the FLV file
* @param initObject [optional] - An object that contains additional properties with which to populate the newly created material.
*/
public function VideoStreamMaterial ( video:Video, stream:NetStream )
{
// store the values
this.stream = stream;
this.video = video;
animated = true;
// init the material with a listener for the NS object
initMaterial ( video, stream );
super ( DisplayObject(video) );
}
// ______________________________________________________________________ INITIALISE
/**
* Executes when the VideoMaterial is instantiated
*/
private function initMaterial ( video:Video, stream:NetStream ):void
{
stream.addEventListener ( NetStatusEvent.NET_STATUS, onStreamStatus );
}
// ______________________________________________________________________ UPDATE
/**
* Updates Video Bitmap
*
* Draws the current Video frame onto bitmap.
*/
public override function updateBitmap ():void
{
try
{
// copies the scale properties of the video
var myMatrix:Matrix = new Matrix();
myMatrix.scale( this.video.scaleX, this.video.scaleY );
// Fills the rectangle with a background color
this.bitmap.fillRect ( this.bitmap.rect, this.fillColor );
// Due to security reasons the BitmapData cannot access RTMP content like a NetStream using a FMS server.
// The next three lines are a simple but effective workaround to get pass Flash its security sandbox.
this.video.attachNetStream ( null );
this.bitmap.draw( this.video, myMatrix, this.video.transform.colorTransform );
this.video.attachNetStream ( this.stream );
}catch(e:Error)
{
//
}
}
// ______________________________________________________________________ STREAM STATUS
/**
* Executes when the status of the NetStream object changes
*
* @param Event that invoked the handler
*/
private function onStreamStatus ( event:NetStatusEvent ):void
{
switch ( event.info.code )
{
case "NetStream.Play.Start":
animated = true;
break;
case "NetStream.Unpause.Notify":
animated = true;
break;
case "NetStream.Play.Failed":
animated = false;
break;
case "NetStream.Play.Stop":
animated = false;
break;
case "NetStream.Play.StreamNotFound":
animated = false;
break;
case "NetStream.Pause.Notify":
animated = false;
break;
}
}
// ______________________________________________________________________ TO STRING
/**
* Returns a string value representing the material properties in the specified VideoMaterial object.
*
* @return A string.
*/
public override function toString():String
{
return 'Texture:' + this.texture;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/VideoStreamMaterial.as | ActionScript | art | 6,010 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveBitmapFileMaterial extends BitmapFileMaterial
{
public function InteractiveBitmapFileMaterial( url:String )
{
super( url );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveBitmapFileMaterial.as | ActionScript | art | 859 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import flash.display.Sprite;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveMovieMaterial extends MovieMaterial
{
public function InteractiveMovieMaterial(movieAsset:Sprite, transparent:Boolean=false, animated:Boolean=false)
{
super(movieAsset, transparent, animated);
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveMovieMaterial.as | ActionScript | art | 963 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveColorMaterial extends ColorMaterial
{
public function InteractiveColorMaterial( color:Number=0xFF00FF, alpha:Number=1 )
{
super( color, alpha );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveColorMaterial.as | ActionScript | art | 880 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* @author John Grden
* NOTE: ported by Andy Zupko
*/
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.IPreciseMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
public class PreciseBitmapFileMaterial extends BitmapFileMaterial implements IPreciseMaterial
{
public var precision:Number = 1;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;
public var focus:Number = 100;
public function PreciseBitmapFileMaterial( url:String )
{
super( url );
precision = precision * precision * 1.4;
}
public override function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var mapping:Matrix = transformUV(face3D);
renderRec(graphics, mapping.a, mapping.b, mapping.c, mapping.d, mapping.tx, mapping.ty, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z,0);
return 1;
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
{
if ((az <= 0) && (bz <= 0) && (cz <= 0))
return;
if (index >= 100 || (focus == Infinity) || (Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx) < 2) || (Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy) < 2))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
var faz:Number = focus + az;
var fbz:Number = focus + bz;
var fcz:Number = focus + cz;
var mabz:Number = 2 / (faz + fbz);
var mbcz:Number = 2 / (fbz + fcz);
var mcaz:Number = 2 / (fcz + faz);
var mabx:Number = (ax*faz + bx*fbz)*mabz;
var maby:Number = (ay*faz + by*fbz)*mabz;
var mbcx:Number = (bx*fbz + cx*fcz)*mbcz;
var mbcy:Number = (by*fbz + cy*fcz)*mbcz;
var mcax:Number = (cx*fcz + ax*faz)*mcaz;
var mcay:Number = (cy*fcz + ay*faz)*mcaz;
var dabx:Number = ax + bx - mabx;
var daby:Number = ay + by - maby;
var dbcx:Number = bx + cx - mbcx;
var dbcy:Number = by + cy - mbcy;
var dcax:Number = cx + ax - mcax;
var dcay:Number = cy + ay - mcay;
var dsab:Number = (dabx*dabx + daby*daby);
var dsbc:Number = (dbcx*dbcx + dbcy*dbcy);
var dsca:Number = (dcax*dcax + dcay*dcay);
if ((dsab <= precision) && (dsca <= precision) && (dsbc <= precision))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
//Debug.trace(num(ta)+" "+num(tb)+" "+num(tc)+" "+num(td)+" "+num(tx)+" "+num(ty));
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
graphics.lineStyle();
graphics.beginBitmapFill(bitmap, matrix, repeat, smooth && (v0x*(v2y - v1y) + v1x*(v0y - v2y) + v2x*(v1y - v0y) > 400));
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
private static function num(n:Number):Number
{
return int(n*1000)/1000;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/PreciseBitmapFileMaterial.as | ActionScript | art | 8,810 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org • blog.papervision3d.org • osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// _______________________________________________________________________ MaterialsList
package org.papervision3d.materials
{
import org.papervision3d.core.proto.*;
import flash.utils.Dictionary;
/**
* The MaterialsList class contains a list of materials.
* <p/>
* Each MaterialsList object has its own materials list.
*/
public class MaterialsList
{
/**
* List of materials indexed by name.
*/
public var materialsByName :Dictionary;
/**
* Returns the number of children of this object.
*/
public function get numMaterials():int
{
return this._materialsTotal;
}
// ___________________________________________________________________________________________________
// N E W
// NN NN EEEEEE WW WW
// NNN NN EE WW WW WW
// NNNNNN EEEE WWWWWWWW
// NN NNN EE WWW WWW
// NN NN EEEEEE WW WW
/**
* Creates a list of materials.
*
* @param materials An array or name indexed object with materials to populate the list with.
*/
public function MaterialsList( materials :*=null ):void
{
this.materialsByName = new Dictionary(true);
this._materials = new Dictionary(false);
this._materialsTotal = 0;
if( materials )
{
if( materials is Array )
{
for( var i:String in materials )
{
this.addMaterial( materials[i] );
}
}
else if( materials is Object )
{
for( var name:String in materials )
{
this.addMaterial( materials[ name ], name );
}
}
}
}
/**
* Adds a material to this MaterialsList object.
*
* @param material The material to add.
* @param name An optional name of the material. If no name is provided, the material name will be used.
* @return The material you have added.
*/
public function addMaterial( material:MaterialObject3D, name:String=null ):MaterialObject3D
{
name = name || material.name || String( material.id );
this._materials[ material ] = name;
this.materialsByName[ name ] = material;
this._materialsTotal++;
return material;
}
/**
* Removes the specified material from the materials list.
*
* @param material The material to remove.
* @return The material you have removed.
*/
public function removeMaterial( material:MaterialObject3D ):MaterialObject3D
{
delete this.materialsByName[ this._materials[ material ] ];
delete this._materials[ material ];
return material;
}
/**
* Returns the material that exists with the specified name.
* </p>
* @param name The name of the material to return.
* @return The material with the specified name.
*/
public function getMaterialByName( name:String ):MaterialObject3D
{
return this.materialsByName[name] ? this.materialsByName[name] : this.materialsByName["all"];
//return this.materialsByName[ name ];
}
/**
* Removes the material that exists with the specified name.
* </p>
* The material object is garbage collected if no other references to the material exist.
* </p>
* The garbage collector is the process by which Flash Player reallocates unused memory space. When a variable or object is no longer actively referenced or stored somewhere, the garbage collector sweeps through and wipes out the memory space it used to occupy if no other references to it exist.
* </p>
* @param name The name of the material to remove.
* @return The material object that was removed.
*/
public function removeMaterialByName( name:String ):MaterialObject3D
{
return removeMaterial( getMaterialByName( name ) );
}
/**
* Creates a copy of the materials list.
*
* @return A newly created materials list that contains a duplicate of each of its materials.
*/
public function clone():MaterialsList
{
var cloned:MaterialsList = new MaterialsList();
for each( var m:MaterialObject3D in this.materialsByName )
cloned.addMaterial( m.clone(), this._materials[ m ] );
return cloned;
}
// ___________________________________________________________________________________________________
/**
* Returns a string with the names of the materials in the list.
*
* @return A string.
*/
public function toString():String
{
var list:String = "";
for each( var m:MaterialObject3D in this.materialsByName )
list += this._materials[ m ] + "\n";
return list;
}
// ___________________________________________________________________________________________________
// P R I V A T E
/**
* [internal-use] List of materials.
*/
protected var _materials :Dictionary;
private var _materialsTotal :int;
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/MaterialsList.as | ActionScript | art | 6,546 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveBitmapColorMaterial extends BitmapColorMaterial
{
public function InteractiveBitmapColorMaterial(color:Number=0xFF00FF, alpha:Number=1)
{
super(color, alpha);
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveBitmapColorMaterial.as | ActionScript | art | 894 |
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
public interface IPreciseMaterial
{
function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/IPreciseMaterial.as | ActionScript | art | 1,050 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* @author John Grden
* NOTE: ported by Andy Zupko
*/
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.materials.IPreciseMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
public class PreciseBitmapAssetMaterial extends BitmapAssetMaterial implements IPreciseMaterial
{
public var precision:Number = 1;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;
public var focus:Number = 100;
public function PreciseBitmapAssetMaterial( linkageID:String )
{
super( linkageID );
precision = precision * precision * 1.4;
}
public override function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var mapping:Matrix = transformUV(face3D);
renderRec(graphics, mapping.a, mapping.b, mapping.c, mapping.d, mapping.tx, mapping.ty, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, 0);
return 1;
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
{
if ((az <= 0) && (bz <= 0) && (cz <= 0))
return;
if (index >= 100 || (focus == Infinity) || (Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx) < 2) || (Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy) < 2))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
var faz:Number = focus + az;
var fbz:Number = focus + bz;
var fcz:Number = focus + cz;
var mabz:Number = 2 / (faz + fbz);
var mbcz:Number = 2 / (fbz + fcz);
var mcaz:Number = 2 / (fcz + faz);
var mabx:Number = (ax*faz + bx*fbz)*mabz;
var maby:Number = (ay*faz + by*fbz)*mabz;
var mbcx:Number = (bx*fbz + cx*fcz)*mbcz;
var mbcy:Number = (by*fbz + cy*fcz)*mbcz;
var mcax:Number = (cx*fcz + ax*faz)*mcaz;
var mcay:Number = (cy*fcz + ay*faz)*mcaz;
var dabx:Number = ax + bx - mabx;
var daby:Number = ay + by - maby;
var dbcx:Number = bx + cx - mbcx;
var dbcy:Number = by + cy - mbcy;
var dcax:Number = cx + ax - mcax;
var dcay:Number = cy + ay - mcay;
var dsab:Number = (dabx*dabx + daby*daby);
var dsbc:Number = (dbcx*dbcx + dbcy*dbcy);
var dsca:Number = (dcax*dcax + dcay*dcay);
if ((dsab <= precision) && (dsca <= precision) && (dsbc <= precision))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
//Debug.trace(num(ta)+" "+num(tb)+" "+num(tc)+" "+num(td)+" "+num(tx)+" "+num(ty));
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
graphics.lineStyle();
graphics.beginBitmapFill(bitmap, matrix, repeat, smooth && (v0x*(v2y - v1y) + v1x*(v0y - v2y) + v2x*(v1y - v0y) > 400));
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
private static function num(n:Number):Number
{
return int(n*1000)/1000;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/PreciseBitmapAssetMaterial.as | ActionScript | art | 8,827 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveMovieAssetMaterial extends MovieAssetMaterial
{
public function InteractiveMovieAssetMaterial(linkageID:String, transparent:Boolean=false, animated:Boolean=false)
{
super(linkageID, transparent, animated);
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveMovieAssetMaterial.as | ActionScript | art | 942 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveBitmapAssetMaterial extends BitmapAssetMaterial
{
public function InteractiveBitmapAssetMaterial( linkageID:String )
{
super( linkageID );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveBitmapAssetMaterial.as | ActionScript | art | 878 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* NOTE: ported by Andy Zupko
*/
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.materials.IPreciseMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.NumberUV;
/** Bitmap material that renders bitmap texture taking into account perspective distortion */
public class PreciseBitmapMaterial extends BitmapMaterial implements IPreciseMaterial
{
public var precision:Number = 1;
public var uv0:NumberUV;
public var uv1:NumberUV;
public var uv2:NumberUV;
public var focus:Number = 100;
public function PreciseBitmapMaterial( asset:BitmapData )
{
super( asset );
precision = precision * precision * 1.4;
}
public override function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var mapping:Matrix = transformUV(face3D);
renderRec(graphics, mapping.a, mapping.b, mapping.c, mapping.d, mapping.tx, mapping.ty, v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z,0);
return 1;
}
public function renderRec(graphics:Graphics, ta:Number, tb:Number, tc:Number, td:Number, tx:Number, ty:Number,
ax:Number, ay:Number, az:Number, bx:Number, by:Number, bz:Number, cx:Number, cy:Number, cz:Number, index:Number):void
{
if ((az <= 0) && (bz <= 0) && (cz <= 0))
return;
if (index >= 100 || (focus == Infinity) || (Math.max(Math.max(ax, bx), cx) - Math.min(Math.min(ax, bx), cx) < 2) || (Math.max(Math.max(ay, by), cy) - Math.min(Math.min(ay, by), cy) < 2))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
var faz:Number = focus + az;
var fbz:Number = focus + bz;
var fcz:Number = focus + cz;
var mabz:Number = 2 / (faz + fbz);
var mbcz:Number = 2 / (fbz + fcz);
var mcaz:Number = 2 / (fcz + faz);
var mabx:Number = (ax*faz + bx*fbz)*mabz;
var maby:Number = (ay*faz + by*fbz)*mabz;
var mbcx:Number = (bx*fbz + cx*fcz)*mbcz;
var mbcy:Number = (by*fbz + cy*fcz)*mbcz;
var mcax:Number = (cx*fcz + ax*faz)*mcaz;
var mcay:Number = (cy*fcz + ay*faz)*mcaz;
var dabx:Number = ax + bx - mabx;
var daby:Number = ay + by - maby;
var dbcx:Number = bx + cx - mbcx;
var dbcy:Number = by + cy - mbcy;
var dcax:Number = cx + ax - mcax;
var dcay:Number = cy + ay - mcay;
var dsab:Number = (dabx*dabx + daby*daby);
var dsbc:Number = (dbcx*dbcx + dbcy*dbcy);
var dsca:Number = (dcax*dcax + dcay*dcay);
if ((dsab <= precision) && (dsca <= precision) && (dsbc <= precision))
{
renderTriangleBitmap(graphics, ta, tb, tc, td, tx, ty, ax, ay, bx, by, cx, cy, smooth, tiled);
return;
}
//Debug.trace(num(ta)+" "+num(tb)+" "+num(tc)+" "+num(td)+" "+num(tx)+" "+num(ty));
if ((dsab > precision) && (dsca > precision) && (dsbc > precision))
{
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2-1, ty*2,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, ta*2, tb*2, tc*2, td*2, tx*2, ty*2-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, -ta*2, -tb*2, -tc*2, -td*2, -tx*2+1, -ty*2+1,
mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, index+1);
return;
}
var dmax:Number = Math.max(dsab, Math.max(dsca, dsbc));
if (dsab == dmax)
{
renderRec(graphics, ta*2, tb*1, tc*2, td*1, tx*2, ty*1,
ax, ay, az, mabx * 0.5, maby * 0.5, (az+bz) * 0.5, cx, cy, cz, index+1);
renderRec(graphics, ta*2+tb, tb*1, 2*tc+td, td*1, tx*2+ty-1, ty*1,
mabx * 0.5, maby * 0.5, (az+bz) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
if (dsca == dmax)
{
renderRec(graphics, ta*1, tb*2, tc*1, td*2, tx*1, ty*2,
ax, ay, az, bx, by, bz, mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, index+1);
renderRec(graphics, ta*1, tb*2 + ta, tc*1, td*2 + tc, tx, ty*2+tx-1,
mcax * 0.5, mcay * 0.5, (cz+az) * 0.5, bx, by, bz, cx, cy, cz, index+1);
return;
}
renderRec(graphics, ta-tb, tb*2, tc-td, td*2, tx-ty, ty*2,
ax, ay, az, bx, by, bz, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, index+1);
renderRec(graphics, 2*ta, tb-ta, tc*2, td-tc, 2*tx, ty-tx,
ax, ay, az, mbcx * 0.5, mbcy * 0.5, (bz+cz) * 0.5, cx, cy, cz, index+1);
}
public function renderTriangleBitmap(graphics:Graphics,a:Number, b:Number, c:Number, d:Number, tx:Number, ty:Number,
v0x:Number, v0y:Number, v1x:Number, v1y:Number, v2x:Number, v2y:Number, smooth:Boolean, repeat:Boolean):void
{
var a2:Number = v1x - v0x;
var b2:Number = v1y - v0y;
var c2:Number = v2x - v0x;
var d2:Number = v2y - v0y;
var matrix:Matrix = new Matrix(a*a2 + b*c2,
a*b2 + b*d2,
c*a2 + d*c2,
c*b2 + d*d2,
tx*a2 + ty*c2 + v0x,
tx*b2 + ty*d2 + v0y);
graphics.lineStyle();
graphics.beginBitmapFill(bitmap, matrix, repeat, smooth && (v0x*(v2y - v1y) + v1x*(v0y - v2y) + v2x*(v1y - v0y) > 400));
graphics.moveTo(v0x, v0y);
graphics.lineTo(v1x, v1y);
graphics.lineTo(v2x, v2y);
graphics.endFill();
}
private static function num(n:Number):Number
{
return int(n*1000)/1000;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/PreciseBitmapMaterial.as | ActionScript | art | 8,740 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import flash.display.BitmapData;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveBitmapMaterial extends BitmapMaterial
{
public function InteractiveBitmapMaterial( asset:BitmapData )
{
super( asset );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveBitmapMaterial.as | ActionScript | art | 896 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// __________________________________________________________________________ BITMAP ASSET MATERIAL
package org.papervision3d.materials
{
import flash.display.BitmapData;
import flash.utils.describeType;
import flash.utils.getDefinitionByName;
import org.papervision3d.Papervision3D;
/**
* The BitmapAssetMaterial class creates a texture from a Bitmap library symbol.
*
* Materials collects data about how objects appear when rendered.
*
*/
public class BitmapAssetMaterial extends BitmapMaterial
{
/**
* A texture object.
*/
override public function get texture():Object
{
return this._texture;
}
/**
* @private
*/
override public function set texture( asset:Object ):void
{
if( asset is String == false )
{
Papervision3D.log("Error: BitmapMaterial.texture requires a BitmapData object for the texture");
return;
}
bitmap = createBitmapFromLinkageID( String(asset) );
_texture = asset;
}
// ______________________________________________________________________ NEW
/**
* The BitmapAssetMaterial class creates a texture from a Bitmap library asset.
*
* @param linkageID The linkage name of the Bitmap symbol in the library.
* @param initObject [optional] - An object that contains additional properties with which to populate the newly created material.
*/
public function BitmapAssetMaterial( linkageID:String )
{
texture = linkageID;
}
// ______________________________________________________________________ CREATE BITMAP
/**
* [internal-use]
*
* @param asset
* @return
*/
protected function createBitmapFromLinkageID( asset:String ):BitmapData
{
// Remove previous bitmap
if( this._texture != asset )
{
_count[this._texture]--;
var prevBitmap:BitmapData = _library[this._texture];
if( prevBitmap && _count[this._texture] == 0 )
prevBitmap.dispose();
}
// Retrieve from library or...
var bitmapOk :BitmapData;
var bitmap :BitmapData = _library[asset];
// ...loadBitmap
if( ! bitmap )
{
var BitmapAsset:Class = getDefinitionByName( asset ) as Class;
var description:XML = describeType( BitmapAsset );
// Check if Flash 9 Alpha
if( description..constructor.length() == 0 )
bitmap = new BitmapAsset() as BitmapData;
else
bitmap = new BitmapAsset( 0, 0 ) as BitmapData;
bitmapOk = createBitmap( bitmap );
_library[asset] = bitmapOk;
_count[asset] = 0;
}
else
{
bitmapOk = bitmap;
maxU = maxV = 1;
_count[asset]++;
}
return bitmapOk;
}
static private var _library :Object = new Object();
static private var _count :Object = new Object();
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/BitmapAssetMaterial.as | ActionScript | art | 4,392 |
package org.papervision3d.materials
{
import flash.media.Video;
import flash.net.NetStream;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractiveVideoStreamMaterial extends VideoStreamMaterial
{
public function InteractiveVideoStreamMaterial( video:Video=null, stream:NetStream=null )
{
super( video, stream );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveVideoStreamMaterial.as | ActionScript | art | 968 |
package org.papervision3d.materials
{
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.objects.DisplayObject3D;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.geom.Matrix;
public class BitmapColorMaterial extends BitmapMaterial implements IFaceDrawer
{
private var uvMatrix:Matrix;
private static const BITMAP_WIDTH:int = 16;
private static const BITMAP_HEIGHT:int = 16;
public function BitmapColorMaterial(color:Number=0xFF00FF, alpha:Number=1)
{
bitmap = new BitmapData(BITMAP_WIDTH,BITMAP_HEIGHT,fillAlpha > 1,0x00000000);
fillColor = color;
fillAlpha = alpha;
init();
}
private function init():void
{
createBitmapData();
createStaticUVMatrix();
}
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
if(bitmap){
var x0:Number = v0.x;
var y0:Number = v0.y;
var x1:Number = v1.x;
var y1:Number = v1.y;
var x2:Number = v2.x;
var y2:Number = v2.y;
_triMatrix.a = x1 - x0;
_triMatrix.b = y1 - y0;
_triMatrix.c = x2 - x0;
_triMatrix.d = y2 - y0;
_triMatrix.tx = x0;
_triMatrix.ty = y0;
_localMatrix.a = uvMatrix.a;
_localMatrix.b = uvMatrix.b;
_localMatrix.c = uvMatrix.c;
_localMatrix.d = uvMatrix.d;
_localMatrix.tx = uvMatrix.tx;
_localMatrix.ty = uvMatrix.ty;
_localMatrix.concat(_triMatrix);
graphics.beginBitmapFill( bitmap, _localMatrix, tiled, smooth);
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.endFill();
return 1;
}
return 0;
}
private function createBitmapData():void
{
var sprite:Sprite = new Sprite();
var graphics:Graphics = sprite.graphics;
graphics.beginFill(fillColor, fillAlpha);
graphics.drawRect(0,0,BITMAP_WIDTH,BITMAP_HEIGHT);
graphics.endFill();
bitmap.draw(sprite);
}
private function createStaticUVMatrix():void
{
var w :Number = BITMAP_WIDTH;
var h :Number = BITMAP_HEIGHT;
var u0 :Number = w;
var v0 :Number = 0;
var u1 :Number = 0;
var v1 :Number = 0;
var u2 :Number = w;
var v2 :Number = h;
// Precalculate matrix & correct for mip mapping
var at :Number = ( u1 - u0 );
var bt :Number = ( v1 - v0 );
var ct :Number = ( u2 - u0 );
var dt :Number = ( v2 - v0 );
uvMatrix = new Matrix( at, bt, ct, dt, u0, v0 );
uvMatrix.invert();
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/BitmapColorMaterial.as | ActionScript | art | 2,787 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org � blog.papervision3d.org � osflash.org/papervision3d
*/
/*
* Copyright 2006-2007 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// ______________________________________________________________________ BITMAP FILE MATERIAL
package org.papervision3d.materials
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;
import flash.utils.Dictionary;
import org.papervision3d.Papervision3D;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.objects.DisplayObject3D;
/**
* The BitmapFileMaterial class creates a texture by loading a bitmap from an external file.
*
* Materials collect data about how objects appear when rendered.
*/
public class BitmapFileMaterial extends BitmapMaterial
{
// ___________________________________________________________________ PUBLIC
/**
* The URL that has been requested.
*/
public var url :String = "";
/**
* Whether or not the texture has been loaded.
*/
public var loaded :Boolean;
/**
* Function to call when the last image has loaded.
*/
static public var callback :Function;
/**
* The color to use in materials before loading has finished.
*/
static public var LOADING_COLOR :int = MaterialObject3D.DEFAULT_COLOR;
/**
* The color to use for the lines when there is an error.
*/
static public var ERROR_COLOR:int = MaterialObject3D.DEBUG_COLOR;
/**
* A texture object.
*/
override public function get texture():Object
{
return this._texture;
}
/**
* @private
*/
override public function set texture( asset:Object ):void
{
if( asset is String == false )
{
Papervision3D.log("Error: BitmapFileMaterial.texture requires a String for the texture");
return;
}
bitmap = createBitmapFromURL( String(asset) );
_texture = asset;
}
/**
* Internal
*
* Used to define if the loading had failed.
*/
private var errorLoading:Boolean = false;
// ___________________________________________________________________ NEW
/**
* The BitmapFileMaterial class creates a texture by loading a bitmap from an external file.
*
* @param url The URL of the requested bitmap file.
* @param initObject [optional] - An object that contains additional properties with which to populate the newly created material.
*/
public function BitmapFileMaterial( url :String="" )
{
// save URL reference
this.url = url;
// set the loaded flag
this.loaded = false;
// Loading color
this.fillAlpha = 1;
this.fillColor = LOADING_COLOR;
// start the loading by setting the texture
if( url.length > 0 ) texture = url;
}
// ___________________________________________________________________ CREATE BITMAP
/**
* [internal-use]
*
* @param asset
* @return
*/
protected function createBitmapFromURL( asset:String ):BitmapData
{
// Empy string?
if( asset == "" )
{
return null;
}
// Already loaded?
else if( _loadedBitmaps[ asset ] )
{
var bmp:BitmapData = _loadedBitmaps[ asset ];
bitmap = super.createBitmap( bmp );
this.loadComplete();
return bmp;
}
else
{
queueBitmap( asset );
}
return null;
}
// ___________________________________________________________________ QUEUE BITMAP
private function queueBitmap( file:String ):void
{
// New filename?
if( ! _subscribedMaterials[ file ] )
{
// Queue file
_waitingBitmaps.push( file );
// Init subscription
_subscribedMaterials[ file ] = new Array();
}
// Subscribe material
_subscribedMaterials[ file ].push( this );
// Launch loading if needed
if( _loadingIdle )
loadNextBitmap();
}
// ___________________________________________________________________ LOAD NEXT BITMAP
private function loadNextBitmap():void
{
// Retrieve next filename in queue
var file:String = _waitingBitmaps[0];
var request:URLRequest = new URLRequest( file );
var bitmapLoader:Loader = new Loader();
bitmapLoader.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, loadBitmapProgressHandler );
bitmapLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadBitmapCompleteHandler );
bitmapLoader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, loadBitmapErrorHandler );
try
{
// Load bitmap
bitmapLoader.load( request );
// Save original url
_loaderUrls[ bitmapLoader ] = file;
// Busy loading
_loadingIdle = false;
Papervision3D.log( "BitmapFileMaterial: Loading bitmap from " + file );
}
catch( error:Error )
{
// Remove from queue
_waitingBitmaps.shift();
// Loading finished
_loadingIdle = true;
Papervision3D.log( "[ERROR] BitmapFileMaterial: Unable to load file " + error.message );
}
}
// ___________________________________________________________________ LOAD BITMAP ERROR HANDLER
private function loadBitmapErrorHandler( e:IOErrorEvent ):void
{
var failedAsset:String = String(_waitingBitmaps.shift());
// force the IOErrorEvent to trigger on any reload.
// ie: no reload on retry if we don't clear these 2 statics below.
_loadedBitmaps[failedAsset] = null;
_subscribedMaterials[failedAsset] = null;
this.errorLoading = true;
this.lineColor = ERROR_COLOR;
this.lineAlpha = 1;
this.lineThickness = 1;
// Queue finished?
if( _waitingBitmaps.length > 0 )
{
// Continue loading
loadNextBitmap();
}
else
{
// Loading finished
_loadingIdle = true;
if( Boolean( callback ) ) callback();
}
var event:FileLoadEvent = new FileLoadEvent(FileLoadEvent.LOAD_ERROR, failedAsset, -1, -1, e.text);
dispatchEvent(event);
}
// ___________________________________________________________________ LOAD BITMAP PROGRESS HANDLER
private function loadBitmapProgressHandler( e:ProgressEvent ):void
{
var progressEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_PROGRESS, url, e.bytesLoaded, e.bytesTotal);
dispatchEvent( progressEvent );
}
// ___________________________________________________________________ LOAD BITMAP COMPLETE HANDLER
private function loadBitmapCompleteHandler( e:Event ):void
{
var loader:Loader = Loader( e.target.loader );
var loadedBitmap:Bitmap = Bitmap( loader.content );
// Retrieve original url
var url:String = _loaderUrls[ loader ];
// Retrieve loaded bitmapdata
var bmp:BitmapData = super.createBitmap( loadedBitmap.bitmapData );
// Update subscribed materials
for each( var material:BitmapFileMaterial in _subscribedMaterials[ url ] )
{
material.bitmap = bmp;
material.maxU = this.maxU;
material.maxV = this.maxV;
material.resetMapping();
material.loadComplete();
}
// Include in library
_loadedBitmaps[ url ] = bmp;
// Remove from queue
_waitingBitmaps.shift();
// Queue finished?
if( _waitingBitmaps.length > 0 )
{
// Continue loading
loadNextBitmap();
}
else
{
// Loading finished
_loadingIdle = true;
if( Boolean( callback ) ) callback();
}
}
// ___________________________________________________________________ LOAD COMPLETE
private function loadComplete():void
{
this.fillAlpha = 0;
this.fillColor = 0;
this.loaded = true;
// Dispatch event
var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_COMPLETE, this.url );
this.dispatchEvent( fileEvent );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
if (bitmap == null || errorLoading)
{
var x0:Number = v0.x;
var y0:Number = v0.y;
var x1:Number = v1.x;
var y1:Number = v1.y;
var x2:Number = v2.x;
var y2:Number = v2.y;
if(errorLoading){
graphics.lineStyle(lineThickness,lineColor,lineAlpha);
}
graphics.beginFill( fillColor, fillAlpha );
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.endFill();
if(errorLoading){
graphics.lineStyle();
}
return 1;
}
var i:int = super.drawFace3D(instance, face3D, graphics, v0, v1, v2);
return i;
}
// ___________________________________________________________________ PRIVATE
// Filenames in the queue
static private var _waitingBitmaps :Array = new Array();
// URLs per loader
static private var _loaderUrls :Dictionary = new Dictionary();
// Loaded bitmap library
static private var _loadedBitmaps :Object = new Object();
// Materials subscribed to the loading queue
static private var _subscribedMaterials :Object = new Object();
// Loading status
static private var _loadingIdle :Boolean = true;
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/BitmapFileMaterial.as | ActionScript | art | 11,102 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org ? blog.papervision3d.org ? osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* @author Alexander Zadorozhny - Away3D
* @author John Grden
*/
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import flash.display.BitmapData;
import org.papervision3d.core.geom.Vertex2D;
import flash.geom.Matrix;
public class InteractivePreciseBitmapMaterial extends PreciseBitmapMaterial
{
public function InteractivePreciseBitmapMaterial( asset:BitmapData )
{
super( asset );
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
}
| 108fantasy-tactics | trunk/org/papervision3d/materials/InteractivePreciseBitmapMaterial.as | ActionScript | art | 2,711 |
package org.papervision3d.materials
{
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.geom.Face3D;
import flash.display.Graphics;
import org.papervision3d.core.geom.Vertex2D;
public class InteractiveShadedColorMaterial extends ShadedColorMaterial
{
public function InteractiveShadedColorMaterial(fillColor:uint, fillAlpha:Number= 1.0)
{
super(fillColor, fillAlpha);
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var result:int = super.drawFace3D(instance, face3D, graphics, v0, v1,v2);
if(instance.interactiveSceneManager != null && result) instance.interactiveSceneManager.drawFace(instance,face3D,v0.x, v1.x, v2.x, v0.y, v1.y, v2.y);
return result;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/InteractiveShadedColorMaterial.as | ActionScript | art | 874 |
/*
* PAPER ON ERVIS NPAPER ISION PE IS ON PERVI IO APER SI PA
* AP VI ONPA RV IO PA SI PA ER SI NP PE ON AP VI ION AP
* PERVI ON PE VISIO APER IONPA RV IO PA RVIS NP PE IS ONPAPE
* ER NPAPER IS PE ON PE ISIO AP IO PA ER SI NP PER
* RV PA RV SI ERVISI NP ER IO PE VISIO AP VISI PA RV3D
* ______________________________________________________________________
* papervision3d.org blog.papervision3d.org osflash.org/papervision3d
*/
/*
* Copyright 2006 (c) Carlos Ulloa Matesanz, noventaynueve.com.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
// __________________________________________________________________________ COLOR MATERIAL
package org.papervision3d.materials
{
import flash.display.Graphics;
import flash.geom.Matrix;
import org.papervision3d.core.draw.IFaceDrawer;
import org.papervision3d.core.geom.Face3D;
import org.papervision3d.core.geom.Vertex2D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.objects.DisplayObject3D;
/**
* The ColorMaterial class creates a solid color material.
*
* Materials collects data about how objects appear when rendered.
*
*/
public class ColorMaterial extends MaterialObject3D implements IFaceDrawer
{
// ______________________________________________________________________ NEW
/**
* The ColorMaterial class creates a solid color material.
*
* @param asset A BitmapData object.
* @param initObject [optional] - An object that contains additional properties with which to populate the newly created material.
*/
public function ColorMaterial( color:Number=0xFF00FF, alpha:Number = 1, initObject:Object=null )
{
this.fillColor = color;
this.fillAlpha = alpha;
}
/**
* drawFace3D
*/
override public function drawFace3D(instance:DisplayObject3D, face3D:Face3D, graphics:Graphics, v0:Vertex2D, v1:Vertex2D, v2:Vertex2D):int
{
var x0:Number = v0.x;
var y0:Number = v0.y;
var x1:Number = v1.x;
var y1:Number = v1.y;
var x2:Number = v2.x;
var y2:Number = v2.y;
graphics.beginFill( fillColor, fillAlpha );
graphics.moveTo( x0, y0 );
graphics.lineTo( x1, y1 );
graphics.lineTo( x2, y2 );
graphics.lineTo( x0, y0 );
graphics.endFill();
return 1;
}
// ______________________________________________________________________ TO STRING
/**
* Returns a string value representing the material properties in the specified ColorMaterial object.
*
* @return A string.
*/
public override function toString(): String
{
return 'ColorMaterial - color:' + this.fillColor + ' alpha:' + this.fillAlpha;
}
}
} | 108fantasy-tactics | trunk/org/papervision3d/materials/ColorMaterial.as | ActionScript | art | 3,789 |