<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_std3DObject.xml $
$Revision: 957 $

last change: $Date: 2009-02-17 14:00:06 +0300 (Вт, 17 фев 2009) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->
<composition name="rnmc_std3DObject" class="rnmc_stdMediaObject">
	<script><![CDATA[
		this.type = "rnmc_std3DObject";
		this.camers = new Array();
		this.lights = new Array();
		this.viewport = null;
		this.cameraName = null;
		this.scene3D    = null;
		this.rotateObject = false;
		// атрибуты rotateXObject, rotateYObject зависимы от атрибута rotateObject,
		// если rotateObject = false; - вращение выключено
		this.rotateXObject = true; 
		this.rotateYObject = true;

	function initFromNode(srcNode){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.id = xmlAttribute.value;
			xmlAttribute = xmlAttributeMap.getNamedItem("visible");
			if (xmlAttribute != null && xmlAttribute.specified){
				if(xmlAttribute.value == "true")
					this.visibility = OBJECT_VISIBILITY_TRUE;
				else if(xmlAttribute.value == "false")
					this.visibility = OBJECT_VISIBILITY_FALSE;
			}
			xmlAttribute = xmlAttributeMap.getNamedItem("enabled");
			if (xmlAttribute != null && xmlAttribute.specified && xmlAttribute.value == "false")
				this.disabled = true;
		}		

		xmlNode = srcNode.firstChild;
		while(xmlNode){
			if(xmlNode.nodeName == "param"){
				this.parseParamNode(xmlNode);
			} else if(xmlNode.nodeName == "rollovermenu"){
				this.parseRolloverMenuNode(xmlNode);
			}  else if(xmlNode.nodeName == "actions"){
				this.parseActionsNode(xmlNode);			
			} else if(xmlNode.nodeName == "zoom"){
				//	===============================================
			} else if(xmlNode.nodeName == "control"){
				this.parseControlNode(xmlNode);
			} else if(xmlNode.nodeName == "title"){
				this.parseTitleNode(xmlNode);
			} else if(xmlNode.nodeName == "hint"){
				this.parseHintNode(xmlNode);
			} else if(xmlNode.nodeName == "effect"){
				this.parseEffectNode(xmlNode);
			} else if(xmlNode.nodeName == "param3D"){
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					xmlAttribute = xmlAttributeMap.getNamedItem("camera");
					if (xmlAttribute != null && xmlAttribute.specified)
						this.cameraName = xmlAttribute.value;
					xmlAttribute = xmlAttributeMap.getNamedItem("rotate");
					if (xmlAttribute != null && xmlAttribute.specified){
						if (xmlAttribute.value == "true")
							this.rotateObject = true;
						else
							this.rotateObject = false;
					}
					xmlAttribute = xmlAttributeMap.getNamedItem("rotateX");
					if (xmlAttribute != null && xmlAttribute.specified){
						if (xmlAttribute.value == "true")
							this.rotateXObject = true;
						else
							this.rotateXObject = false;
					}
					xmlAttribute = xmlAttributeMap.getNamedItem("rotateY");
					if (xmlAttribute != null && xmlAttribute.specified){
						if (xmlAttribute.value == "true")
							this.rotateYObject = true;
						else
							this.rotateYObject = false;
					}
				}
				
			} else if(xmlNode.nodeName == "camera"){
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					var camera = new Object();
					camera.object = null;
					xmlAttribute = xmlAttributeMap.getNamedItem("name");
					if (xmlAttribute != null && xmlAttribute.specified)
						camera.name = xmlAttribute.value;
					xmlAttribute = xmlAttributeMap.getNamedItem("src");
					if (xmlAttribute != null && xmlAttribute.specified)
						camera.src = xmlAttribute.value;
					camers.push(camera);
				}
			} else if(xmlNode.nodeName == "light"){
				xmlAttributeMap = xmlNode.attributes;
				if (xmlAttributeMap){
					var light = new Object();
					light.object = null;
					xmlAttribute = xmlAttributeMap.getNamedItem("src");
					if (xmlAttribute != null && xmlAttribute.specified)
						light.src = xmlAttribute.value;
					lights.push(light);
				}
			}			
			
			xmlNode = xmlNode.nextSibling;
		}
	// если не задан zoom-объект - отключаем опцию увеличения в rollovermenu
		if(!this.zoomObject)
			this.menuZoom = false;
		return true;
	}
	
