Download pool/shard010/Python/0089356_mesh_vertex.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 4.54 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard010/Python/0089356_mesh_vertex.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard010/Python/0089356_mesh_vertex.py
-
curl -L -o 0089356_mesh_vertex.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard010/Python/0089356_mesh_vertex.py
4.54 kB
| ################################################################################# | |
| # Copyright 2014 See AUTHORS file. | |
| # | |
| # Licensed under the GNU General Public License Version 3.0 (the "LICENSE"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.gnu.org/licenses/gpl-3.0.txt | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| ################################################################################# | |
| from mathutils import Vector, Color | |
| class MeshVertex: | |
| """Represents a vertex we can export, with facilities to compare two of them""" | |
| _position = None | |
| def position(self): | |
| return self._position | |
| def position(self,position): | |
| if not isinstance(position, Vector): | |
| raise TypeError("position needs to be a mathutils.Vector") | |
| self._position = position | |
| _normal = None | |
| def normal(self): | |
| return self._normal | |
| def normal(self,normal): | |
| if not isinstance(normal, Vector): | |
| raise TypeError("normal needs to be a mathutils.Vector") | |
| self._normal = normal | |
| _tangent = None | |
| def tangent(self): | |
| return self._tangent | |
| def tangent(self,tangent): | |
| if tangent != None and not isinstance(tangent, Vector): | |
| raise TypeError("tangent needs to be a mathutils.Vector") | |
| self._tangent = tangent | |
| _binormal = None | |
| def binormal(self): | |
| return self._binormal | |
| def binormal(self,binormal): | |
| if binormal != None and not isinstance(binormal, Vector): | |
| raise TypeError("binormal needs to be a mathutils.Vector") | |
| self._binormal = binormal | |
| _texcoord = None | |
| def texcoord(self): | |
| return self._texcoord | |
| def texcoord(self,texcoord): | |
| if texcoord != None and not isinstance(texcoord, list): | |
| raise TypeError("texcoord needs to be a list of vectors (mathutils.Vector) or None") | |
| self._texcoord = texcoord | |
| _blendweight = None | |
| def blendweight(self): | |
| return self._blendweight | |
| def blendweight(self,blendweight): | |
| if blendweight != None and not isinstance(blendweight, list): | |
| raise TypeError("blendweight needs to be a list of vectors (mathutils.Vector) or None") | |
| self._blendweight = blendweight | |
| def __init__(self, position, normal, tangent = None, binormal = None, texcoord = None, blendweight = None): | |
| self.position = position | |
| self.normal = normal | |
| self.tangent = tangent | |
| self.binormal = binormal | |
| self.texcoord = texcoord | |
| self.blendweight = blendweight | |
| _color = None | |
| def color(self): | |
| return self._color | |
| def color(self,color): | |
| if not isinstance(color, Color): | |
| raise TypeError("color needs to be a mathutils.Color") | |
| self._color = color | |
| def compare(self, another): | |
| """Compare two vertices, return True if they have the same value for all fields""" | |
| if another == None or not isinstance(another, MeshVertex): | |
| return False | |
| comparison = self.position == another.position \ | |
| and self.normal == another.normal \ | |
| and self.color == another.color \ | |
| and self.tangent == another.tangent \ | |
| and self.binormal == another.binormal \ | |
| and self.texcoord == another.texcoord \ | |
| and self.blendweight == another.blendweight | |
| return comparison | |
| def normalize_weights(self): | |
| """Normalize all bone weights in this vertex so that they all sum to 1 (one).""" | |
| if self.blendweight != None: | |
| total_weight = 0.0 | |
| for weight in self.blendweight: | |
| total_weight = total_weight + weight[1] | |
| if total_weight != 0.0: | |
| for weight in self.blendweight: | |
| weight[1] = weight[1] / total_weight |