/*************************************************************************/ /* multimesh.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* 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. */ /*************************************************************************/ #include "multimesh.h" #include "servers/visual_server.h" void MultiMesh::_set_transform_array(const DVector& p_array) { int instance_count = get_instance_count(); DVector xforms = p_array; int len=xforms.size(); ERR_FAIL_COND((len/4) != instance_count); if (len==0) return; DVector::Read r = xforms.read(); for(int i=0;i MultiMesh::_get_transform_array() const { int instance_count = get_instance_count(); if (instance_count==0) return DVector(); DVector xforms; xforms.resize(instance_count*4); DVector::Write w = xforms.write(); for(int i=0;i& p_array) { int instance_count = get_instance_count(); DVector colors = p_array; int len=colors.size(); ERR_FAIL_COND(len != instance_count); if (len==0) return; DVector::Read r = colors.read(); for(int i=0;i MultiMesh::_get_color_array() const { int instance_count = get_instance_count(); if (instance_count==0) return DVector(); DVector colors; colors.resize(instance_count); for(int i=0;i& p_mesh) { mesh=p_mesh; if (!mesh.is_null()) VisualServer::get_singleton()->multimesh_set_mesh(multimesh,mesh->get_rid()); else VisualServer::get_singleton()->multimesh_set_mesh(multimesh,RID()); } Ref MultiMesh::get_mesh() const { return mesh; } void MultiMesh::set_instance_count(int p_count) { VisualServer::get_singleton()->multimesh_set_instance_count(multimesh,p_count); } int MultiMesh::get_instance_count() const { return VisualServer::get_singleton()->multimesh_get_instance_count(multimesh); } void MultiMesh::set_instance_transform(int p_instance, const Transform& p_transform) { VisualServer::get_singleton()->multimesh_instance_set_transform(multimesh,p_instance,p_transform); } Transform MultiMesh::get_instance_transform(int p_instance) const { return VisualServer::get_singleton()->multimesh_instance_get_transform(multimesh,p_instance); } void MultiMesh::set_instance_color(int p_instance, const Color& p_color) { VisualServer::get_singleton()->multimesh_instance_set_color(multimesh,p_instance,p_color); } Color MultiMesh::get_instance_color(int p_instance) const { return VisualServer::get_singleton()->multimesh_instance_get_color(multimesh,p_instance); } void MultiMesh::set_aabb(const AABB& p_aabb) { aabb=p_aabb; VisualServer::get_singleton()->multimesh_set_aabb(multimesh,p_aabb); } AABB MultiMesh::get_aabb() const { return aabb; } void MultiMesh::generate_aabb() { ERR_EXPLAIN("Cannot generate AABB if mesh is null."); ERR_FAIL_COND(mesh.is_null()); AABB base_aabb=mesh->get_aabb(); aabb=AABB(); int instance_count = get_instance_count(); for(int i=0;imultimesh_create(); } MultiMesh::~MultiMesh() { VisualServer::get_singleton()->free(multimesh); }