//	загрузка объекта
	function loadObject(){
trace("rnmc_std3DObject.loadObject()");
		if (!this.scene3D){
			this.scene3D = new Scene3D();
			this.scene3D.name    = "scene3d";
			this.scene3D.parent  = this;
		}

		for (var i = 0; i < this.camers.length; ++i){
			if (this.camers[i].object != null)
				continue;
			this.camers[i].object = new Camera();
			this.camers[i].object.name = camers[i].name;
			this.camers[i].object.src = camers[i].src;
			this.camers[i].object.parent = this.scene3D;
		}

		for (var i = 0; i < this.lights.length; ++i){
			if (this.lights[i].object != null)
				continue;
			this.lights[i].object = new Light();
			this.lights[i].object.src = lights[i].src;
			this.lights[i].object.parent = this.scene3D;
		}

		if(!this.objectContent){
			this.objectContent = new Object3D();
			this.objectContent.src = this.objectSrc;
			this.objectContent.visible = false;
			if (this.objectHitArea != null)
				this.objectContent.hitArea = this.objectHitArea;
			this.objectContent.parent = this.scene3D;
		}		

		if (!this.viewport){

			this.viewport = new Viewport();
			this.viewport.x = this.objectX;
			this.viewport.y = this.objectY;
			this.viewport.width  = this.objectWidth;
			this.viewport.height = this.objectHeight;
			if (this.cameraName != null)
				this.viewport.camera = "scene3d."+this.cameraName;
			else if (camers.length > 0)
				this.viewport.camera = "scene3d."+camers[0].name;			
			this.viewport.parent = this;
		}		
	}

//	 выгрузка (удаление объекта)
	function unloadObject(){
//trace("rnmc_std3DObject.unloadObject()");	
		if (this.viewport){
			this.viewport.parent = null;
			this.viewport = null;		
		}

		if(this.objectContent){
			this.objectContent.src = null;
			this.objectContent.parent = null;
			this.objectContent = null;
		}
		
		for (var i = 0; i < camers.length; ++i){
			if (camers[i].object != null){
				camers[i].object.parent = null;
				camers[i].object = null;
			}		
		}

		for (var i = 0; i < lights.length; ++i){
			if (lights[i].object != null){
				lights[i].object.parent = null;
				lights[i].object = null;
			}
		}

		if (this.scene3D){
			this.scene3D.parent = null;
			this.scene3D = null;
		}
	}
	
	function showObject(){
trace("rnmc_std3DObject.showObject()");
		this.loadObject();

		if(this.objectContent){
			this.objectContent.visible = false;
		};
		
		if(this.viewport){
			this.viewport.depth = this.objectDepth;
			this.viewport.opacity = this.objectOpacity;
		}

		if (rotateObject){
			this.onPress = function(){
				this.dragPoint = new Position3D();				
				this.dragPoint.x = scene.xMouse;
				this.dragPoint.y = scene.yMouse;
			}
			
			this.onRelease = function(){
				delete dragPoint;
			}
			this.onReleaseOutside = function(){
				delete dragPoint;
			}			

			this.onMouseMove = function(){
				if (this.dragPoint != undefined){
					if (rotateXObject){
						dx = scene.xMouse - this.dragPoint.x;
						var rtnX = new Rotation3D(0,0,1,-dx);
						this.objectContent.rotation.mult(rtnX);					
						this.dragPoint.x = scene.xMouse;
						}
					if (rotateYObject){						
						dy = scene.yMouse - this.dragPoint.y;
						var rtnY = new Rotation3D(1,0,0,-dy);
						this.objectContent.rotation.mult(rtnY);
						this.dragPoint.y = scene.yMouse;
					}

				}
			}
		}
		//	OBJECTIVES for onShow
		if(this.onShowObjectives && this.objectivesList){
			for(var i = 0; i < this.objectivesList.length; i++){
				if(this.objectivesList[i] == "onShow"){
					this.objectivesList[i].complete = true;
          this.checkObjectives();
				}
			}
		}
		//	END OBJECTIVES for onShow

		rnmc_stdMediaObject_showObject();
	};	

	function hideObject(){
//trace("rnmc_std3DObject.hideObject(--------------------)");
		rnmc_stdMediaObject_hideObject();
	};
	
	function zoomIn(){
	}

	function zoomOut(){
	}

	function buttonDispatcher(btnId){
		switch(btnId){
		default:
			rnmc_stdMediaObject_buttonDispatcher(btnId);
		}
	}	
]]></script>
</composition>

</rmml>